tsr: Trading System Returns

Description Usage Arguments Details Value Author(s) Examples

Description

tsr calculates a vector of period returns of a trading system's equity.

Usage

1
tsr(prices, states=1, delta=1/prices)

Arguments

prices

numeric vector of prices.

states

numeric vector of states.

delta

numeric. See below.

Details

prices must be a numeric vector.

states must be a vector consisting of 1, 0, and -1 only. Its length must be a multiple of prices but is generally identical to it.

tsr calculates the trading system return at each period t as

[P(t) - P(t-1)] * S(t-1) * D(t-1)

where D(t) is delta[t].

The default value of delta calculates the familiar special case of the above formula

(P(t) / P(t-1) - 1) * S(t-1)

, arithmetic period returns.

Value

A numeric vector of period returns.

Author(s)

Robert Sams robert@sanctumfi.com

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
p <- c(100,110,100,90,120)

## Arithmetic returns by default. x% chg in price = x% chg in equity.
c(0, exp(diff(log(p))) - 1)
tsr(p)
tsr(p, c(1,-1,-1,1,0))

## 2x leveraged
tsr(p, delta=2/p)

## 1 point chg in price = 1% change in equity.
tsr(p, delta=.01)

## The 'Equity Curve'
cumprod(tsr(p) + 1)

plot(sapply(seq(.5, to=5, by=.5), function(lev) prod(tsr(p) * lev + 1)), type="l",
     main="Don't forget that returns are non-linear with leverage!", sub="Leverage Ratio")

## 2x leveraging of price returns
tsr(p, delta=2/p)
tsr(p) * 2  ## same

tradesys documentation built on May 2, 2019, 4:53 p.m.