Overall Statistics |
Total Trades 6 Average Win 3.48% Average Loss -0.05% Compounding Annual Return 459.920% Drawdown 1.500% Expectancy 31.191 Net Profit 2.388% Sharpe Ratio -1.865 Probabilistic Sharpe Ratio 33.733% Loss Rate 50% Win Rate 50% Profit-Loss Ratio 63.38 Alpha 0.135 Beta 0.689 Annual Standard Deviation 0.082 Annual Variance 0.007 Information Ratio 5.719 Tracking Error 0.046 Treynor Ratio -0.223 Total Fees $6.00 |
from datetime import timedelta from QuantConnect.Data.UniverseSelection import * from Selection.FundamentalUniverseSelectionModel import FundamentalUniverseSelectionModel class MyUniverse(FundamentalUniverseSelectionModel): def __init__(self, algorithm): super().__init__(True, None, None) self.count = 0 self.name = "GOOG" def SelectCoarse(self, algorithm, coarse): self.count = (self.count + 1) % 2 if self.count == 0: return [] else: for c in coarse: if c.Symbol.Value == self.name: return [c.Symbol] return []
from MyUniverse import MyUniverse from MyAlpha import MyAlpha from MyPortfolio import MyPortfolio class VentralQuantumAutosequencers(QCAlgorithm): def Initialize(self): self.SetStartDate(2020, 7, 20) # Set Start Date self.SetEndDate(2020, 7, 25) # Set Start Date self.SetCash(100000) # Set Strategy Cash self.UniverseSettings.Resolution = Resolution.Hour self.SetUniverseSelection(MyUniverse(self)) self.SetAlpha(MyAlpha()) self.SetPortfolioConstruction(MyPortfolio(self)) self.SetRiskManagement(NullRiskManagementModel()) # self.SetExecution(NullExecutionModel()) self.SetExecution(ImmediateExecutionModel()) def OnData(self, data): '''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here. Arguments: data: Slice object keyed by symbol containing the stock data ''' # if not self.Portfolio.Invested: # self.SetHoldings("SPY", 1)
from datetime import timedelta, datetime class MyAlpha(AlphaModel): def __init__(self): self.TargetWeight = {} # hash map, key: Symbol, value: SMA for rolling rebalance self.RollingWindowSize = 10 # cache from OnSecuritiesChanged self.lastChanges = {} self.hasChanges = False def Update(self, algorithm, data): insights = [] if not self.hasChanges: return insights # Handle securities changes self.hasChanges = False # Handle new securities for security in self.lastChanges.AddedSecurities: if security.Symbol not in self.TargetWeight: self.TargetWeight[security.Symbol] = SimpleMovingAverage(self.RollingWindowSize) self.TargetWeight[security.Symbol].Update(algorithm.Time, 1) insights.append(Insight.Price(security.Symbol, timedelta(10000), InsightDirection.Up, self.TargetWeight[security.Symbol].Current.Value)) algorithm.Log("Added Security: {}".format(security.Symbol)) # Handle removed securities for security in self.lastChanges.RemovedSecurities: self.TargetWeight[security.Symbol].Update(algorithm.Time, 0) insights.append(Insight.Price(security.Symbol, timedelta(10000), InsightDirection.Flat, self.TargetWeight[security.Symbol].Current.Value)) algorithm.Log("Removed Security: {}".format(security.Symbol)) return insights def OnSecuritiesChanged(self, algorithm, changes): self.lastChanges = changes self.hasChanges = True
from QuantConnect import Resolution, Extensions from QuantConnect.Algorithm.Framework.Alphas import * from QuantConnect.Algorithm.Framework.Portfolio import * from itertools import groupby from datetime import datetime, timedelta class MyPortfolio(PortfolioConstructionModel): def __init__(self, algorithm, rebalance = Resolution.Hour, portfolioBias = PortfolioBias.Long): self.portfolioBias = portfolioBias # If the argument is an instance of Resolution or Timedelta # Redefine rebalancingFunc rebalancingFunc = rebalance if isinstance(rebalance, int): rebalance = Extensions.ToTimeSpan(rebalance) if isinstance(rebalance, timedelta): rebalancingFunc = lambda dt: dt + rebalance if rebalancingFunc: self.SetRebalancingFunc(rebalancingFunc) self.algorithm = algorithm def DetermineTargetPercent(self, activeInsights): result = {} for insight in activeInsights: result[insight] = insight.Magnitude # self.algorithm.Log("SetHoldings, Symbol: {} Magnitude: {}".format(insight.Symbol, insight.Magnitude)) return result