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.482 Tracking Error 0.051 Treynor Ratio 0 Total Fees $0.00 Estimated Strategy Capacity $0 Lowest Capacity Asset |
''' Test code for Floor/Ceiling code. ''' import pandas as pd # from swings import add_swings_fp # from floor_ceiling import add_regime_fc class FloorCeilingTest(QCAlgorithm): def Initialize(self): self.SetStartDate(2021, 8, 3) self.SetEndDate(2021, 8, 17) self.SetCash(100000) resolution = Resolution.Daily self.inst = self.AddForex('EURUSD', market=Market.Oanda, resolution=resolution, fillDataForward =False) # self.inst = self.AddForex('NZDUSD', market=Market.Oanda, resolution=resolution, fillDataForward =False) # self.inst = self.AddForex('USDJPY', market=Market.Oanda, resolution=resolution, fillDataForward =False) # Get history to populate the price DataFrame. self.inst_data_df = self.History(self.inst.Symbol, 1000) self.inst_data_df = self.inst_data_df.loc[self.inst.Symbol, ['high', 'low', 'close']] # self.Debug(str(self.inst_data_df.iloc[-2]) # + '\n' + str(self.inst_data_df.iloc[-1])) # Set up a chart for the regime data. test_chart = Chart('Test Plot') test_chart.AddSeries(Series('Close', SeriesType.Line, 0)) test_chart.AddSeries(Series('H-High', SeriesType.Line, 0)) test_chart.AddSeries(Series('H-Low', SeriesType.Line, 0)) test_chart.AddSeries(Series('H-Close', SeriesType.Line, 0)) self.AddChart(test_chart) def OnData(self, data): ''' OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here. Parameters: data: Slice object keyed by symbol containing the price data ''' # Update the instrument data DataFrame. new_row = { data[self.inst.Symbol].EndTime : [data[self.inst.Symbol].High, data[self.inst.Symbol].Low, data[self.inst.Symbol].Close]} new_row = pd.DataFrame.from_dict(new_row, orient="index", columns=["high", "low", "close"]) self.inst_data_df = self.update_price_history(self.inst_data_df, new_row) # self.Debug(str(self.inst_data_df.iloc[-2]) # + '\n' + str(self.inst_data_df.iloc[-1])) self.Debug(str(self.Time) + ": THLC = " + str(self.inst_data_df.index[-1]) + ", " + str(self.inst_data_df.iloc[-1]["high"]) + ", " + str(self.inst_data_df.iloc[-1]["low"]) + ", " + str(self.inst_data_df.iloc[-1]["close"])) self.Plot('Test Plot', 'Close', data[self.inst.Symbol].Close) self.Plot("Test Plot", "H-High", self.inst_data_df.iloc[-1]["high"]) self.Plot("Test Plot", "H-Low", self.inst_data_df.iloc[-1]["low"]) self.Plot("Test Plot", "H-Close", self.inst_data_df.iloc[-1]["close"]) def update_price_history(self, history_df, new_row): ''' Rolls the price history by adding the new row and dropping the oldest. Parameters ---------- history_df : DataFrame The price history DataFrame. new_row : DataFrame The new row as a one-row DataFrame. Return ------ history_df : DataFrame The supplied history rolled forward one data period. ''' # self.Debug(str(self.Time) + ": new_row = " + str(new_row.name) + ": " + str(new_row)) history_df = history_df.append(new_row) history_df.drop(history_df.index[0], inplace=True) # self.Debug(str(self.Time) + ": THLC = " + str(self.inst_data_df.index[-1]) # + ", " + str(self.inst_data_df.iloc[-1]["high"]) # + ", " + str(self.inst_data_df.iloc[-1]["low"]) # + ", " + str(self.inst_data_df.iloc[-1]["close"])) return history_df