Time/date periods
StartDate
Start of the simulation. The start date can be determined in several different ways:
-
A 4-digit number (f.i. 2006) gives the number of the historical data file with which the simulation starts (f.i. EURUSD_2006.t6). If the file has no year number (f.i. MSFT.t6),
StartDate is ignored and the simulation starts with the start of the file.
-
A date in the 8-digit yyyymmdd format starts the backtest at a certain date (f.i. 20090401 = April 1st, 2009). The simulation period begins earlier because the LookBack period is added in front of the date.
Due to the lookback period, StartDate = 2006 starts the backtest normally at a later date than StartDate = 20060101.
- StartDate = NOW; sets the start date to the current day, and executes the run function in [Trade]
mode immediately after the lookback period, regardless of the current time. Useful for strategies that do not run permanently, but are only started for modifying a portfolio.
- StartDate = 0; (default) starts the simulation with the year number given by NumYears before the current year.
EndDate
End of the simulation, either 4 digits for determining the number of the last historical price data file (similar to StartDate), or a date in yyyymmdd format for ending the backtest at that date (f.i. 20091231 = December 31, 2009),
or NOW for the current day. If at 0 (default),
the simulation runs until the end of the available price history. In January it
runs until the end of the price history of the previous year.
NumYears
Number of years of the simulation if no StartDate or EndDate is given (default: 6 years). The current year counts as one full year. Set NumYears to -1 for not loading any prices by assetHistory.
MaxBars
Maximum number of bars of the simulation (default: 0 = no limit). The simulation ends either at EndDate or after the given number of bars (including the LookBack period), whichever happens earlier.
UpdateDays
Interval in days for automatically downloading new price data and adding it to the price history file (default: 0 = don't download new price data). If the price history is older than the given number of days, the download process starts automatically at the begin of a [Test] or [Train] cycle. Set UpdateDays to -1 for always loading all prices up to the current time.
ReTrainDays
Interval in days for automatically retraining a live trading system (Zorro S required; default: 0 = no automatic retraining). Set this to the duration of the WFO test period for keeping a WFO trained system in sync with the market.
GapDays
Maximum allowed gap in days in the historic prices and in the downloaded price data (default: 0 = no gap checking). Set this to 2 or above in order to check the price curve for gaps and inconsistencies, and give an Error 047 message if any are detected. Weekends and international holidays are except from gap checking. Gaps of 1 day are normal in historic prices due to national holidays.
StartWeek
Start of the business week in dhhmm, where d = day number (1 = Monday .. 7 = Sunday), hh = hour and mm = minute
(not used). Default: 72300 (Sunday 23:00). Used to determine the
weekend for BarMode flags.
EndWeek
End of the business week in dhhmm as above Default: 52000 (Friday 20:00).
Weekend begins at this time. Used to determine the weekend for BarMode
flags.
StartMarket
Daily market opening time in hhmm local time format, hh = hour and mm = minute. Default:
0930. Used for the day and market functions
and for AssetMarket.
Also prevents trading before this time and sampling of bars dependent on
BarMode flags.
EndMarket
Daily market closing time in hhmm local time format, hh = hour and mm = minute. Default: 1600. Used for the day and market functions
and for AssetMarket. Also prevents trading at or
after this time and sampling of bars dependent on BarMode
flags. Set StartMarket = EndMarket = 0 for disabling
market closing.
Type:
int
Holidays
Pointer to an int array of holiday dates either in
yyyymmdd or in mmdd
format, ending with 0. Default: { 0101, 1225, 0 }. Can be set
to a 0-terminated array for defining local stock market holidays.
The yyyymmdd format specifies a holiday only in a certain year,
mmdd for all years.
Type:
int*
Now
Date/time in Windows DATE format for passing a certain
point in time to the contractUpdate function or to
the date/time functions
that support the NOW argument. When at 0 (default), the current PC date and time is used
for NOW.
DayOffset
Time period in Windows DATE format to be added to the
current time in [Trade] mode, for a quick-and-dirty test of
the live behavior at a particular day, or at weekend or market closure. Set it to
1 or adding a day, or 1./24 for adding one
hour to the current time. Affects also the lookback period and the time of a connected
server; does not affect timestamps of historical data.
Type:
var
Remarks:
- The earliest possible StartDate is determined by the availability of historic price data. M1 data back to 2002 can be downloaded from the Zorro website. In 2002 the EUR replaced national currencies; currency backtests before that date make not much sense as the EUR pairs were not traded in volume and the Forex markets behaved different.
- StartDate and EndDate can be used to 'zoom' the backtest to a certain period and examine the trade
behavior of that period in more detail.
- If the StartDate lies before the history start of the
first asset, the simulation begins with the first bar of the history. If
COMMONSTART is set, the simulation begins with the
latest history start of all assets. The simulation ends with the earliest
history end of all assets or with EndDate, whichever is
earlier.
- StartWeek, EndWeek,
StartMarket, EndMarket have normally little effect
on bar generation, since historical data contains anyway no price ticks
during market closure, weekends, or holidays. However they can be used to
limit trading time even during market hours or to determine market hours
when BR_FLAT was set.
- StartDate, EndDate, NumYears and UpdateDays affect price data loading and thus must be set before loading prices or calling asset.
- WFO parameters and rules are only valid for the simulation period with which they were created. If the period is changed, the strategy must be trained again. When re-training the last WFO cycle, set
EndDate to 0, otherwise the training period ends with
EndDate.
- The initial run of a strategy (INITRUN) has no valid date since the start and end date are set in this run.
- For simulating a 'fast forward' mode in a live trading test, use a
tock function that adds a time period to
DayOffset at every minute. For instance, DayOffset +=
0.9/1440 lets time pass 10 times faster.
Example:
StartDate = 20150901; // start the simulation in September 2015
EndDate = 20160901; // and simulate one year.
static int USHolidays[10] = { 0101, 0218, 0419, 0704, 0527, 0902, 1128, 1225, 0 };
Holidays = USHolidays; // set up US holidays
See also:
bar, BarPeriod, LookBack, Detrend, time/date functions, PlotDate
► latest version online