Get Data Range when backtesting
Author: sburgener
Creation Date: 11/22/2012 12:06 PM
profile picture

sburgener

#1
Hi,

I have been searching on your forum and webpage but couldn't get to the bottom of what I was looking for.

Is there a Wealthscript function to retrieve the start and end dates of your backtesting settings in the C# code, (the <i>Data Range</i> being set set in the top left corner of your WealthLab window)?

The reason for the above is that I am running a strategy on a futures strip (with futures reaching back to, say, Jan 2000) and it turns out that the various futures only have data for 2.5-year windows. I then would like to identify which one is the first futures to consider, given the backtesting start date (which I set to say 2002 and I would like to ignore all futures which are pre-2002).

Thanks,
Seb
profile picture

Eugene

#2
Hi,

QUOTE:
Is there a Wealthscript function to retrieve the start and end dates of your backtesting settings in the C# code, (the <i>Data Range</i> being set set in the top left corner of your WealthLab window)?

There are many ways:

1. Simple: Bars.Date[0] and Bars.Date[ Bars.Count-1 ]. What can be simpler?

2. Exotic: parse the strategy's XML file (User Guide > Data > Where data are stored?). Here I mean the DataRange xml tag with StartDate and EndDate.

3. Advanced: use System.Reflection to obtain the current strategy window's WealthScript property. 95% of the code required by this task already lives inside Community.Components. Open up the solution, find the StrategyChartForm class, and add this method somewhere next to GetPositionSize(), IsRawProfitMode() etc:

CODE:
Please log in to see this code.

QUOTE:
and I would like to ignore all futures which are pre-2002).

You might want to look up Bars.FirstActualBar in the QuickRef.
profile picture

sburgener

#3
Thanks for the detailed answer Eugene!

As expected, the first method doesn't return what I was looking for in cases where the DataSeries starts after the Start Date as defined in Data Range in the top left corner of WealthLab. Indeed, the value I get is the start of the DataSeries which is currently being processed instead of the start of the backtesting window.
Same comment for Bars.FirstActualBar which I had also tried before asking you.

The third method however is quite straightforward and returns exactly what I was looking for! Thanks!


profile picture

Eugene

#4
Good to know it helps. You're welcome.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).