Overall Statistics
Total Trades
1521
Average Win
1.51%
Average Loss
-0.57%
Compounding Annual Return
71.652%
Drawdown
15.200%
Expectancy
0.331
Net Profit
1396.082%
Sharpe Ratio
2.869
Probabilistic Sharpe Ratio
99.440%
Loss Rate
63%
Win Rate
37%
Profit-Loss Ratio
2.64
Alpha
0.778
Beta
0.03
Annual Standard Deviation
0.273
Annual Variance
0.075
Information Ratio
1.795
Tracking Error
0.328
Treynor Ratio
26.541
Total Fees
$3353.89
Estimated Strategy Capacity
$35000000.00
Lowest Capacity Asset
AMZN R735QTJ8XC9X
import numpy as np

class UglyBrownDolphin(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2016, 6, 10)
        self.SetCash(100000) 
        self.symbol = self.AddEquity("AMZN", Resolution.Hour).Symbol
        
        self.indicator = Trend0('Trend0', period=10, exponent=1.5)
        self.RegisterIndicator(self.symbol, self.indicator, Resolution.Hour)



    def OnData(self, data):
        if not (data.ContainsKey(self.symbol) and data[self.symbol] is not None):
            return
            
        if not self.indicator.IsReady:
            return
                
        if self.indicator.Value > 0 and self.Portfolio[self.symbol].Quantity <= 0:
            self.SetHoldings(self.symbol, 0.99)
        elif self.indicator.Value < 0 and self.Portfolio[self.symbol].Quantity >= 0:
            self.SetHoldings(self.symbol, -0.99)
            
        
           
class Trend0(PythonIndicator):
    def __init__(self, name, period, exponent):
        self.Name = name
        self.period = period
        self.exponent = exponent
        self.Time = datetime.min
        self.Value = 0
        self.prices = np.array([])


    def Update(self, input):
        
        self.prices = np.append(self.prices, input.Close)[-self.period:]
        
        # IsReady?
        if len(self.prices) != self.period:
            self.Value = 0
            return False
        
        self.Value = self.calc_trend()
        return True
    
    def calc_trend(self):
        changes = np.array([])
        for i in range(len(self.prices) - 1):
            _return = (self.prices[i + 1] - self.prices[i]) / self.prices[i]
            changes = np.append(changes, _return)
        return self.power_weighted_moving_average(changes)
    
    def power_weighted_moving_average(self, changes):
        return self.weighted_average(changes, self.exponential_weights(len(changes)))
        
    def exponential_weights(self, length):
        weights = np.array([])
        for i in range(length):
            w = i + 1
            weights = np.append(weights, w**self.exponent)
        return weights
        
    def weighted_average(self, changes, weights):
        products = []
        for i in range(len(changes)):
            products.append(changes[i] * weights[i])
        return sum(products) / sum(weights)