Overall Statistics
Total Trades
697
Average Win
0%
Average Loss
0%
Compounding Annual Return
1.140%
Drawdown
25.700%
Expectancy
0
Net Profit
17.444%
Sharpe Ratio
0.17
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0.009
Beta
0.004
Annual Standard Deviation
0.056
Annual Variance
0.003
Information Ratio
-0.378
Tracking Error
0.163
Treynor Ratio
2.655
Total Fees
$0.00
import numpy as np
from System import *
from NodaTime import DateTimeZone

from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Algorithm")
AddReference("QuantConnect.Common")

from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Data import *
from datetime import timedelta




### <summary>
### Day if week strategy for Oil and Gold
### </summary>
class ScheduledEventsAlgorithm(QCAlgorithm):
    '''Basic template algorithm simply initializes the date range and cash'''

    def Initialize(self):
        '''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.'''

        self.SetStartDate(2005,6, 1)  #Set Start Date
        self.SetEndDate(2019,8,1)     #Set End Date
        self.SetCash(1000000)            #Set Strategy Cash
        #Timezone Setting
        self.SetTimeZone(DateTimeZone.Utc)
        #
        
        #use self.Allocate to assign portfolio weights
        #self.Allocate = -2 # Percentage of holdings to risk
        
        # Setup Oanda Broker simulation or Interactive Broker for Equities or Oanda for CFD
        self.SetBrokerageModel(BrokerageName.OandaBrokerage)
        #self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage)
        
        #Adding Instruments 
        
        self.AddCfd("XAUUSD", Resolution.Minute)
        self.AddEquity("GLD", Resolution.Minute)
        #Logging / Debugs
        self.Logging_On = True
        self.Debug_On = False
        
        # Set Schedule to buy and sell
        #self.Schedule.On(self.DateRules.Every(DayOfWeek.Monday, DayOfWeek.Tuesday,DayOfWeek.Wednesday,DayOfWeek.Thursday,DayOfWeek.Friday), self.TimeRules.At(8, 0), self.MorningBuy)
        #self.Schedule.On(self.DateRules.Every(DayOfWeek.Monday, DayOfWeek.Tuesday,DayOfWeek.Wednesday,DayOfWeek.Thursday,DayOfWeek.Friday), self.TimeRules.At(20, 0), self.AfternoonSell)
        self.Schedule.On(self.DateRules.Every(DayOfWeek.Friday), self.TimeRules.At(0, 0), self.MorningBuy)
        self.Schedule.On(self.DateRules.Every(DayOfWeek.Monday), self.TimeRules.At(0, 0), self.AfternoonSell)
        #self.Schedule.On(self.DateRules.WeekEnd(), self.TimeRules.At(9, 1), self.MorningBuy)
        #self.Schedule.On(self.DateRules.WeekEnd(), self.TimeRules.At(17, 29), self.AfternoonSell)


    def OnData(self, data):
        '''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.

        Arguments:
            data: Slice object keyed by symbol containing the stock data
        '''
        pass

        
    def MorningBuy(self):
        if self.Debug_On:
            self.Debug("MorningBuy: Fired at : {0}".format(self.Time))
        #self.MarketOrder("GLD", 10)
        #self.Liquidate
        self.MarketOrder("XAUUSD", 1)
        #self.SetHoldings("XAUUSD", -2)
        
    
    def AfternoonSell(self):
        if self.Debug_On:
            self.Debug("AfternoonSell: Fired at : {0}".format(self.Time))
        self.Liquidate
        #self.SetHoldings("XAUUSD", 2)
        #self.MarketOrder("XAUUSD", 1 )