Overall Statistics |
Total Trades 0 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Net Profit 0% Sharpe Ratio 0 Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta 0 Annual Standard Deviation 0 Annual Variance 0 Information Ratio 0 Tracking Error 0 Treynor Ratio 0 Total Fees $0.00 |
import numpy as np import pandas as pd class rollingWindowDataFrameExample(QCAlgorithm): def Initialize(self): self.SetStartDate(2019, 2, 1) self.SetCash(5000) # Define tickers self.tickers = ["AAPL","IBM"] for ticker in self.tickers: self.AddEquity(ticker, Resolution.Daily) # Set rolling window period self.period = 10 # Create empty DataFrame self.df = pd.DataFrame(columns = self.tickers) # Use WarmUp to fill the DataFrame self.SetWarmUp(self.period) def OnData(self,data): # Create an empty dictionary dict = {} # Fill the dictionary with prices for ticker in self.tickers: price = self.Securities[ticker].Price dict[ticker] = price # Append dictionary to DataFrame self.df = self.df.append(dict,ignore_index=True) # Return if DataFrame is not filled if self.IsWarmingUp: return # Retrieve last values in DataFrame and convert to numpy array self.Log(str(self.df.tail(self.period).values))