Hi all this is mainly directed to the developers of the great "quantstrat" package. I am happy to continue this conversation with any of them individually. I have been backtesting some strategies on quantstrat. In order to take them live (through the ibrokers package) I have recently begun to write my own versions of some key quantstrat functions, i.e. applyStrategy, applyRules and ruleOrderProc (addOrder is to follow) One thing I have been looking at is how to make the "applyRules" function process only one timestamp at a time (process all rules only for one specific marketdata timestamp). I consider my solution to this problem to be a rather ugly fix that I would really like to avoid, since essentially it looks like the "applyRules" function has already been designed for that sort of thing, but the implementation seems to be buggy or I just don't understand it. I am asking for some help from the list. I have attached my slightly modified version of "applyRules" and am hoping to get some comments that will make me "see the light" here. Thanks and best regards Soren -------------- next part -------------- A non-text attachment was scrubbed... Name: IBapplyRules.r Type: application/octet-stream Size: 15789 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20110221/4f3f0c73/attachment.obj>
quantstrat for live trading - some questions
9 messages · Me, Brian G. Peterson, Henry Ward +1 more
1 day later
On 02/21/2011 03:22 AM, me at censix.com wrote:
this is mainly directed to the developers of the great "quantstrat" package. I am happy to continue this conversation with any of them individually. I have been backtesting some strategies on quantstrat. In order to take them live (through the ibrokers package) I have recently begun to write my own versions of some key quantstrat functions, i.e. applyStrategy, applyRules and ruleOrderProc (addOrder is to follow) One thing I have been looking at is how to make the "applyRules" function process only one timestamp at a time (process all rules only for one specific marketdata timestamp). I consider my solution to this problem to be a rather ugly fix that I would really like to avoid, since essentially it looks like the "applyRules" function has already been designed for that sort of thing, but the implementation seems to be buggy or I just don't understand it. I am asking for some help from the list. I have attached my slightly modified version of "applyRules" and am hoping to get some comments that will make me "see the light" here. Thanks and best regards
Soren, Probably best a discussion for off-list. I'll send this initial response to the list, since I think others might find it useful, but the technical discussion likely to follow should probably happen off-list. The biggest difficulty is that basically everything needs to change a little to be handled with streaming data. Let's assume for the moment that your indicator and signal generators are fast enough that you can get data from IB and run them using 'applyIndicators' and 'applySignals' basically unchanged in your event loop. This seems like a reasonable enough assumption, given that we can backtest strategies on tick data (millions of timestamps) in about a minute per day In this case, you'd start by modifying/replacing applyStrategy with your IB event loop that will get data for the instrument(s) you're monitoring, and calculate your indicators and signals. As you've noted, and as is mentioned in the quantstrat documentation, 'ruleOrderProc', 'addOrder', and 'applyRules' also need to change. 'ruleOrderProc' probably goes away entirely in this mode. it exists in the quantstrat package basically as the 'fill simulator' container for turning open orders into transactions in the trade blotter. If you still wanted to keep a 'blotter' of fills, rather than or in addition to simply querying IB whenever you need your position, then it would make sense to modify rather than replace ruleOrderProc. 'addOrder' should in all likelihood be replaced (or overloaded) by a wrapper for the IB order functions. Quickly, I'll talk about dindex in applyRules. It's there predominantly for handling tick data, and can be seen as short for a 'dimension reduction' index. By looking at places where we *might* have to do something, we routinely reduce millions of timestamps to a few hundred on a day of tick data, which, as one might imagine, massively improves the total time it takes to do a backtest. For streaming/periodic data, there is indeed no reason to use dindex, and curIndex can be set to FALSE. It seems that technical implementation details will probably be best hand;ed off-list. Regards, - Brian
Brian G. Peterson http://braverock.com/brian/ Ph: 773-459-4973 IM: bgpbraverock
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20110222/5fb809e4/attachment.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20110222/1852f7d4/attachment.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20110222/b7035ef5/attachment.pl>
On 02/22/2011 11:13 AM, Henry Ward wrote:
Hi Jeff, Thank you for your assistance. Below is my configuration before updating from R-Forge. After updating xts from R-Forge with
install.packages("xts", repos="http://R-Forge.R-project.org")
I restart R and it tells me that xts was built under R 2.12.2 which I don't have. I've updated to the latest 2.12.1 but can't seem to find an xts repository between the cutting edge R-Forge and the older CRAN. Thank you for posting the update on CRAN. If you could shoot me a quick email letting me know when you might be able to do it I'd appreciate. My project requires the marginal VaR calculation. Thanks.
You should be able to use the R-Forge version on R 2.12.1 (with a warning on load). If it won't load the new xts, let us know. But the marginal VaR calc works for me with the latest xts. Regards, - Brian
Brian G. Peterson http://braverock.com/brian/ Ph: 773-459-4973 IM: bgpbraverock
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20110222/cafcb338/attachment.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20110222/d554e746/attachment.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20110222/4332fed0/attachment.pl>