[R-SIG-Finance] PerfomanceAnalytics
Brian G. Peterson
brian at braverock.com
Sat Jan 28 22:41:59 CET 2012
On Sat, 2012-01-28 at 15:16 -0500, Eric Thungstom wrote:
> I'm having a little trouble understanding why my calculated values are not
> matching up with what's being shown on the PerformanceAnalytics chart and
> drawdown table:
>
> My calculated equity = 2.83
> Cumulative return on the PerformanceAnalytics chart shows about 2.05
>
> table.Drawdowns shows the worst drawdown as about 23%
> Drawdown chart shows worst drawdown at about 13%
>
> table.Drawdown shows the worst drawdown beginning on Nov 01, 2011
> If I look at the cumulative return chart, it seem to start around July 2007
>
> My code is as follows:
<... snip ...>
You're mixing simple and log returns.
require(quantmod)
require(PerformanceAnalytics)
getSymbols("FAIRX", from='2000-01-01', to=Sys.Date())
FAIRX <-na.locf(FAIRX )
ind <- EMA(Ad(FAIRX),100)
sig <- Lag(ifelse(ind > Lag(ind,30), 1, 0))
#ret <- diff(log(Ad(FAIRX )))*sig
ret <- Delt(Ad(FAIRX ))*sig
bh.ret <- Delt(Ad(FAIRX ))
#bh.ret <- Delt(Ad(FAIRX ), type='log')
ret[is.na(ret)] <- 0
eq <- exp(cumsum(ret))
table <- na.omit(merge.xts(Ad(FAIRX ), round(ind,3), sig, round(ret,3),
round(bh.ret,3),round(eq,3)))
names(table) <-c("SP5", "ind", "sig", "rtn", "bhrtn", "equity")
table.Drawdowns(ret, top=5)
table.DownsideRisk(ret)
charts.PerformanceSummary(table[,c("rtn","bhrtn")], wealth.index=TRUE,
colorset=rich6equal, lwd=1, ylog=FALSE,
geometric=TRUE)
print(tail(table))
--
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock
More information about the R-SIG-Finance
mailing list