Feature: Simulator Hooks

This post is irrelevant to the v2 engine. See our post regarding TuringTrader 16 to learn more about what changed and why.



TuringTrader's new simulator hooks allow developers to fine-tune backtesting behavior. Let's have a brief look at what we can use these hooks for:

FillModel

protected virtual double FillModel(Order orderTicket, Bar barOfExecution, double theoreticalPrice)

A backtest is only as accurate as the assumptions fed into it. One of the more important assumptions is the fill price for orders. With the FillModel hook, we can develop complex fill models, taking the order type and the current bar of the instrument traded into account.

IsValidSimTime

protected virtual bool IsValidSimTime(DateTime timestamp)

TuringTrader validates simulation timestamps before passing them on to the algorithm. This is helpful when trading in multiple markets simultaneously, which might differ in their trading calendar.

With previous versions, this behavior was deeply buried inside the simulator. We have now exposed this functionality with the IsValidSimTime hook to make it easy to customize.

CalcNextSimTime

protected virtual DateTime CalcNextSimTime(DateTime timestamp)

Many strategies have weekly or monthly trading schedules. Often, we want to place our orders on the last day of the week (or month), so that they are executed on the open of the new week (or month). Because we haven't seen the next bar yet, more complex logic is needed to get this timing right, especially in the light of holidays.

The CalcNextSimTime hook returns the next sim time, based on the current simulator time stamp. We can use this to customize the trading calendar as we see fit.

IsValidBar

protected virtual bool IsValidBar(Bar bar)

Every strategy is different, and the choices we make to validate bars might be dependent on the strategy or its implementation. With the IsValidBar hook we can specify which bars are valid and which ones are not, so that we at least see a warning when calculating NAV or placing orders against bars we deem invalid.

Happy coding!