Overall Statistics
Total Trades
4
Average Win
0.34%
Average Loss
-11.79%
Compounding Annual Return
-11.464%
Drawdown
19.900%
Expectancy
-0.486
Net Profit
-11.493%
Sharpe Ratio
-0.734
Probabilistic Sharpe Ratio
1.522%
Loss Rate
50%
Win Rate
50%
Profit-Loss Ratio
0.03
Alpha
-0.053
Beta
-0.136
Annual Standard Deviation
0.103
Annual Variance
0.011
Information Ratio
-0.738
Tracking Error
0.33
Treynor Ratio
0.557
Total Fees
$140.00
Estimated Strategy Capacity
$260000000.00
Lowest Capacity Asset
GOOCV VP83T1ZUHROL
Portfolio Turnover
0.72%
# region imports
from AlgorithmImports import *
# endregion

# class Q1(QCAlgorithm):
    
#     # Order ticket for our stop order
#     stopMarketTickets = None
    
#     def Initialize(self):
#         self.SetStartDate(2020, 1, 1)
#         self.SetEndDate(2021, 1, 1)
#         self.SetCash(1000000)

#         self.pairs =['GOOG','AMZN']
#         self.symbols =[]
        
#         for ticker in self.pairs:
            
#             self.AddEquity(ticker, Resolution.Daily)
#             self.symbols.append(self.Symbol(ticker))

#     def OnData(self, data: Slice):

#         # Check if we hit our stop orders
#         if self.stopMarketTickets is not None:
#             return

#         if not self.Portfolio.Invested:
#             self.MarketOrder(self.pairs[0], 6000)
#             self.MarketOrder(self.pairs[1], -8000)
#             self.Debug(self.Securities[self.symbols[0]].Price)
#             self.Debug(self.Securities[self.symbols[1]].Price)
#         else:
#             if 1000000 - self.Portfolio.TotalPortfolioValue >= 100000:
#                 self.stopMarketTickets = self.Liquidate()
#                 # Printing the security fill prices.
#                 self.Debug(self.Securities[self.symbols[0]].Price)
#                 self.Debug(self.Securities[self.symbols[1]].Price)


class Q2(QCAlgorithm):
    
    def Initialize(self):
        self.SetStartDate(2020, 1, 1)
        self.SetEndDate(2021, 1, 1)
        self.SetCash(1000000)

        self.pairs =['GOOG','AMZN']
        self.symbols =[]
        
        for ticker in self.pairs:
            self.AddEquity(ticker, Resolution.Daily)
            self.symbols.append(self.Symbol(ticker))
        
        # Keep track of backtesting days/time steps
        self.count = 0
        # To store first day prices
        self.px0 = []

    def OnData(self, data: Slice):

        # Place Limit orders only on the first day of backtesting
        if self.count == 0:
            for ticker in self.pairs:
                self.px0.append(self.Securities[ticker].Open)
            self.Debug(self.px0)
            self.LimitOrder(self.pairs[0], 6000, 0.95*self.px0[0])
            self.LimitOrder(self.pairs[1], -8000, 1.05*self.px0[1])
        self.count += 1

        if self.Portfolio.Invested:
            if 1000000 - self.Portfolio.TotalPortfolioValue >= 100000:
                # The orders may not be filled on the same day since the prices we want for two stocks may not be available together
                if self.Portfolio[self.pairs[0]].Invested:
                    self.Liquidate(self.pairs[0])
                if self.Portfolio[self.pairs[1]].Invested:
                    self.Liquidate(self.pairs[1])

# class Q3(QCAlgorithm):
    
#     def Initialize(self):
#         self.SetStartDate(2020, 1, 1)
#         self.SetEndDate(2021, 1, 1)
#         self.SetCash(1000000)

#         self.pairs =['GOOG','AMZN']
#         self.symbols =[]
        
#         for ticker in self.pairs:
            
#             self.AddEquity(ticker, Resolution.Daily)
#             self.symbols.append(self.Symbol(ticker))

#     def OnData(self, data: Slice):
#         # determine the maximum amount of shares for each stock with the total equity
#         if not self.Portfolio.Invested:
#             # searched from 1000 to 700, 703 is the maximal for avoiding a margin call through the whole period
#             self.MarketOrder(self.pairs[0], 6*704)
#             self.MarketOrder(self.pairs[1], -8*704)

#     def OnMarginCall(self, requests: List[SubmitOrderRequest]) -> List[SubmitOrderRequest]:
#         self.Debug("Margin CALL!!!!!!!!!!!!!!")
#         return requests
    
#     def OnMarginCallWarning(self):
#         self.Error("OnMarginCallWarning")
#region imports
from AlgorithmImports import *
#endregion


class Q1(QCAlgorithm):
    
    # Order ticket for our stop order
    stopMarketTickets = None
    
    def Initialize(self):
        self.SetStartDate(2020, 1, 1)
        self.SetEndDate(2021, 1, 1)
        self.SetCash(1000000)

        self.pairs =['GOOG','AMZN']
        self.symbols =[]
        
        for ticker in self.pairs:
            
            self.AddEquity(ticker, Resolution.Daily)
            self.symbols.append(self.Symbol(ticker))

    def OnData(self, data: Slice):

        # Check if we hit our stop orders
        if self.stopMarketTickets is not None:
            return

        if not self.Portfolio.Invested:
            self.MarketOrder(self.pairs[0], 6000)
            self.MarketOrder(self.pairs[1], -8000)
            self.Debug(self.Securities[self.symbols[0]].Price)
            self.Debug(self.Securities[self.symbols[1]].Price)
        else:
            if 1000000 - self.Portfolio.TotalPortfolioValue >= 100000:
                self.stopMarketTickets = self.Liquidate()
                # Printing the security fill prices.
                self.Debug(self.Securities[self.symbols[0]].Price)
                self.Debug(self.Securities[self.symbols[1]].Price)
#region imports
from AlgorithmImports import *
#endregion


class Q2(QCAlgorithm):
    
    def Initialize(self):
        self.SetStartDate(2020, 1, 1)
        self.SetEndDate(2021, 1, 1)
        self.SetCash(1000000)

        self.pairs =['GOOG','AMZN']
        self.symbols =[]
        
        for ticker in self.pairs:
            self.AddEquity(ticker, Resolution.Daily)
            self.symbols.append(self.Symbol(ticker))
        
        # Keep track of backtesting days/time steps
        self.count = 0
        # To store first day prices
        self.px0 = []

    def OnData(self, data: Slice):

        # Place Limit orders only on the first day of backtesting
        if self.count == 0:
            for ticker in self.pairs:
                self.px0.append(self.Securities[ticker].Open)
            self.Debug(self.px0)
            self.LimitOrder(self.pairs[0], 6000, 0.95*self.px0[0])
            self.LimitOrder(self.pairs[1], -8000, 1.05*self.px0[1])
        self.count += 1

        if self.Portfolio.Invested:
            if 1000000 - self.Portfolio.TotalPortfolioValue >= 100000:
                # The orders may not be filled on the same day since the prices we want for two stocks may not be available together
                if self.Portfolio[self.pairs[0]].Invested:
                    self.Liquidate(self.pairs[0])
                if self.Portfolio[self.pairs[1]].Invested:
                    self.Liquidate(self.pairs[1])
#region imports
from AlgorithmImports import *
#endregion


class Q3(QCAlgorithm):
    
    def Initialize(self):
        self.SetStartDate(2020, 1, 1)
        self.SetEndDate(2021, 1, 1)
        self.SetCash(1000000)

        self.pairs =['GOOG','AMZN']
        self.symbols =[]
        
        for ticker in self.pairs:
            
            self.AddEquity(ticker, Resolution.Daily)
            self.symbols.append(self.Symbol(ticker))

    def OnData(self, data: Slice):
        # determine the maximum amount of shares for each stock with the total equity
        if not self.Portfolio.Invested:
            # searched from 1000 to 700, 703 is the maximal for avoiding a margin call through the whole period
            self.MarketOrder(self.pairs[0], 6*704)
            self.MarketOrder(self.pairs[1], -8*704)

    def OnMarginCall(self, requests: List[SubmitOrderRequest]) -> List[SubmitOrderRequest]:
        self.Debug("Margin CALL!!!!!!!!!!!!!!")
        return requests
    
    def OnMarginCallWarning(self):
        self.Error("OnMarginCallWarning")