Hey,
I have a small problem trying to delete dates that already happened in the past. For each value I want to check if the current date is bigger than the value, if thats the case it should delete it from the values list. (Working in Notebook so I replaced self.Time with self.current_time)
My attempt so far:
self.current_time = datetime(2018, 1, 1, 0, 0)
for x in self.dict:
print(x)
for i in reversed(self.dict[x]):
print(i)
if self.current_time > i:
print("yes")
self.dict.pop(i)
Dictionary:
{'NEE': [datetime.datetime(2016, 2, 22, 0, 0),
datetime.datetime(2016, 4, 29, 0, 0),
datetime.datetime(2016, 7, 28, 0, 0),
datetime.datetime(2016, 11, 1, 0, 0),
datetime.datetime(2017, 2, 23, 0, 0),
datetime.datetime(2017, 4, 21, 0, 0),
datetime.datetime(2017, 7, 26, 0, 0),
datetime.datetime(2017, 10, 26, 0, 0),
datetime.datetime(2018, 2, 16, 0, 0),
datetime.datetime(2018, 4, 24, 0, 0),
datetime.datetime(2018, 7, 25, 0, 0),
datetime.datetime(2018, 10, 23, 0, 0)],
'WFC': [datetime.datetime(2016, 2, 24, 0, 0),
datetime.datetime(2016, 5, 4, 0, 0),
datetime.datetime(2016, 8, 3, 0, 0),
datetime.datetime(2016, 11, 3, 0, 0),
datetime.datetime(2017, 3, 1, 0, 0),
datetime.datetime(2017, 5, 5, 0, 0),
datetime.datetime(2017, 8, 4, 0, 0),
datetime.datetime(2017, 11, 3, 0, 0),
datetime.datetime(2018, 3, 1, 0, 0),
datetime.datetime(2018, 5, 4, 0, 0),
datetime.datetime(2018, 8, 3, 0, 0),
datetime.datetime(2018, 11, 6, 0, 0)],
'WMT': [datetime.datetime(2016, 3, 30, 0, 0),
...
datetime.datetime(2017, 11, 22, 0, 0),
datetime.datetime(2018, 3, 9, 0, 0),
datetime.datetime(2018, 5, 31, 0, 0),
datetime.datetime(2018, 8, 31, 0, 0),
datetime.datetime(2018, 11, 28, 0, 0)]}
How it should look like for NEE:
{'NEE': [
datetime.datetime(2018, 2, 16, 0, 0),
datetime.datetime(2018, 4, 24, 0, 0),
datetime.datetime(2018, 7, 25, 0, 0),
datetime.datetime(2018, 10, 23, 0, 0)]}
I guess it has something to do with the positions when deleting values, how do I solve this problem?
Thanks in advance!
Nico Xenox
I solved the issue but is there a better way to write this?
Nico Xenox
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!