Overall Statistics
Total Trades
58
Average Win
0.01%
Average Loss
-0.48%
Compounding Annual Return
-10.972%
Drawdown
19.400%
Expectancy
-0.940
Net Profit
-11.000%
Sharpe Ratio
-0.633
Probabilistic Sharpe Ratio
1.736%
Loss Rate
94%
Win Rate
6%
Profit-Loss Ratio
0.01
Alpha
-0.063
Beta
-0.051
Annual Standard Deviation
0.113
Annual Variance
0.013
Information Ratio
-0.764
Tracking Error
0.313
Treynor Ratio
1.386
Total Fees
$183.75
Estimated Strategy Capacity
$1400000000.00
Lowest Capacity Asset
GOOCV VP83T1ZUHROL
Portfolio Turnover
0.78%
# region imports
from AlgorithmImports import *
# endregion

class GeekySkyBlueGorilla(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2020, 1, 1)  # Set Start Date
        self.SetEndDate(2021, 1, 1)  # Set End Date
        self.SetCash(1000000)  # Set Strategy Cash
        self.goog = self.AddEquity("GOOG", Resolution.Daily).Symbol
        self.amzn = self.AddEquity("AMZN", Resolution.Daily).Symbol

        self.FirstDay = None

    def OnData(self, data: Slice):
        if self.FirstDay is None:
            self.FirstDay = {self.goog:data[self.goog].Price,
                            self.amzn:data[self.amzn].Price}
            self.MarketOrder(self.goog, 6000)
            self.MarketOrder(self.amzn, -8000)

        pct_change = lambda old,new: (new-old)/old
        self.Change = {self.goog: pct_change(self.FirstDay[self.goog],data[self.goog].Price),
                        self.amzn: pct_change(self.FirstDay[self.amzn],data[self.amzn].Price),}

        self.Plot('Changes',self.goog.Value, self.Change[self.goog])
        self.Plot('Changes',self.amzn.Value, self.Change[self.amzn])

        # If the prices takes momentum increase the current position
        if self.Change[self.goog] > 0.02 and self.Change[self.amzn] < -0.02:
            abs_mean_change = np.mean(np.abs([self.Change[self.goog],self.Change[self.amzn]]))
            self.MarketOrder(self.goog, 6*abs_mean_change*100)
            self.MarketOrder(self.amzn, -8*abs_mean_change*100)
        # Otherwise, if the prices takes momentum in the oposite direction, reduce the current position
        elif self.Change[self.goog] < -0.02 and self.Change[self.amzn] > 0.02:
            abs_mean_change = np.mean(np.abs([self.Change[self.goog],self.Change[self.amzn]]))
            self.MarketOrder(self.goog, -6*abs_mean_change*100)
            self.MarketOrder(self.amzn, 8*abs_mean_change*100)
        
        if self.Portfolio.Invested and self.Portfolio.TotalUnrealizedProfit < -100000:
            self.Liquidate()