Hi
I'm very new to QuantConnect.
I have created attached backtest.
For context, the intention of the algorithm is to score all the members of the QC500 universe with a momentum score based on linear regression then trade the top 30 stocks long if the score is over 40.
I havent worked out yet how to do it but I want to only trade every 1 week for new insights and to rebalance by risk parity and monthly for changes in QC500(which I believe is the default update period for QC500 anyway).
I get the above error (Runtime Error: Cannot implicitly convert type 'Python.Runtime.PyObject' to 'decimal' in PythonIndicator.cs:line 144), which is being caused by self.Value in the custom indicator.
I know this because if I change the variable name to self.Score, it doesnt error and runs through. Anyone have any idea how I can use the intended self.Value without creating the error.
Also any help implementing my intended timing of rebalancing would be appreciated
(The attached backtest uses the self.Score version as I cant attach a failed backtest with the self.Value being updated.)
Thanks for any help.
Mark
Nico Xenox
Hey Mark Gahagan,
the self.Value is a reserved property for the underlying class. You will have to use another name for it.
You also asked for weekly insights, so I changed the code to emit insights once per week (attached backtest).
Hope it helps ;)
Mark Gahagan
Hi Nico
Thanks for the speedy response.
So my using self.Score was probably the best thing I could do instead of self.Value
Also, it appears from your code that my trying to use the algorithmic framework ie. the alpha model was not the best way to code this.
Thanks for the insights ;)
Mark
Mark Gahagan
To avoid this error that occurs as well although handled:
Backtest Handled Error: TXG X7SGNKRL4WV9: The security does not have an accurate price as it has not yet received a bar of data. Before placing a trade (or using SetHoldings) warm up your algorithm with SetWarmup, or use slice.Contains(symbol) to confirm the Slice object has price before using the data. Data does not necessarily all arrive at the same time so your algorithm should confirm the data is ready before using it. In live trading this can mean you do not have an active subscription to the asset class you're trying to trade. If using custom data make sure you've set the 'Value' property.
Whare and how should I use the code suggested ie. slice.Contains(symbol)?
Derek Melchin
Hi Mark,
To fix the issue, we need to reset the dictionary of momentum scores before each rebalance.
See the attached backtest for reference.
Best,
Derek Melchin
Want to invest in QuantConnect as we build the Linux of quant finance? Checkout our Wefunder campaign to join the revolution.
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.
Mark Gahagan
Thanks Derek,
That has totally solved that issue.
One other issue:
With the stock: RIDE, it always creates two insights and two identical trades on the same date. I have researched the stock and cant find any reason for it(not got duplicate listing). It doesnt happen with any other stock. Is this an issue in QC or an issue with the stock?
Mark Gahagan
Regarding the issue with RIDE:
I did some more backtesting as per attached and the algo is picking up the old ticker for RIDE which was DPHC, as well as the new symbol.
DPHC has been reallocated so is still active. Hence it creates two insights and two trades. Not sure how to solve that issue generically so would need to do a workaround each time it occurs with a stock which isnt ideal, but my understanding is limited and may be flawed
Mark Gahagan
sorry, forgot the backtest
Derek Melchin
Hi Mark,
Thanks for reporting this. To track our progress of resolving this error, subscribe to this data issue.
Best,
Derek Melchin
Want to invest in QuantConnect as we build the Linux of quant finance? Checkout our Wefunder campaign to join the revolution.
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.
Mark Gahagan
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!