Overall Statistics
Total Trades
1
Average Win
0%
Average Loss
0%
Compounding Annual Return
17.382%
Drawdown
7.000%
Expectancy
0
Net Profit
2.669%
Sharpe Ratio
0.835
Probabilistic Sharpe Ratio
46.084%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0.176
Beta
-0.012
Annual Standard Deviation
0.207
Annual Variance
0.043
Information Ratio
-0.32
Tracking Error
0.255
Treynor Ratio
-14.77
Total Fees
$1.59
Estimated Strategy Capacity
$410000000.00
# MOMP test.
# ---------------------------------
STOCK = 'QQQ'; RETURN_PERIOD = 10;
# ---------------------------------

class EnergeticOrangeBat(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2021, 1, 1) 
        self.SetEndDate(2021, 3, 1)
        self.SetCash(100000) 
        
        self.stock = self.AddEquity(STOCK, Resolution.Daily).Symbol
        
        # Warm up with history, not automatic
        self.mom0 = self.MOMP(self.stock, RETURN_PERIOD, Resolution.Daily)
        history = self.History(self.stock, RETURN_PERIOD, Resolution.Daily)
        for time, row in history.loc[self.stock].iterrows():
            self.mom0.Update(time, row.close)
        
        # Automatic Wwarm up with history
        self.EnableAutomaticIndicatorWarmUp = True
        self.mom = self.MOMP(self.stock, RETURN_PERIOD, Resolution.Daily)
        
        self.Log(f"Starting values ref: {self.mom0.Current.Value} {self.mom0.Samples}")
        self.Log(f"Starting values    : {self.mom.Current.Value} {self.mom.Samples}")
        self.mom_2, df = self.returns(self.stock, RETURN_PERIOD)
        self.mom_3, df2 = self.returns(self.stock, RETURN_PERIOD+1)
        
    def returns(self, symbol, period):
        history = self.History(symbol, period, Resolution.Daily)
        volume = history.volume
        if len(volume) != period:
            self.Log(f'Len = {len(volume)}')
        prices = history.close
        return float(100*(prices.iloc[-1]/prices.iloc[0] - 1)), history

    def OnData(self, data):
        if self.stock not in data.Bars:
            return
    
        if not self.Portfolio.Invested:
            self.SetHoldings(self.stock, 1)

        self.mom_2, df = self.returns(self.stock, RETURN_PERIOD)
        self.mom_3, df2 = self.returns(self.stock, RETURN_PERIOD+1)

        self.Plot("Momentum Percent", "RET", self.mom_2)
        self.Plot("Momentum Percent", "RET+1", self.mom_3)
        self.Plot("Momentum Percent", "MOMP", self.mom.Current.Value)
        self.Plot("Momentum Percent", "MOMP Ref", self.mom0.Current.Value)
        self.Log(f"Ending values: {self.mom.Current.Value} {self.mom0.Current.Value} {self.mom_2} {self.mom_3}")