Overall Statistics
Total Trades
58
Average Win
0.13%
Average Loss
-0.05%
Compounding Annual Return
2288.702%
Drawdown
1.300%
Expectancy
0.613
Net Profit
5.967%
Sharpe Ratio
11.537
Loss Rate
54%
Win Rate
46%
Profit-Loss Ratio
2.49
Alpha
2.465
Beta
-0.005
Annual Standard Deviation
0.214
Annual Variance
0.046
Information Ratio
11.473
Tracking Error
0.214
Treynor Ratio
-495.704
Total Fees
$344.30
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, 5)
        self.SetCash(100000)
        self.a = self.AddEquity("VIXY", Resolution.Hour).Symbol
        self.b = self.AddEquity("SVXY", Resolution.Hour).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)))