Hi all,
special thanks to Louis Szeto and this is a continuation from
I tried to develop a strategy and here are the rules:
Entry:
1. Stocks ≥ 85 decile rank
2. close > 200 simple moving average
3. stochastics (5) ≤ 30
Exit:
1. Stocks < 85 decile rank
I've modified the code but I've faced 3 issues:
1. If I set my universe resolution to daily, I receive “Warning: fill at stale price”. However, when I change the resolution to hour (in order to schedule a function), I get the following error:
KeyNotFoundException : 'HUM R735QTJ8XC9X' wasn't found in the TradeBars object, likely because there was no-data at this moment in time and it wasn't possible to fillforward historical data. Please check the data exists before accessing it with data.ContainsKey("HUM R735QTJ8XC9X")
at QuantConnect.Data.Market.DataDictionary`1.get_Item(Symbol symbol) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Common/Data/Market/DataDictionary.cs:line 228
at OnData
symbolTradeBar = tradeBars[symbol]
===
at Python.Runtime.PyObject.Invoke(PyTuple args in main.py:line 83
2. There seems to be too many trade for a short period of time. The objective is to liquidate symbols not in the short list (self.potential) but the algo seems to liquidate and cancel the order. I'm not sure why.
3. The back test take a long time to run. Maybe there is a better way to improve the code?
Open to suggestions and I hope somebody can help me understand the error that is happening
Thanks a lot!! 😊
Louis Szeto
Hi Ang
Before this, I want to tell you I forgot to put in updating method for PPO's rolling window, but the post has closed. Please add it back thx 😂😂
Sorry
Louis
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.
Ang Jin Wei
Hi Louis,
I'm not sure how can I re-open closed discussion but do you mean this?
Louis Szeto
Hi Ang
Please refer to the following backtest for the updating of rolling window. But some more questions from your backtest: why do you need self.potential, won't self.SCTRuniverse handled them all? And you actually never liquidate anything else except those not inclusive in coarse/fine universe anymore, as nothing ever removed from self.potential.
For your questions:
If you wish to use higher resolution, you can schedule and directly change the name of OnData into your scheduled function name, removing if data.ContainsKey() part. It should work just fine.
Cheers
Louis
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.
Louis Szeto
Why I remove your entryindicator class? It is for speed (assume memory is not concern):
using same class but 2 more indicators with existing dataframe, we'll do 500*.85 (unused equities) extra calculation: time complexity = constant (time for queuing indicator value) * (2*500*.85) = 850c
vs
using new class calling new 200-day history dataframe to loop for 500*.15 shortlisted equities:time complexity = constant (time for queuing indicator value) * no. of tickers (200) * 500*.15 = 15000c
Of course there will be redundant memory used for 2 more indicators (their pointers and 200/5 8-byte decimal value)
Louis
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.
Ang Jin Wei
Hi Louis,
Thank you so much for your help! I have some questions 😅
‘SetHoldings’ is used here; hence the portfolio will hold long positions whenever stochastic is ≤30. However, the objective is to stay long in the position until it is no long in the 85th decile rank.
Do you think by changing to this help to stay long in the position?
Also, the position will only liquidate once it is remove from the universe. The universe referred here is the 500 returned from ‘FineFilter’ right? Since not 'self.SCTRuniverse', will it continue to stay long even when it is lesser than the 85 decile rank?
Will adding the above liquidate position not in 'self.SCTRuniverse' but is still part of the universe returned in ‘FineFilter’?
Cheers!
Ang
Louis Szeto
Hi Ang
Sorry missed that part. I'll suggest just adding one more line at the end of OnData shall be fine:
Cheers
Louis
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.
Ang Jin Wei
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!