Hi all,
I am a novice in QC and python. I am working on applying RSI on the stock "ROKU" and write backtest code on Jupyter notebook using (ib_insync and ta.momentum). My prof. hopes us to understand how backtest works in QC. I used MovingType.Simple for RSI, but after talking to Alex, I change into MovingType.Wilder. I still get unmatched results. I am encouraged by my prof. to search for help there!
1. In "orders" of backtest, it calls 3110 shares on Market open at 32.85$ in 2018-3-24.
- My initial cash is 100,000. Since 100,000//32.85 = 3044, then how QC gets 3110 shares.
- How QC executes the order on 2018-03-27 at $32.85 that was placed on 2018-03-24 (Saturday)? The historical data from IB tells that open price in 2018-03-27 is 33.55.
Yd124
I realized that rsi is calculated differently in QC and ta.momentum. I used Quant Book and code given by QC document (You can view in my backtest notebook):
https://github.com/QuantConnect/Lean/blob/master/Research/KitchenSinkQuantBookTemplate.ipynb
I define the (enter,exit) = (40,60) by training in QC. However, if I use the same thresholds, I didn't get similar results as QC. One thing I observe that because of different rsi, in QC, it enters the market on 2018-03-24 (or say on 2018-03-27) but using ta.momentum, it enters the market on 2018-03-23. At the end of 2019, I only earn 28,336 using ta.momentum which is much less than 63,420.42 in QC. Can someone explain that? or would someone like to tell me how to calculate t__he net profit so that my final resluts can be close to the one in QC?
I will attach the picture!
Yd124
Derek Melchin
Hi Yd124,
> My initial cash is 100,000. Since 100,000//32.85 = 3044, then how QC gets 3110 shares.
With daily data, orders are placed at midnight. At this point, the latest price we have available is the most recent close, so we use this value to determine position sizing. In the attached backtest, we see the closing price for the first order was $32.06. The algorithm used a Market On Open order, which was filled at the next day's open price ($32.85). In addition, the default cash buffer is 2.5%. If we disable the cash buffer, we can see the order size is now
100,000 / 32.06 = 3118
See the attached backtest for reference.
> How QC executes the order on 2018-03-27 at $32.85 that was placed on 2018-03-24 (Saturday)? The historical data from IB tells that open price in 2018-03-27 is 33.55.
When backtesting, daily orders are filled at the official opening auction prices. These prices prices may differ from the IB's internal data.
There are two reasons why the TA Lib RSI indicator differs from our RSI indicator implementation.
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.
Yd124
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!