Description Usage Arguments Details Value Author(s) Examples
tsr
calculates a vector of period returns of a trading
system's equity.
1 |
prices |
numeric vector of prices. |
states |
numeric vector of states. |
delta |
numeric. See below. |
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.
A numeric vector of period returns.
Robert Sams robert@sanctumfi.com
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
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.