Hi All,
Ive been digging through the docs but i cant seem to find an answer to this simply. I'm running a simple system where we add the bar data to a rolling window every time it comes in using the method shown in the documentationand all i want to do is turn the rolling window with the tradebardata into a dataframe with the indexs as open high low close volume but using the pd.Dataframe method never seems to work for me and I cant seem to get the thing working, can someone tell me what im doing wrong?
cheers
Matt
# region imports
from AlgorithmImports import *
import tensorflow
import pandas as pd
import statistics
# endregion
class HyperActiveRedViper(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2022, 6, 20) # Set Start Date
self.SetCash(100000) # Set Strategy Cash
self.AddEquity("SPY", Resolution.Minute)
self.counter = 0
self.State = None
# Create a Rolling Window to keep the 2 TradeBar
self.tradeBarWindow = RollingWindow[TradeBar](10000)
self.SetWarmUp(10000) #warm up 10000 bars
# In OnData, update the rolling windows
def OnData(self,slice):
#first we check the data for this slice to see if it has data for our ticker in it
#if so then we add the data to our rolling window.
if slice.ContainsKey("SPY"):
self.tradeBarWindow.Add(slice["SPY"])
#Next we take the rolling window and move it to a dataframe
df = pd.DataFrame(self.tradeBarWindow)
self.Debug(df)
#Now we run the calculations to create our interpretation columns for the ML model to predict on.
df['Change'] = df.apply(lambda row: self.calculate_price_change(row), axis = 1)
#self.calculate_close_bar_shape(self.tradeBarWindow[0])
#self.calculate_open_bar_shape(self.tradeBarWindow[0])
if len(self.tradeBarWindow) > 10001:
self.Quit()
Adam W
`RollingWindow` and `TradeBar` are QC API Python classes, so pandas doesn't just automatically know how to put this into a dataframe.
You can do something like the following:
Louis Szeto
Hi MatteMatto and Adam
Lean provides a conversion helper method PandasConverter.GetDataFrame<TradeBar> to aid in easy conversion from RollingWindow<TradeBar> into DataFrame. Please refer to this doc for its usage.
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.
MatteMatto
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!