Back

How to backtest with historical limit order book data

Hi all,

I am new to QuantConnect and still in the stage of understanding how QuantConnect works.

I am particularly interested in backtesting algo trading strategies with the use of limit order book information, e.g. market making strategy. Assume I have obtained historical limit order book data with bid/ask/trade ticks, how may I backtest with QuantConnect? Thanks very much!
Update Backtest








Have a peek at the QCU How Do I Import Yahoo Data? example algorithm available under the university tab on the left in the backtester. In short, you'll need to define a custom type that derives from BaseData and implement the Reader and GetSource methods. Reader will take a line of your data and parse it into your custom data type. The GetSource method will return information about how to access the data.

Once this is defined, you'll need to add the data using the AddData method and then it will be routed into a special OnData(MyCustomDataType data) event handler and will also be available via the OnData(Slice) method.
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.


Hi Michael,

Nice to meet you.

Wayne
0

Hi Michael,

Many thanks for your reply. The reference at QCU is very useful!

I wish to ask one more question. Suppose I have created the custom data and implement OnData method to reconstruct the order book, in order to backtest market making strategy, I need to further consider order submission and cancellation events in the order queue, as well as the trade fill events, are there any methods/classes in QuantConnect for handling these events so that I can refer to and have a look?

Thanks again and appreciate your help!

Wayne
0

All order events will come through your algorithm's OnOrderEvent(OrderEvent) handler. All new orders, fills, and cancellations will go through this handler. An important note is that it will only be *your* new orders, fills and cancellations that get pumped through here, not the fills of other market participants.

You can define it like this:public override void OnOrderEvent(OrderEvent orderEvent)
{
var order = Transactions.GetOrderById(orderEvent.OrderId);
Console.WriteLine("{0} >> ORDER >> " + order, Time);
}

Here's a link to the OrderEvent class.
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.


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