| Overall Statistics |
|
Total Trades 257 Average Win 0.90% Average Loss -0.42% Compounding Annual Return 12.366% Drawdown 12.400% Expectancy 0.353 Net Profit 19.968% Sharpe Ratio 1.093 Probabilistic Sharpe Ratio 51.399% Loss Rate 57% Win Rate 43% Profit-Loss Ratio 2.15 Alpha 0.087 Beta 0.179 Annual Standard Deviation 0.12 Annual Variance 0.014 Information Ratio -0.455 Tracking Error 0.252 Treynor Ratio 0.734 Total Fees $382.88 |
class EMVIndicatorAlpha(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2019, 1, 1)
self.SetEndDate(2020, 7, 24)
self.SetCash(100000)
self.tickers = ["SPY"]
for ticker in self.tickers:
self.AddEquity(ticker, Resolution.Hour)
self.portfolioPercentage = 1/len(self.tickers)
self.lastday = None
self.symbolDataBySymbol = {}
self.emvIndicator(self.tickers)
EMVPlot = Chart("EMV Plot")
EMVPlot.AddSeries(Series("Buy", SeriesType.Scatter, 0))
EMVPlot.AddSeries(Series("Short", SeriesType.Scatter, 0))
EMVPlot.AddSeries(Series("Sell", SeriesType.Scatter, 0))
EMVPlot.AddSeries(Series("Price", SeriesType.Line, 0))
self.AddChart(EMVPlot)
EMVValuePlot = Chart("EMV Value Plot")
EMVValuePlot.AddSeries(Series("EMV", SeriesType.Line, 0))
self.AddChart(EMVValuePlot)
self.SetWarmUp(timedelta(days=2))
def OnData(self, data):
if self.IsWarmingUp: return
day= self.Time.day
if day == self.lastday:
return
self.lastday = day
self.emvIndicator(self.tickers)
for ticker, info in self.symbolDataBySymbol.items():
'''Enters a long or short position'''
if info.EMV > 0 and not self.Portfolio[ticker].Invested:
self.SetHoldings(ticker, self.portfolioPercentage)
self.Plot("EMV Plot", "Buy", self.Securities[ticker].Close)
if info.EMV < 0 and not self.Portfolio[ticker].Invested:
self.SetHoldings(ticker, -(self.portfolioPercentage)/20) #Allows 5% of portfolioPercentage to short
self.Plot("EMV Plot", "Short", self.Securities[ticker].Close)
'''Liquidates a long or short position'''
if info.EMV < 0 and self.Portfolio[ticker].IsLong:
self.Liquidate(ticker)
self.Plot("EMV Plot", "Sell", self.Securities[ticker].Close)
if info.EMV > 0 and self.Portfolio[ticker].IsShort:
self.Liquidate(ticker)
self.Plot("EMV Plot", "Sell", self.Securities[ticker].Close)
self.Plot("EMV Plot", "Price", self.Securities[ticker].Close)
self.Plot("EMV Value Plot", "EMV", float(info.EMV))
def emvIndicator(self, tickers):
self.df = self.History(tickers, 2, Resolution.Daily)
for ticker in tickers:
if not self.df.empty:
currentSymbolData = self.df.loc[ticker]
'''Calculation for Ease of Movement Value'''
mov_mid_today = (currentSymbolData["high"][1] + currentSymbolData["low"][1]) / 2
mov_mid_yesterday = (currentSymbolData["high"][0] + currentSymbolData["low"][0]) / 2
MID = mov_mid_today - mov_mid_yesterday
t_vol = self.Securities[ticker].Volume
ratio = (t_vol/10000) / (currentSymbolData["high"][1] - currentSymbolData["low"][1])
EMV = MID/ratio
else:
EMV = 0
self.symbolDataBySymbol[ticker] = SymbolData(ticker, EMV)
class SymbolData:
def __init__(self, symbol, EMV):
self.Symbol = symbol
self.EMV = EMV