| Overall Statistics |
|
Total Trades 1579 Average Win 0.03% Average Loss -0.02% Compounding Annual Return -85.709% Drawdown 5.100% Expectancy -0.658 Net Profit -2.457% Sharpe Ratio -9.537 Loss Rate 87% Win Rate 13% Profit-Loss Ratio 1.62 Alpha -1.552 Beta 0.005 Annual Standard Deviation 0.163 Annual Variance 0.026 Information Ratio -9.622 Tracking Error 0.163 Treynor Ratio -339.026 Total Fees $10479.72 |
import numpy as np
from datetime import timedelta
from datetime import datetime
import pandas as pd
class MovingAverage(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2018, 1, 1)
self.SetEndDate(2018, 1, 3)
self.SetCash(100000)
self.a = self.AddEquity("VIXY", Resolution.Minute).Symbol
self.b = self.AddEquity("SVXY", Resolution.Minute).Symbol
self.SetWarmUp(30,Resolution.Daily)
self.previous = None
self.position = None
self.macd1 = self.MACD(self.a, 40, 85, 30, MovingAverageType.Exponential, Resolution.Hour)
self.macd2 = self.MACD(self.b, 40, 85, 30, MovingAverageType.Exponential, Resolution.Hour)
#self.rsi_vixy = self.RSI("VIXY", 18, MovingAverageType.Exponential,Resolution.Hour)
#self.rsi_svxy = self.RSI("SVXY", 18, MovingAverageType.Exponential,Resolution.Hour)
def OnData(self,data):
if self.IsWarmingUp: return
if self.macd1.Current.Value > self.macd1.Signal.Current.Value and self.macd2.Current.Value < self.macd2.Signal.Current.Value:
if not self.Portfolio.Invested:
self.SetHoldings("SVXY", -0.3)
self.SetHoldings("VIXY", 1.3)
self.Log('SVXY %' + str(round((self.Securities["SVXY"].Price * self.Portfolio['SVXY'].Quantity)/self.Portfolio.TotalPortfolioValue,4)))
self.Log('VIXY %' + str(round((self.Securities["VIXY"].Price * self.Portfolio['VIXY'].Quantity)/self.Portfolio.TotalPortfolioValue,4)))
else:
self.Liquidate("SVXY")
self.SetHoldings("SVXY", -0.3)
self.SetHoldings("VIXY", 1.3)
self.Log('SVXY %' + str(round((self.Securities["SVXY"].Price * self.Portfolio['SVXY'].Quantity)/self.Portfolio.TotalPortfolioValue,4)))
self.Log('VIXY %' + str(round((self.Securities["VIXY"].Price * self.Portfolio['VIXY'].Quantity)/self.Portfolio.TotalPortfolioValue,4)))
if self.macd1.Current.Value < self.macd1.Signal.Current.Value and self.macd2.Current.Value > self.macd2.Signal.Current.Value:
if not self.Portfolio.Invested:
self.SetHoldings("VIXY", -0.3)
self.SetHoldings("SVXY", 1.3)
self.Log('SVXY %' + str(round((self.Securities["SVXY"].Price * self.Portfolio['SVXY'].Quantity)/self.Portfolio.TotalPortfolioValue,4)))
self.Log('VIXY %' + str(round((self.Securities["VIXY"].Price * self.Portfolio['VIXY'].Quantity)/self.Portfolio.TotalPortfolioValue,4)))
else:
self.Liquidate("VIXY")
self.SetHoldings("VIXY", -0.3)
self.SetHoldings("SVXY", 1.3)
self.Log('SVXY %' + str(round((self.Securities["SVXY"].Price * self.Portfolio['SVXY'].Quantity)/self.Portfolio.TotalPortfolioValue,4)))
self.Log('VIXY %' + str(round((self.Securities["VIXY"].Price * self.Portfolio['VIXY'].Quantity)/self.Portfolio.TotalPortfolioValue,4)))