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 Probabilistic 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 2.486 Tracking Error 0.23 Treynor Ratio 0 Total Fees $0.00 |
import pandas as pd class OptimizedVerticalSplitter(QCAlgorithm): def Initialize(self): self.SetStartDate(2021, 1, 2) # Set Start Date self.SetCash(100000) # Set Strategy Cash symbol = self.AddEquity("SPY", Resolution.Minute).Symbol self.rsi = RelativeStrengthIndex(5) self.ema9 = ExponentialMovingAverage(9) # create the 36-minutes data consolidator threeCountConsolidator = TradeBarConsolidator(timedelta(minutes=30)) threeCountConsolidator.DataConsolidated += self.ConsolidationHandler self.SubscriptionManager.AddConsolidator(symbol, threeCountConsolidator) self.indicator_history = pd.DataFrame() history = self.History(symbol, 30*9, Resolution.Minute) if not history.empty and 'close' in history.columns: for i, (time, row) in enumerate(history.loc[symbol].iterrows()): if i % 30 == 0: self.update_indicators(time, row.close) def update_indicators(self, time, value): if self.rsi.Update(time, value): self.indicator_history.loc[time, 'rsi'] = self.rsi.Current.Value if self.ema9.Update(time, value): self.indicator_history.loc[time, 'ema9'] = self.ema9.Current.Value self.indicator_history = self.indicator_history.iloc[-10:] def ConsolidationHandler(self, sender, consolidated): self.update_indicators(consolidated.EndTime, consolidated.Close) def OnData(self, data): if data.Time.minute == 1 or data.Time.minute == 31: self.Log(f"RSI: {self.rsi.Current.Value} EMA: {self.ema9.Current.Value}") def OnEndOfAlgorithm(self): self.Log(f"Indicator History: {self.indicator_history.to_string()}")