Created with Highcharts 12.1.2EquityJan 1Jan 15Jan 29Feb 12Feb 26Mar 11Mar 25Apr 8Apr 22May 6May 20Jun 31,750k2,000k2,250k-20-10000.51-1010100M200M010M20M101520
Overall Statistics
Total Orders
59
Average Win
0.44%
Average Loss
-0.88%
Compounding Annual Return
-25.690%
Drawdown
13.100%
Expectancy
-0.413
Start Equity
2000000
End Equity
1766483.11
Net Profit
-11.676%
Sharpe Ratio
-2.167
Sortino Ratio
-1.709
Probabilistic Sharpe Ratio
0.265%
Loss Rate
61%
Win Rate
39%
Profit-Loss Ratio
0.49
Alpha
-0.212
Beta
-0.129
Annual Standard Deviation
0.109
Annual Variance
0.012
Information Ratio
-2.798
Tracking Error
0.15
Treynor Ratio
1.829
Total Fees
$1178.45
Estimated Strategy Capacity
$45000000.00
Lowest Capacity Asset
ROKU WO9FGTL2I89X
Portfolio Turnover
9.45%
# 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< ind1 or \
                self.Portfolio[self.ticker1].IsLong and self.sym1.Price> ind1:

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