| Overall Statistics |
|
Total Trades 0 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Net Profit 0% Sharpe Ratio 0 Probabilistic Sharpe Ratio 0% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta 0 Annual Standard Deviation 0 Annual Variance 0 Information Ratio -0.258 Tracking Error 0.43 Treynor Ratio 0 Total Fees $0.00 |
class MovingAverageAlphaModel(AlphaModel):
def __init__(self,
lookback = 200,
resolution_period = 30):
self.lookback = lookback
self.resolutionPeriod = resolution_period
self.insightPeriod = Time.Multiply(Extensions.ToTimeSpan(Resolution.Daily), self.resolutionPeriod)
self.securities = []
self.insightsTimeBySymbol = {}
self.Name = '{}(l:{},rp:{})'.format(self.__class__.__name__, self.lookback, self.resolutionPeriod)
def Update(self, algorithm, data):
''' Creates a constant insight for each security as specified via the constructor
Args:
algorithm: The algorithm instance
data: The new data available
Returns:
The new insights generated'''
insights = []
for security in self.securities:
# security price could be zero until we get the first data point. e.g. this could happen
# when adding both forex and equities, we will first get a forex data point
if security.Price != 0 and self.ShouldEmitInsight(algorithm.UtcTime, security.Symbol):
# If the current price is above the 'lookback', return an 'Up' insight.
# If the current price is below the 'lookback', return a 'Down' insight.
sma = algorithm.SMA(security.Symbol, self.lookback, Resolution.Daily)
algorithm.Log(security.Symbol.Value + ": " + str(security.Price) + ", " + str(sma.Current.Value))
if security.Price > sma.Current.Value:
insights.append(Insight(security.Symbol, self.insightPeriod, InsightType.Price, \
InsightDirection.Up, 0, security.Price, "", sma.Current.Value))
else:
insights.append(Insight(security.Symbol, self.insightPeriod, InsightType.Price, \
InsightDirection.Down, 0, security.Price, "", sma.Current.Value))
return insights
def OnSecuritiesChanged(self, algorithm, changes):
''' Event fired each time the we add/remove securities from the data feed
Args:
algorithm: The algorithm instance that experienced the change in securities
changes: The security additions and removals from the algorithm'''
for added in changes.AddedSecurities:
self.securities.append(added)
# this will allow the insight to be re-sent when the security re-joins the universe
for removed in changes.RemovedSecurities:
if removed in self.securities:
self.securities.remove(removed)
if removed.Symbol in self.insightsTimeBySymbol:
self.insightsTimeBySymbol.pop(removed.Symbol)
def ShouldEmitInsight(self, utcTime, symbol):
generatedTimeUtc = self.insightsTimeBySymbol.get(symbol)
if generatedTimeUtc is not None:
# we previously emitted a insight for this symbol, check it's period to see
# if we should emit another insight
if utcTime - generatedTimeUtc < self.insightPeriod:
return False
# we either haven't emitted a insight for this symbol or the previous
# insight's period has expired, so emit a new insight now for this symbol
self.insightsTimeBySymbol[symbol] = utcTime
return Truefrom MovingAverageAlphaModel import MovingAverageAlphaModel
from Execution.ImmediateExecutionModel import ImmediateExecutionModel
from Portfolio.EqualWeightingPortfolioConstructionModel import EqualWeightingPortfolioConstructionModel
class QuantumModulatedAntennaArray(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2020, 1, 1)
self.SetCash(100000)
self.movingAverageLookback = 5
self.resolutionPeriod = 1
self.benchmark = Symbol.Create('SPY', SecurityType.Equity, Market.USA)
self.SetAlpha(MovingAverageAlphaModel(self.movingAverageLookback, self.resolutionPeriod))
self.SetExecution(ImmediateExecutionModel())
self.SetPortfolioConstruction(NullPortfolioConstructionModel())
#symbols = [ Symbol.Create("UPRO", SecurityType.Equity, Market.USA), \
# Symbol.Create("TMF", SecurityType.Equity, Market.USA)]
symbols = [ Symbol.Create("UPRO", SecurityType.Equity, Market.USA)]
self.SetUniverseSelection( ManualUniverseSelectionModel(symbols) )
self.EnableAutomaticIndicatorWarmUp = True
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)