Overall Statistics
Total Trades
202
Average Win
5.91%
Average Loss
-2.06%
Compounding Annual Return
22.850%
Drawdown
17.500%
Expectancy
0.763
Net Profit
308.013%
Sharpe Ratio
0.944
Probabilistic Sharpe Ratio
48.023%
Loss Rate
54%
Win Rate
46%
Profit-Loss Ratio
2.87
Alpha
0.117
Beta
0.427
Annual Standard Deviation
0.157
Annual Variance
0.025
Information Ratio
0.447
Tracking Error
0.168
Treynor Ratio
0.347
Total Fees
$226.33
Estimated Strategy Capacity
$200000000.00
Lowest Capacity Asset
AAPL R735QTJ8XC9X
Portfolio Turnover
8.05%
from AlgorithmImports import *

class CalmBrownTermite(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2017, 1, 2)
        self.SetCash(10000) 
        self.spy = self.AddEquity("AAPL", Resolution.Daily).Symbol
        self.Fast = self.SMA(self.spy,9,Resolution.Daily)
        self.Slow = self.SMA(self.spy,200,Resolution.Daily)
        
        
        self.previous = self.Time.min
        self.Tolerance = 0.00015
    def OnData(self, data):
        
        if not self.Slow.IsReady :return
        if  self.previous is  None or self.previous.day==self.Time.day:return
        holdings = self.Portfolio[self.spy].Quantity
        if holdings<=0:
            if self.Fast[0]>=self.Fast[1] : # .Current.Value self.Slow.Current.Value*(1+self.Tolerance):
                self.SetHoldings(self.spy,1)
                self.Debug("BUY  >> " + str(self.Securities[self.spy].Price))
        elif holdings>=0:
            
            if self.Fast[0]<self.Fast[1]:
                self.SetHoldings(self.spy,0)
        if self.Portfolio[self.spy].UnrealizedProfit<= -420:
                self.Debug("Sell at "+str(self.Securities[self.spy].Price))
                self.Liquidate()
        self.previous = self.Time