| Overall Statistics |
|
Total Trades 189 Average Win 10.96% Average Loss -1.80% Compounding Annual Return 148.697% Drawdown 32.800% Expectancy 2.016 Net Profit 1574.437% Sharpe Ratio 2.533 Probabilistic Sharpe Ratio 94.416% Loss Rate 57% Win Rate 43% Profit-Loss Ratio 6.09 Alpha 0.978 Beta 0.435 Annual Standard Deviation 0.41 Annual Variance 0.168 Information Ratio 2.161 Tracking Error 0.416 Treynor Ratio 2.389 Total Fees $189.00 Estimated Strategy Capacity $220000000.00 Lowest Capacity Asset TSLA UNU3P8Y3WFAD |
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(1), InsightDirection.Up), Insight.Price(ordered[1]['symbol'], timedelta(1), InsightDirection.Flat) ])
class FrameworkAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2018, 10, 1)
# self.SetEndDate(2020, 12, 1)
self.SetCash(1000)
symbols = [Symbol.Create("TSLA", 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())
self.SetRiskManagement(MaximumDrawdownPercentPerSecurity(0.02))
#1. Set the Execution Model to an Immediate Execution Model
self.SetExecution(ImmediateExecutionModel())