Hi
Based on the data in the Tick data folder, which includes trade and quote, I have attached an algorithm to create a limit order book (L2 data).
Due to backtesting limitations, I have drawn price and volume charts every 5 minutes. The midprice and weighted order imbalance ratio are plotted in the chart. As far as I know this ratio is important in HFT and by using this ratio we can have a better price forecast.
I would be very happy if you make a suggestion regarding increasing the accuracy of the results and its usability.
In some cases, the getLOrders method does not work properly by changing the date of the algorithm due to the presence of some Trade orders at the time before the market Open or quote orders outside the range. It is clear that Cancel orders are not considered in this algorithm. I would be happy if you have a suggestion to correct it.
I hope we can better predict midprice in intrady trading by using this algorithm and ML ideas and statistics and parameter optimization. As there are many papers on this topic. And it can be used in the Algorithm Framework to send more accurate Insights.
Best,
R.Faidi
Derek Melchin
Hi R.mat faridi,
The algorithm above throws an IndexError because it is trying to pop from an empty heap. See the attached backtest logs for reference.
Best,
Derek Melchin
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.
R.mat faridi
Hello, and thank you for bringing up that topic.
As previously stated, some out-of-range orders may cause the algorithm that generates the Lb and Ls stacks to fail.
However, the algorithm performed correctly the previous time it was run, and the accompanying charts were generated.
However, I made the following changes to the date:Â Â Â Â
self.SetStartDate(2015, 10, 8) self.SetEndDate(2015, 10, 8)
I have sent the results and chart that were acquired without error.
Filling stacks X and Y with trivial data, such as the following, is one way to prevent this problem:
Pmin = -10 Pmax = 1000 self.Lb = [[Pmins,1],[Pmins+1,1],[Pmins+2,1],[Pmins+3,1],[Pmins+4,1]] self.Lb = [[Pmax,1],[Pmax+1,1],[Pmax+2,1],[Pmax+3,1],[Pmax+4,1]]
As intraday orders are entered, irrelevant data is gradually placed at the bottom of the stack.
Of course, based on the data we have, I think about whether the algorithm works properly and whether the results are reliable or not.
There may be other qoute and trade data that are not included here.
Best,
R.Faridi
Varad Kabade
Hi R.mat faridi,
The above algorithm had a bug in getLOrders() method(case where t = 1) while we are popping the element without checking if the heap is empty. If our heap becomes empty during any iteration, we have an incomplete order. The fix is adding and len(bu)>0 in the condition for the while loop. See attached backtest for reference.
Best,
Varad Kabade
R.mat faridi
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.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!