| Overall Statistics |
|
Total Orders 103 Average Win 14.03% Average Loss -1.98% Compounding Annual Return 11.251% Drawdown 21.300% Expectancy 1.374 Start Equity 100000 End Equity 340300.26 Net Profit 240.300% Sharpe Ratio 0.501 Sortino Ratio 0.52 Probabilistic Sharpe Ratio 11.403% Loss Rate 71% Win Rate 29% Profit-Loss Ratio 7.07 Alpha 0.01 Beta 0.607 Annual Standard Deviation 0.114 Annual Variance 0.013 Information Ratio -0.221 Tracking Error 0.092 Treynor Ratio 0.094 Total Fees $279.38 Estimated Strategy Capacity $54000000.00 Lowest Capacity Asset SPY R735QTJ8XC9X Portfolio Turnover 2.45% Drawdown Recovery 766 |
from AlgorithmImports import *
class DualMovingAverageAlgorithm(QCAlgorithm):
def Initialize(self):
self.universe_settings.leverage = 1.0
self.set_start_date(2015, 1, 1)
self.spy = self.add_equity("SPY", Resolution.MINUTE).symbol
self.slow_ma = self.sma(self.spy, 200, Resolution.DAILY)
self.fast_ma = self.hma(self.spy, 50, Resolution.DAILY)
self.schedule.on(
self.date_rules.every_day(self.spy),
self.time_rules.after_market_open(self.spy, 30),
self._evaluate_market_regime,
)
self.set_warm_up(200, Resolution.DAILY)
self.set_benchmark(self.spy)
def _evaluate_market_regime(self):
if self.is_warming_up or not (self.fast_ma.is_ready and self.slow_ma.is_ready):
return
price = self.securities[self.spy].price
is_bullish = price > self.slow_ma.current.value or price > self.fast_ma.current.value
# Stay fully invested if the macro trend is intact OR if we are above the fast MA.
if is_bullish:
if not self.portfolio[self.spy].invested:
self.set_holdings(self.spy, 1.0)
elif self.portfolio[self.spy].invested:
self.liquidate(self.spy)