Overall Statistics |
Total Trades 404 Average Win 0.90% Average Loss -0.56% Compounding Annual Return 3.598% Drawdown 15.900% Expectancy 0.170 Net Profit 19.343% Sharpe Ratio 0.458 Probabilistic Sharpe Ratio 9.013% Loss Rate 55% Win Rate 45% Profit-Loss Ratio 1.60 Alpha 0.033 Beta -0.01 Annual Standard Deviation 0.07 Annual Variance 0.005 Information Ratio -0.317 Tracking Error 0.139 Treynor Ratio -3.221 Total Fees $1736.66 |
from datetime import timedelta class MOMAlphaModel(AlphaModel): def __init__(self): self.mom = [] def OnSecuritiesChanged(self, algorithm, changes): for security in changes.AddedSecurities: symbol = security.Symbol self.mom.append({"symbol":symbol, "indicator":algorithm.MOM(symbol, 14, Resolution.Daily)}) def Update(self, algorithm, data): ordered = sorted(self.mom, key=lambda kv: kv["indicator"].Current.Value, reverse=True) return Insight.Group([Insight.Price(ordered[0]['symbol'], timedelta(22), InsightDirection.Up), Insight.Price(ordered[1]['symbol'], timedelta(22), InsightDirection.Flat) ]) class FrameworkAlgorithm(QCAlgorithm): def Initialize(self): self.SetStartDate(2014, 1, 1) self.SetEndDate(2019, 1, 1) self.SetCash(100000) symbols = [Symbol.Create("SPY", SecurityType.Equity, Market.USA), Symbol.Create("BND", SecurityType.Equity, Market.USA)] self.UniverseSettings.Resolution = Resolution.Daily self.SetUniverseSelection(ManualUniverseSelectionModel(symbols)) self.SetAlpha(MOMAlphaModel()) self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel(rebalancingParam = timedelta(22))) self.SetRiskManagement(MaximumDrawdownPercentPerSecurity(0.02)) #1. Set the Execution Model to an Immediate Execution Model self.SetExecution(ImmediateExecutionModel())