Overall Statistics
Total Trades
47
Average Win
44.79%
Average Loss
-3.14%
Compounding Annual Return
29.130%
Drawdown
39.300%
Expectancy
3.855
Net Profit
475.643%
Sharpe Ratio
0.988
Probabilistic Sharpe Ratio
36.624%
Loss Rate
68%
Win Rate
32%
Profit-Loss Ratio
14.26
Alpha
0.145
Beta
0.717
Annual Standard Deviation
0.228
Annual Variance
0.052
Information Ratio
0.549
Tracking Error
0.206
Treynor Ratio
0.313
Total Fees
$133.24
Estimated Strategy Capacity
$240000000.00
Lowest Capacity Asset
TLT SGNKIKYGE9NP

class MovingAverageCrossAlgorithm(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2015, 1, 1)  
        self.SetCash(100000)
        self.tickers = ["TSLA", "AAPL", "TLT"]
        self.symbols =  [self.AddEquity(ticker, Resolution.Daily).Symbol for ticker in self.tickers]
        self.fast = {}
        self.slow = {}
        for symbol in self.symbols:
            self.fast[symbol] = self.SMA(symbol, 20, Resolution.Daily)
            self.slow[symbol] = self.SMA(symbol, 200, Resolution.Daily)
        self.SetWarmUp(200, Resolution.Daily)
        
        
    def OnData(self, data):
        if self.IsWarmingUp: return 
    
        for symbol in self.symbols: 
            holdings = self.Portfolio[symbol].Quantity
            self.Plot("holdings", symbol, holdings) 

        for symbol in self.symbols:
            if not self.fast[symbol].IsReady: continue
            if not self.slow[symbol].IsReady: continue
            fast = self.fast[symbol].Current.Value
            slow = self.slow[symbol].Current.Value
            self.Plot(symbol, "fast", fast) 
            self.Plot(symbol, "slow", slow) 
            if fast > slow and self.Portfolio[symbol].Quantity <= 0:
                self.SetHoldings(symbol, 1/len(self.symbols))
            elif fast < slow and self.Portfolio[symbol].Quantity > 0: 
                self.Liquidate(symbol)