Overall Statistics
Total Trades
58
Average Win
0.03%
Average Loss
-0.32%
Compounding Annual Return
3.060%
Drawdown
19.200%
Expectancy
-0.945
Net Profit
3.068%
Sharpe Ratio
0.209
Probabilistic Sharpe Ratio
17.017%
Loss Rate
95%
Win Rate
5%
Profit-Loss Ratio
0.11
Alpha
0.037
Beta
0.032
Annual Standard Deviation
0.201
Annual Variance
0.04
Information Ratio
-0.375
Tracking Error
0.336
Treynor Ratio
1.307
Total Fees
$191.97
Estimated Strategy Capacity
$430000000.00
Lowest Capacity Asset
GOOCV VP83T1ZUHROL
Portfolio Turnover
0.96%
# region imports
from AlgorithmImports import *
# endregion

class GeekySkyBlueGorilla(QCAlgorithm):
    PercentTimes = 500

    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*self.PercentTimes)
            self.MarketOrder(self.amzn, -8*abs_mean_change*self.PercentTimes)
        # 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*self.PercentTimes)
            self.MarketOrder(self.amzn, 8*abs_mean_change*self.PercentTimes)
        
        if self.Portfolio.Invested and self.Portfolio.TotalUnrealizedProfit < -100000:
            self.Liquidate()