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
-0.87
Tracking Error
0.258
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
# Laguerre Filter Indicator

# --------------------------------------------------------
STOCK = 'QQQ';PERIOD = 20; GAMMA_F = 0.20; GAMMA_S = 0.80; 
# --------------------------------------------------------

class CustomIndicatorAlgorithm(QCAlgorithm):
    
    def Initialize(self):
        self.SetStartDate(2020, 1, 1)   
        self.SetEndDate(2021, 6, 30)     

        res = Resolution.Minute
        self.stock = self.AddEquity(STOCK, Resolution.Daily).Symbol
        self.LaguerreF = LAGUERRE('LAGUERRE', GAMMA_F)
        self.RegisterIndicator(self.stock, self.LaguerreF, Resolution.Daily)
        self.LaguerreS = LAGUERRE('LAGUERRE', GAMMA_S)
        self.RegisterIndicator(self.stock, self.LaguerreS, Resolution.Daily)
        self.SetWarmUp((PERIOD), Resolution.Daily)
        self.Schedule.On(self.DateRules.EveryDay(self.stock), self.TimeRules.AfterMarketOpen(self.stock, 61), 
            self.Indicator)
            

    def Indicator(self):
        if self.IsWarmingUp or not self.LaguerreS.IsReady: return
        price = self.Securities[self.stock].Price

        self.Plot("Indicator", "Price", price)
        self.Plot("Indicator", "LaguerreF", float(self.LaguerreF.Value))
        self.Plot("Indicator", "LaguerreS", float(self.LaguerreS.Value))
            
# Laguerre Filter as defined by John F. Ehlers in `Cybernetic Analysis for 
# Stock and Futures`, 2004, published by Wiley. `ISBN: 978-0-471-46307-8
# https://www.mt5users.com/wp-content/uploads/2020/01/timewarp.pdf
        
class LAGUERRE(PythonIndicator):  # Laguerre Filter
    def __init__(self, name, gamma ):
        self.Name = name
        self.gamma = gamma
        self.prices = np.array([])
        self.Value = 0
        self.L0 = 0.0; self.L1 = 0.0; self.L2 = 0.0; self.L3 = 0.0
        
    
    def Update(self, input):
        mp = (input.High + input.Low)/2
        self.prices = np.append(self.prices, mp)[-4:]
        if len(self.prices) <= 1:
            self.L0 = mp; self.L1 = mp; self.L2 = mp; self.L3 = mp;
        
        if len(self.prices) != 4 : return
    
        L01 = self.L0; L11 = self.L1; L21 = self.L2; L31 = self.L3;
        g = self.gamma  
        
        self.L0 = (1 - g)*mp + g*L01
        self.L1 = L01 - g*self.L0 + g*L11
        self.L2 = L11 - g*self.L1 + g*L21
        self.L3 = L21 - g*self.L2 + g*L31
        
        if len(self.prices) != 4 :
            self.Value = mp
            return False
        
        self.Value = (self.L0 + (2*self.L1) + 2*(self.L2) + self.L3) / 6
        return True