Overall Statistics
Total Trades
39
Average Win
1.89%
Average Loss
-10.08%
Compounding Annual Return
-100.000%
Drawdown
74.700%
Expectancy
-0.472
Net Profit
-43.238%
Sharpe Ratio
1.964
Probabilistic Sharpe Ratio
46.332%
Loss Rate
56%
Win Rate
44%
Profit-Loss Ratio
0.19
Alpha
6.254
Beta
19.748
Annual Standard Deviation
4.565
Annual Variance
20.836
Information Ratio
1.949
Tracking Error
4.531
Treynor Ratio
0.454
Total Fees
$4867.35
import math 
import numpy as np
import pandas as pd
import talib

from calendar import monthrange
from datetime import date, datetime, time, timedelta 
from QuantConnect.Python import PythonQuandl


class Algorithm(QCAlgorithm):

    def Initialize(self):

        self.SetCash(5000000)
        self.SetStartDate(2020, 8, 10)
        #self.SetEndDate(2020, 5, 15)
    

        # SECURITIES

        self.usequities = ["SPY"]
        for s in self.usequities:
            x = self.AddEquity(s, Resolution.Daily) 

        self.fut_sp = self.AddFuture(Futures.Indices.SP500EMini)
        self.fut_sp.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(60))
        self.fut_gold = self.AddFuture(Futures.Metals.Gold)
        self.fut_gold.SetFilter(TimeSpan.FromDays(30), TimeSpan.FromDays(60))
        
        # SCHEDULE FUNCTIONS

        self.Schedule.On(self.DateRules.EveryDay("SPY"), self.TimeRules.At(9, 45), self.Trade_spfut) 
        self.Schedule.On(self.DateRules.EveryDay("SPY"), self.TimeRules.At(10, 45), self.Trade_goldfut) 
            
    # TRADING
    
    
    def Trade_spfut(self):
        
        for self.fut_sp in self.CurrentSlice.FutureChains:
            
            sp = [sp for sp in self.fut_sp.Value if sp.OpenInterest > 0]
            sorted_sp = sorted(sp, key=lambda k: k.OpenInterest, reverse = True)
            trade_sp = sorted_sp[0]
            
            self.SetHoldings(trade_sp.Symbol, 0.5)
            
            # log
            shares = self.Portfolio[trade_sp.Symbol].Quantity
            price = self.Securities[trade_sp.Symbol].Price
            self.Log("{} @ {}".format(shares,price))
            
    
    def Trade_goldfut(self):
        
        for self.fut_gold in self.CurrentSlice.FutureChains:
            
            gc = [gc for gc in self.fut_gold.Value if gc.OpenInterest > 0]
            sorted_gc = sorted(gc, key=lambda k: k.OpenInterest, reverse = True)
            trade_gc = sorted_gc[0]
            
            self.SetHoldings(trade_gc.Symbol, 0.5)
            
            # log
            shares = self.Portfolio[trade_gc.Symbol].Quantity
            price = self.Securities[trade_gc.Symbol].Price
            self.Log("{} @ {}".format(shares,price))