Created with Highcharts 12.1.2Equity200020022004200620082010201220142016201820202022202420260500k1,000k-40-20000.10.2012050010000500M1,000M025M50M49.849.8549.949.95
Overall Statistics
Total Orders
176
Average Win
14.60%
Average Loss
-1.29%
Compounding Annual Return
6.629%
Drawdown
25.500%
Expectancy
1.802
Start Equity
100000
End Equity
538304.69
Net Profit
438.305%
Sharpe Ratio
0.285
Sortino Ratio
0.266
Probabilistic Sharpe Ratio
0.129%
Loss Rate
77%
Win Rate
23%
Profit-Loss Ratio
11.33
Alpha
0.011
Beta
0.378
Annual Standard Deviation
0.097
Annual Variance
0.009
Information Ratio
-0.135
Tracking Error
0.124
Treynor Ratio
0.073
Total Fees
$1091.47
Estimated Strategy Capacity
$510000000.00
Lowest Capacity Asset
SPY R735QTJ8XC9X
Portfolio Turnover
1.83%
# region imports
from AlgorithmImports import *
# endregion

class CrawlingMagentaTapir(QCAlgorithm):

    def initialize(self):
        self.set_start_date(1999, 1, 1)
        self._spy = self.add_equity("SPY")
        self._spy.sma = SimpleMovingAverage(200)
        self.schedule.on(self.date_rules.every_day(self._spy.symbol), self.time_rules.before_market_close(self._spy.symbol, 1), self._rebalance)
        self.set_warm_up(timedelta(365))
        self._scaler = None

    def _rebalance(self):
        self._spy.sma.update(self.time, self._spy.price)
        if self.is_warming_up:
            return
        if not self._scaler:
            self._scaler = self.portfolio.cash_book['USD'].amount / self._spy.price
        sma = self._spy.sma.current.value
        self.plot('Strategy Equity', 'Benchmark', self._spy.price * self._scaler)
        self.plot('Signal', 'SMA', sma)
        self.plot('Signal', 'Price', self._spy.price)
        if self._spy.price > sma and not self._spy.invested:
            self.set_holdings(self._spy.symbol, 1)
        elif self._spy.price < sma and self._spy.invested:
            self.liquidate()