SmartQuant Discussion

Question regarding simulation and bars
Page 1 of 1

Author:  bean3178 [ Wed Nov 06, 2013 3:53 am ]
Post subject:  Question regarding simulation and bars

Up to this point I haven't used OpenQuant for simulation/back testing. I would now like to implement simulation/back testing in my strategy and I don't fully understand how the simulator works. In my strategy, I build my own bars from trades so that I can accommodate any time frame (i.e. 5 hour, 7 hour, 4:30 hour, 5:40 hour, etc.). I do this by pulling 5 minute historical bars and then combining them to the desired time frame using a custom method. I add/update using Bars.Add (so they are plotted) and my indicator is based off of those bars. If the time frames don't evenly divide into 24 hours, I'll typically start a new bar at 00:00:00 to keep things uniform.

If I add 5 minute bars to "Market Data" and run the simulation, OpenQuant plots 5 minute bars. Is there a way to add bars with custom (and possibly non-uniform) time frames into the Data Manager for the simulator to run against? If so, how? If not, what is the best way to accomplish this? Should I run the simulator with 5 minute bars, but create a separate BarSeries with my custom time frames by calling my custom method in the OnBar() method? Then, use my separate BarSeries as my indicator input? If this is required, is there a way to plot my BarSeries rather than have the 5 minute bars plotted (since I'm not using them for anything other than creating my own bars)?

Author:  Baraz Sergey [ Wed Nov 06, 2013 10:59 am ]
Post subject:  Re: Question regarding simulation and bars


OQ doesn't build uniform bars by default, but yes, you can build them in the strategy code if you need. The best way to do what you need is to create a BarSeries in OnStrategyStart handler, like:
myCustomBarSeries=GetBars((5 * 60 + 40) * 60);
(for 5:40 bars), use this series as your indicators input and add bars to this series in the strategy code. In this case this series will be plotted on the BarChart. There is no way to remove 5 min bar series from the BarChart if 5 min bars are subscribed in the MarketData section, though you can clear this series in OnStrategyStop handler if you need:


Author:  bean3178 [ Wed Nov 06, 2013 3:21 pm ]
Post subject:  Re: Question regarding simulation and bars

Okay, so I already have everything working in Live/Paper mode using Trade data only. It sounds like for simulation to work properly, I need to subscribe to 5 min bars in simulation mode, build my own custom bars in a new BarSeries, and use that BarSeries for my indicator. When simulation runs, it will run against the 5 minute bars, but my strategy code will only reference my BarSeries and indicator for the logic. At this point all back testing data should be correct, but just the chart will be incorrect.

Am I understanding all of this properly?

Page 1 of 1 All times are UTC + 3 hours
Powered by phpBB® Forum Software © phpBB Group