Overall Statistics
Total Trades
8
Average Win
0.16%
Average Loss
-0.22%
Compounding Annual Return
-1.620%
Drawdown
1.200%
Expectancy
-0.143
Net Profit
-0.125%
Sharpe Ratio
-0.968
Probabilistic Sharpe Ratio
30.322%
Loss Rate
50%
Win Rate
50%
Profit-Loss Ratio
0.71
Alpha
-0.02
Beta
-0.008
Annual Standard Deviation
0.017
Annual Variance
0
Information Ratio
1.862
Tracking Error
0.256
Treynor Ratio
2.076
Total Fees
$22.10
import datetime
from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Algorithm")
AddReference("QuantConnect.Common")

from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from time import sleep

class ControllClass(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2020, 9, 1)  # Set Start Date
        self.SetCash(100000)  # Set Strategy Cash
        self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage, AccountType.Cash)
        
        self.Settings.FreePortfolioPercentage = 0.8
        self.weekDays = ("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday")
        
        self.symbols = []
        self.openAt = datetime.time(15,55)
        
        self.spy = self.AddEquity("SPY").Symbol
        self.symbols.append(self.spy)
        self.gld = self.AddEquity("GLD").Symbol
        self.symbols.append(self.gld)
        
        self.SetBenchmark(self.spy)
        self.UniverseSettings.Resolution = Resolution.Minute
        self.SetPortfolioConstruction( EqualWeightingPortfolioConstructionModel() )
        
        
        self.Schedule.On(self.DateRules.Every(
            DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Friday),
            self.TimeRules.BeforeMarketClose(self.spy, 21), self.closePositions)
        
        self.sma = self.SMA(self.spy, 34, Resolution.Daily)
        self.SetWarmUp(timedelta(days=34))
        

    def OnData(self, data):
        if self.IsWarmingUp: return
        if not self.Time.time() >= self.openAt: return
        
        
        
        if self.Time.weekday() == 0:
            if not self.Portfolio[self.spy].Invested and data[self.spy].Close < self.sma.Current.Value:
                self.SetHoldings(self.spy, 1, True)
                # self.Debug(str(self.Portfolio.Invested))
                self.Debug(str(self.Securities[self.spy].Invested))
                self.Debug(f"ist long {str(self.Portfolio[self.spy].IsLong)}")
                self.Debug(f"Time {self.Time.weekday()}")
                return
        
        if self.Time.weekday() == 3:
            if not self.Portfolio[self.gld].Invested:
                self.SetHoldings(self.gld, 1, True)
                self.Debug(str(self.Securities[self.gld].Invested))
                self.Debug(f"ist long {str(self.Portfolio[self.gld].IsLong)}")
                self.Debug(f"Time {self.Time.weekday()}")
                return

    def closePositions(self):
        self.Liquidate()
        
    def OnOrderEvent(self, event):
        if event.Quantity == 0: return
        self.Debug(str(event))