Overall Statistics |
Total Trades 2 Average Win 1.71% Average Loss 0% Compounding Annual Return 162.692% Drawdown 2.500% Expectancy 0 Net Profit 1.332% Sharpe Ratio -3.887 Probabilistic Sharpe Ratio 10.919% Loss Rate 0% Win Rate 100% Profit-Loss Ratio 0 Alpha -0.064 Beta 1.033 Annual Standard Deviation 0.128 Annual Variance 0.016 Information Ratio -1.379 Tracking Error 0.056 Treynor Ratio -0.48 Total Fees $2.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, 1)) 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, .5)) 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 CreateTargets(self, algorithm, insights): targets = [] for insight in insights: targets.append(PortfolioTarget.Percent(algorithm, insight.Symbol, insight.Magnitude)) return targets # 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