Created with Highcharts 12.1.2EquityJan 1Jan 15Jan 29Feb 12Feb 26Mar 11Mar 25Apr 8Apr 22May 6May 20Jun 31,500k1,750k2,000k2,250k-20-10000.51-1010100M200M010M20M101520
Overall Statistics
Total Orders
35
Average Win
0.45%
Average Loss
-0.98%
Compounding Annual Return
-32.501%
Drawdown
16.400%
Expectancy
-0.727
Start Equity
2000000
End Equity
1696881.94
Net Profit
-15.156%
Sharpe Ratio
-2.29
Sortino Ratio
-2.023
Probabilistic Sharpe Ratio
0.213%
Loss Rate
81%
Win Rate
19%
Profit-Loss Ratio
0.46
Alpha
-0.2
Beta
-0.475
Annual Standard Deviation
0.126
Annual Variance
0.016
Information Ratio
-2.622
Tracking Error
0.18
Treynor Ratio
0.605
Total Fees
$1011.09
Estimated Strategy Capacity
$44000000.00
Lowest Capacity Asset
ROKU WO9FGTL2I89X
Portfolio Turnover
5.50%
# region imports
from AlgorithmImports import *
# endregion

class QC3(QCAlgorithm):
    
    def Initialize(self):
        
        self.SetStartDate(2023, 12, 20) 
        self.SetEndDate(2024, 5, 20) 
        self.SetCash(2000_000)  
        self.SetWarmUp(30)

        self.ticker ='ROKU'
        self.sym = self.AddEquity(self.ticker, Resolution.Daily)

        self.ticker1 = 'MSFT'
        self.sym1 = self.AddEquity(self.ticker1, Resolution.Daily)

        # define a 10-period daily RSI indicator with shortcut helper method
        self.sma = self.SMA(self.ticker, 20, Resolution.Daily)
        self.sma1 = self.SMA(self.ticker1, 20, Resolution.Daily)

        self.port = True # True indicates that have one or two stocks

        
        if self.port:

            self.wt = 0.25 # if we have two stocks, each wt will be 25%

        else:
            
             self.wt = 0.5 # single stock wt 50%

    def OnData(self, data):
        
        if self.IsWarmingUp:
            return
            
        ind = self.sma.Current.Value
        ind1= self.sma1.Current.Value

        self.Debug("Price " + str(self.sym.Price) + "indicator " +str(ind))
        self.Debug(" Compare " + str(self.sym.Price>ind))


        #Trend-Following Momentum Strategy for self.ticker
        if not self.Portfolio[self.ticker].Invested:
            
            if self.sym.Price > ind:

                self.SetHoldings(self.sym.Symbol, self.wt)

            elif self.sym.Price <ind:

                self.SetHoldings(self.sym.Symbol, -self.wt)

        elif self.Portfolio[self.ticker].IsLong and self.sym.Price< ind or \
            self.Portfolio[self.ticker].IsShort and self.sym.Price> ind:

            self.SetHoldings(self.sym.Symbol, 0.0)


        #Trend-Reversal Strategy for self.ticker1
        if self.port:

            if not self.Portfolio[self.ticker1].Invested:
            
                if self.sym1.Price > ind1:

                    self.SetHoldings(self.sym1.Symbol, -self.wt)

                elif self.sym1.Price <ind1:

                    self.SetHoldings(self.sym1.Symbol, self.wt)

            elif self.Portfolio[self.ticker1].IsShort and self.sym1.Price< ind or \
                self.Portfolio[self.ticker1].IsLong and self.sym1.Price> ind:

                self.SetHoldings(self.sym1.Symbol, 0.0)