Hello,
I'm quite confused on how to make the Rolling windows work. Because every calculation of each stock just has to be done one time so I just put everything on OnSecuritiesChanged. With the code I have down below would it be smarter to do it another way and is it even possible to do it like this?
After the calculation I have to add the number to the Symbol, do I use SymbolData or just a dict?
def OnSecuritiesChanged(self, changes: SecurityChanges) -> None:
for symbol in [x.Symbol for x in changes.AddedSecurities]:
self.mappings[symbol] = self.AddData(SECReport10Q, symbol).Symbol
history = self.History(SECReport10Q, self.mappings[symbol], 400, Resolution.Daily)
self.Debug(f"We got {len(history)} items from our history request")
a = history.drop(['datasourceid','report'], axis=1, inplace=True)
a = history.index.droplevel('symbol')
for date in a:
# 1. history for date
# 2. calculate time
self.window = RollingWindow[TradeBar](30)
history_std = self.History(symbol, 40, Resolution.Daily)
self.Debug(history_std)
self.std = self.STD(self.mappings[symbol], 10)
self.std.Updated += self.StdUpdated
self.stdWin = RollingWindow[IndicatorDataPoint](30)
self.window.Add(data[symbol])
if not (self.stdWin.IsReady and self.window.IsReady): return
Thanks in advancce!
Louis Szeto
Hi Nico
A fews things to mention in here:
series_std = history_std.close.rolling(10).std()
Then iterate the last 30 rows in the series.
Best
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.
Nico Xenox
Louis Szeto
You are right, the code is very confusing. I wrote a short code in the research notebook to show how it should look like.
I'm trying to archieve this with rolling windows so i can access the values in a simple manner. The problem is no matter what I'm trying in QC, it wont work.
Nico Xenox
Hey again,
I was able to get the 30(in code 50) day history for each of the days and adding the rolling std to it. Thank you for that.
But how do I add the series_std into the window? I assume I cant just ‘self.window.Add(series_std)’
Then how can I add the data into it?
Nico Xenox
Hey Louis Szeto
I was able to figure out another way to get the information I needed.
But I'm still asking myself if adding the series_std into a rolling window would work. Because it seems that just data that is newly generated and updated can be added into the rolling windows and not a ‘Dataframe’.
Anyways thank you for your help!
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!