Overall Statistics |
Total Trades 130 Average Win 0.03% Average Loss -0.72% Compounding Annual Return -38.596% Drawdown 6.900% Expectancy -0.211 Net Profit -2.853% Sharpe Ratio 3.382 Probabilistic Sharpe Ratio 61.375% Loss Rate 25% Win Rate 75% Profit-Loss Ratio 0.05 Alpha 1.059 Beta 0.826 Annual Standard Deviation 0.328 Annual Variance 0.108 Information Ratio 3.282 Tracking Error 0.319 Treynor Ratio 1.344 Total Fees $131.64 |
from datetime import timedelta class helloWorldModel(AlphaModel): #yahoo finance (daily data) # algoseek def __init__(self): self.mom = [] def OnSecuritiesChanged(self, algorithm, changes): for security in changes.AddedSecurities: symbol = security.Symbol kama_val=algorithm.KAMA(symbol, 10,2,30, Resolution.Hour) mom_val=algorithm.MOM(symbol, 14, Resolution.Hour) self.mom.append({"symbol":symbol, "mom":mom_val, "kama":kama_val}) def Update(self, algorithm, data): grp=[] x = 0 while x < len(self.mom): symbol=str(self.mom[x]['symbol']) mom=self.mom[x]['mom'].Current.Value kama=self.mom[x]['kama'].Current.Value price= algorithm.Securities[symbol].Price # Latest known price; we are at 12:00 and the last trade at 10.57 if symbol in data.Bars.Keys: bar = data.Bars[symbol] vinsightDirection = InsightDirection.Flat signal="hold" if mom >0 and price>kama: vinsightDirection = InsightDirection.Up signal="buy" if mom < 0 or price<kama: vinsightDirection = InsightDirection.Down signal="sell" algorithm.Log(f"{symbol} MOM {mom}") #timedelta(1) insight stays for 1 day; grp.append(Insight(symbol, timedelta(hours=1), InsightType.Price, vinsightDirection, 1,None, "helloWorldModel",None)) x += 1 return grp class FrameworkAlgorithm(QCAlgorithm): def Initialize(self): self.SetStartDate(2020, 12, 1) self.SetCash(100000) tickers=["MSFT","MRNA","MELI"] symbols = [Symbol.Create(x, SecurityType.Equity, Market.USA) for x in tickers] # FTSE # DAX frequency = Resolution.Hour #10-11, etc Daily data is midnight to mifnight, 12AM EST # Set Benchmark self.SetBenchmark("SPY") self.UniverseSettings.Resolution = frequency self.SetWarmUp(timedelta(28)) # Warm up 28 days of data. self.SetUniverseSelection(ManualUniverseSelectionModel(symbols)) self.SetAlpha(helloWorldModel()) #self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel()) self.SetPortfolioConstruction(MeanVarianceOptimizationPortfolioConstructionModel(Resolution.Hour,PortfolioBias.LongShort,1,63,Resolution.Hour,0.02,MaximumSharpeRatioPortfolioOptimizer(0,1,0))) self.SetRiskManagement(MaximumDrawdownPercentPerSecurity(0.02)) # drop in profit from the max self.SetExecution(ImmediateExecutionModel())