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 FloorCeiling

class FloorCeilingTest(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2021, 8, 3)
        self.SetEndDate(2021, 8, 17)
        self.SetCash(100000) 
        
        # Trading Rule-set Initialisation
        sd_len = 63
        prom_devs = 1.5
        distance = 21
        width = 3
        min_shortfall_devs = 1.5
        
        resolution = Resolution.Daily
        
        self.inst = self.AddForex('EURUSD', market=Market.Oanda, resolution=resolution, fillDataForward =False)
        
        # Get history to populate the price DataFrame.
        inst_data_df = self.History(self.inst.Symbol, 600).loc[self.inst.Symbol, ['high', 'low', 'close']]
        
        self.regime_obj = FloorCeiling(inst_data_df, sd_len, (prom_devs, distance, width), min_shortfall_devs)
        
        self.Debug("Initialize(): " + str(self.regime_obj.fc_df.iloc[-2])
                    + '\n' + str(self.regime_obj.fc_df.iloc[-1]))
        
        # Set up a chart for the regime data.
        regime_chart = Chart('Regime Plot')
        # self.chart_setup(regime_chart)
        regime_chart.AddSeries(Series('Close', SeriesType.Line, 0))
        regime_chart.AddSeries(Series('H-High', SeriesType.Line, 0))
        regime_chart.AddSeries(Series('H-Low', SeriesType.Line, 0))
        self.AddChart(regime_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
        '''
        
        hlc = [data[self.inst.Symbol].High, data[self.inst.Symbol].Low, data[self.inst.Symbol].Close]
        new_row = pd.Series(hlc, index=["high", "low", "close"],
                            name=str(data[self.inst.Symbol].EndTime), copy=True).copy()

        self.Debug("OnData(): " + str(self.regime_obj.fc_df.iloc[-2])
                    + '\n' + str(self.regime_obj.fc_df.iloc[-1]))
        
        self.regime_obj.update_regime(new_row, rolling=True)
        
        # self.Debug(str(self.Time) + ": THLC = " + str(self.inst_data_df.index[-1])
        #                                 + ", " + str(latest_high)
        #                                 + ", " + str(self.inst_data_df.iloc[-1]["low"]))
        
        self.Plot('Regime Plot', 'Close', data[self.inst.Symbol].Close)
        high = self.regime_obj.fc_df.iloc[-1]["high"]
        low = self.regime_obj.fc_df.iloc[-1]["low"]
        self.Plot("Regime Plot", "H-High", float(high))
        self.Plot("Regime Plot", "H-Low", float(low))
        
        pass
        
    
    def chart_setup(self, chart):
        '''
        Set up the chart for plotting swings, floor and ceiling.
        '''
        chart.AddSeries(Series('Close', SeriesType.Line, 0))
        chart.AddSeries(Series('H-High', SeriesType.Line, 0))
        chart.AddSeries(Series('H-Low', SeriesType.Line, 0))
        chart.AddSeries(Series('H-Close', SeriesType.Line, 0))
        # chart.AddSeries(Series('Swing High', SeriesType.Scatter, 0))
        # chart.AddSeries(Series('Swing Low', SeriesType.Scatter, 0))
        # chart.AddSeries(Series('Floor/Ceiling', SeriesType.Line, 0))
        
        return