Back

Backtesting Order Fill Criteria / Engine and Other features

Hi All, first of all congrats on what seems to be a great project. 

I've been programing in Ninjatrader for some time. My biggest criticism with NT, (which I have several but this is one of the deal breakers) is that for quant trading the backtesting features are not at par with the rest of the platform. Without getting into many details, the fill order criteria on limit orders can be one of two in NT. 

  1. Fill on touch
  2. or not. In this case there is an order engine that is supposed to estimatite a real fill process (queue) based on market conditions. 

I don't see much use for 1) if the object is to run it on live market conditions. The second one is more useful and there could be an even worst case scenario such as "fill on penetrate" for example where a limit order gets filled if price surpasses the limit by a tick. NT's problem is not this criteria, but how the data is streamed during backtesting and how the orders are filled. All though with NT8 there is an option to have "Tick Replay" during backtesting which basically streams the data tick by tick, the fill process when "fill on touch" is not selected generates wrong fills; meaning orders will often not get filled where they are supposed to (usually there will be a 1 tick difference from where the order should have been filled). 

For a discretionary trader with large tragets, that is probably insignificant, but for quant trading it could imply a big difference. 

1st question: could you tell me what fill criterias are available with LEAN? I understand there is only one data stream mode (tick by tick) for both back testing and live trading which is PERFECT, so I'm just curious to understand the fill process of limit orders. 

My second criticism of NT is the CRASH ratio of the aplication itself and its inability to automatically recover from it.

2nd question: 
- how does LEAN handle or the service running LEAN recover from eventual crashes? 
- how does LEAN handle connection losses to either data feed or broker? 
- is there a way to get notifications in such cases?

Many thanks, 

Julio

Update Backtest








At the moment, we have just one fill model (ImmediateFillModel) that will use information from the last bar which resolution depends on the data subcription. For instance, say you subscribed to minute-resolution data:

AddEquity("SPY", Resolution.Minute)

It is 10 am, you hold SPY, its price is $102 and you have a stop market order at $100.
The next minute, 10:01 am the price is $100 (meaning that stop market order would not be filled), but from 10 to 10:01 there was a low at $98, so that order is market as filled for $98 (plus slippage). 
Despite the fact we have only one fill model, we provide two slippage models. ConstantSlippageModel (default) and VolumeShareSlippageModel. With these models, we expect to capture some sort of impact of market conditions. 

Needlessly to say, we can backest with higher resolution:

AddEquity("SPY", Resolution.Second);
AddEquity("SPY", Resolution.Tick);

but there is no "tick replay" like feature. Howeve, please note that our tick data is timestamped to the second.

If Lean crashes, you receive an email. The algorithm will not redeploy automatically. When you manually redeploy, Lean will fetch your positions from the brokerage, but the values of local variables of your algorithm will be lost.
If Lean loses connection, it will retry to reconnect a couple of times. You can set up, in your code, email/sms notitifications for that case.

0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


You can also easily define your own fill models.
0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Guys thanks for getting back to me asap. Jared I'll take a look at the fill models. Eventually I guess I could work with stop limit orders only for both entry and exit to eliminate abiguity in the fill process. 

Alexandre you mentioned that the Tick data is timestamped to the second. If that is the case the Tick Resolution would be equivalent to the Second resolution? 

Thanks,

Julio

1

Just to clarify my question on the timestamp. 

A Tick Resolution data should look something like this:
yyyyMMdd HHmmss fffffff;last price; bid price; ask price;volume

Whereas a Second Resolution data should look something like this:
yyyyMMdd HHmmss;last price; bid price; ask price;volume

So if Tick Resolution is timestamped to the second only then there is really no Tick Resolution data for backtesting. Is this correct? I appreciate your feedback as this is super crucial for my particular projects.

Thanks,

Julio

0

Tick resolution is stored as milliseconds since midnight for equities. 

For US equities we have tick data ordered; but rounded to the nearest second in backtesting. Live the tick data is realtime off the exchanges. This is mentioned many time in the forums but I've updated the documentation to make its mentioned there too.

0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Thanks Jared, sorry to make you repeat the info. What about Futures data? Do you have milliseconds on the historical data for Futures?

0

CFD, Forex, Futures milliseonds yes; options Minute only. Equities rounded to second.

0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


PERFECT! Thanks... I'll give it a shot... 

Julio

1

Can I please have an example of the VolumeShareSlippageModel in python ?

0

Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed