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.894
Tracking Error
0.17
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
# FIR_Filter custom indicator for prices SMA
# Inspired by Warren Harding and Derek Melchin for their Trend0 algorithms
# https://www.quantconnect.com/forum/discussion/11613/algo-FIR_Filter/p1
# ----------------------------------------
STOCK = 'AMZN'; PERIOD = 63; POWER = 0; 
# ----------------------------------------
import numpy as np

class UglyBrownDolphin(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2016, 6, 10)
        self.SetCash(100000) 
        self.stock = self.AddEquity(STOCK, Resolution.Daily).Symbol
        self.indicator = FIR_Filter('FIR_Filter', period = PERIOD, power = POWER)
        self.RegisterIndicator(self.stock, self.indicator, Resolution.Daily)
        self.sma = self.SMA(self.stock, PERIOD, Resolution.Daily)
        self.SetWarmUp(PERIOD)


    def OnData(self, data):
        if self.IsWarmingUp or not self.indicator.IsReady: return

        price = self.Securities[self.stock].Price
        
        mean = self.History([self.stock], PERIOD, Resolution.Daily)['close'].unstack(level=0).mean()

        self.Plot("Indicator", "mean", mean)
        self.Plot("Indicator", "ma", self.indicator.Value)
        self.Plot("Indicator", "sma", self.sma.Current.Value)
        
           
class FIR_Filter(PythonIndicator):
    def __init__(self, name, period, power):
        self.Name = name
        self.period = period
        self.power = power
        self.Time = datetime.min
        self.Value = 0
        self.prices = np.array([])
        self.weights = np.array([(i+1)**power for i in range(self.period)])
        

    def Update(self, input):
        self.prices = np.append(self.prices, input.Close)[-self.period:]

        if len(self.prices) != self.period:
            self.Value = 0
            return False
        
        self.Value = sum(self.prices * self.weights) / sum(self.weights)
        return True