Overall Statistics
Total Trades
15
Average Win
0%
Average Loss
-3.45%
Compounding Annual Return
-72.043%
Drawdown
70.600%
Expectancy
-1
Net Profit
-65.482%
Sharpe Ratio
-0.885
Probabilistic Sharpe Ratio
0.542%
Loss Rate
100%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-0.009
Beta
-2.45
Annual Standard Deviation
0.575
Annual Variance
0.33
Information Ratio
-1.134
Tracking Error
0.628
Treynor Ratio
0.208
Total Fees
$15.00
Estimated Strategy Capacity
$52000000.00
Lowest Capacity Asset
TSLA UNU3P8Y3WFAD
class FatBrownBison(QCAlgorithm):

    def Initialize(self):
        self.cash = 100000
        self.ticker = "TSLA"
        self.tp = 0.02
        self.risk = 0.01
        
        self.SetStartDate(2021, 1, 1)
        self.SetEndDate(2021, 11, 1)
        self.SetCash(self.cash)
        self.AddEquity(self.ticker, Resolution.Minute)

        #indicators and rolling windows
        self.emaFast = self.EMA(self.ticker, 12)
        self.emaFast.Updated += self.FastEmaUpdated
        self.fastWin = RollingWindow[IndicatorDataPoint](5)
        
        self.emaSlow = self.EMA(self.ticker, 26)
        self.emaSlow.Updated += self.SlowEmaUpdated
        self.slowWin = RollingWindow[IndicatorDataPoint](5)
        
        self.SetWarmUp(31)
        
        #self.SetRiskManagement(MaximumDrawdownPercentPerSecurity(0.005))
    
    def OnData(self, data):
        
            if self.IsWarmingUp or not self.emaFast.IsReady or not self.emaSlow.IsReady or not self.fastWin.IsReady or not self.slowWin.IsReady: return

            currSlowEMA = self.slowWin[0]
            prevSlowEMA = self.slowWin[1]
    
            currFastEMA = self.fastWin[0]
            prevFastEMA = self.fastWin[1]
            
            if not self.Portfolio.Invested:
            #short logic w/ stop loss
                if prevFastEMA.Value > prevSlowEMA.Value and currFastEMA.Value < currSlowEMA.Value:
                    self.SetHoldings(self.ticker, -1)
                    self.StopMarketOrder(self.ticker, self.Portfolio[self.ticker].Quantity, self.Portfolio[self.ticker].Price * (1 - self.tp))
        
            #long logic w/ stop loss
                elif prevFastEMA.Value < prevSlowEMA.Value and currFastEMA.Value > currSlowEMA.Value:
                    self.SetHoldings(self.ticker, 1)
                    self.StopMarketOrder(self.ticker, -self.Portfolio[self.ticker].Quantity, self.Portfolio[self.ticker].Price * (1 + self.tp))
        
            #short take profit logic
            elif self.Portfolio[self.ticker].IsShort:
                if self.Securities[self.ticker].Price <= (self.Portfolio[self.ticker].Price * (1 - self.tp)):
                    self.Transactions.CancelOpenOrders()
                    self.Liquidate()
            
            #long take profit logic
            elif self.Portfolio[self.ticker].IsLong:
                if self.Securities[self.ticker].Price >= (self.Portfolio[self.ticker].Price * (1 + self.tp)):
                    self.Transactions.CancelOpenOrders()
                    self.Liquidate()
        
    def FastEmaUpdated(self, sender, updated):
        self.fastWin.Add(updated)
        
    def SlowEmaUpdated(self, sender, updated):
        self.slowWin.Add(updated)