Hi,
Can someone please explaing how to get rid of the “object not subscriptable” error I get when I try to fill an array of symbols with historical closing data. With the MOM indicator it works fine,
Any help will be very appreciated.
Andres
QUANTCONNECT COMMUNITY
Hi,
Can someone please explaing how to get rid of the “object not subscriptable” error I get when I try to fill an array of symbols with historical closing data. With the MOM indicator it works fine,
Any help will be very appreciated.
Andres
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.
Vladimir
Andres Arizpe
Try this way.
If you are satisfied with my answer, please accept it and don't forget to like it.
Andres Arizpe
Hi Vladimir,
Your help is very appreciated.
Using the Identiy indicator does get rid of the error message but it does not load the array with the last closing prices. I get all zero values when I print them as you can see in the attached backtest and the log:
2020-01-01 00:00:00 :Launching analysis for 569479ad05e2b4c36c6ce27df3da2a30 with LEAN Engine v2.5.0.0.136752020-01-01 00:00:00 :2020-01-01 00:00:00 symbol:SPY closingPrice:0.02020-01-01 00:00:00 :2020-01-01 00:00:00 symbol:IGV closingPrice:0.02020-01-01 00:00:00 :2020-01-01 00:00:00 symbol:XLE closingPrice:0.02020-01-01 00:00:00 :2020-01-01 00:00:00 symbol:VNQ closingPrice:0.02020-01-01 00:00:00 :2020-01-01 00:00:00 symbol:XLF closingPrice:0.02020-01-01 00:00:00 :2020-01-01 00:00:00 symbol:XME closingPrice:0.02020-01-01 00:00:00 :2020-01-01 00:00:00 symbol:XHB closingPrice:0.02020-01-01 00:00:00 :2020-01-01 00:00:00 symbol:TBT closingPrice:0.02020-01-01 00:00:00 :2020-01-01 00:00:00 symbol:KWEB closingPrice:0.02020-01-01 00:00:00 :2020-01-01 00:00:00 symbol:OIH closingPrice:0.02020-01-01 00:00:00 :2020-01-01 00:00:00 symbol:XBI closingPrice:0.02021-01-01 00:00:00 :Algorithm Id:(569479ad05e2b4c36c6ce27df3da2a30) completed in 0.94 seconds at 5k data points per second. Processing total of 4,602 data points.How can i load the last closing prices into the array?
Vladimir
Andres Arizpe
How are you going to use self.closingPrices in your algorithm?
Show a sample.
Vladimir
Andres Arizpe
-→I get all zero values when I print them as you can see in the attached backtest and the log:
Try to log closingPrices this way
If you are satisfied with my answer on “object not subscriptable” error, please accept it.
I'll be happy to answer other your questions in another thread.
Andres Arizpe
Hi Vladimir,
I use self.closingPrices to calculate how many shares to buy in my Rebalance method (see attached backtest).
The algo works but once I go live I need to wait at least until the next day (after midnight when OnData has run at least once) to buy or sell stock because otherwise I get an error when I do the number or shares calculation because self.closingPrices is zero until after midnight. So my intention is to use an historical close value to populate the array in the Initialize method to avoid this wait.
I am open to any other way you consider I might avoid this wait once I go live.
Cheers,
Andres
Vladimir
Andres Arizpe
We would recommend to replace on lines 80 and 91 in your last algorithm
lastPrice = self.closingPrices[added]
by
lastPrice = self.Securities[added].Price
If you are satisfied with my answer on “object not subscriptable” error, please accept it.
I'll be happy to answer other your questions in another thread.
Andres Arizpe
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!