i look forward to it – never could get my head ar…
Autore del blog - May 0, 2009
i look forward to it – never could get my head around performance metrics..
This is awesome - very cool. I also was curious if you could put together a simple example of the following:
- Take four ETFs (SPY,IWM,QQQQ,TLT) and rank them by their 12m ROC.
- Buy the top one on the first day of the month.
- Rerank at the beginning of each month, sell the fund if it has fallen from the top position and buy the new top position.
I’ll keep that in mind for when we start showing some more complicated trading systems and portfolio management using another package, ‘blotter’.
You can see a demo of the blotter package by installing it, attaching it (via ‘library()'), and running ‘demo(turtles)'.
Please do note that the blotter package is still in heavy development, so many things will probably change. Such is life on the bleeding edge. :)
Thank you very much for the informative post. I was wondering if you knew of any limitations this code would have when we do not use the getSymbols quantmod function and instead use imported Bloomberg data.
I have found that the results from Bloomberg data differ highly from the results you’ve posted.
I think that this problem may be due to how RSI and ROC calculate the signals and returns respectively.
Any advice or suggestions would be awesome. Thanks in advance.
It’s really hard to say, without more information. Here are the things I would expect to cause differences:
- actual data differences between Yahoo and Bloomberg
- data object differences (i.e. getSymbols returns an xts object, the function you use to pull Bloomberg data may return a data.frame, matrix, etc.)
Thanks Josh, I found that the problem lies in how the lag operator works. I posted a similar problem to the R Finance Community and the error should be corrected in the new version of quantmod.
To quote Jeff:
“lag.zoo was designed by Achim and Kurt to map as closely as possible to R’s ts class behavior, which by all rational interpretations is simply inconsistent with the common understanding of lagged series. Zoo’s goal was a better ts; xts is a time-based zoo.
That said, lag.xts makes a break from this R lag “design” and implements a different set of default behavior, more consistent with user expectations IMO.
Take a look at ?lag.xts
Obviously the downside is management of this difference amongst time classes.”