Overall Statistics
Total Trades
106
Average Win
6.46%
Average Loss
-4.53%
Compounding Annual Return
0.744%
Drawdown
42.900%
Expectancy
0.095
Net Profit
8.370%
Sharpe Ratio
0.125
Probabilistic Sharpe Ratio
0.198%
Loss Rate
55%
Win Rate
45%
Profit-Loss Ratio
1.43
Alpha
0.017
Beta
0.012
Annual Standard Deviation
0.147
Annual Variance
0.022
Information Ratio
-0.559
Tracking Error
0.226
Treynor Ratio
1.582
Total Fees
$323.09
from datetime import datetime,timedelta
import numpy as np


class ScheduledEventsAlgorithm(QCAlgorithm):
    
    def Initialize(self):
        self.SetStartDate(2010, 1, 1)  # Set Start Date
        self.SetEndDate(2020, 11, 1) # Set end date
        self.SetCash(25000)  # Set Strategy Cash
        #self.symbol="XLK"
        self.XLK = self.AddEquity("XLK", Resolution.Hour)
        self.DBA = self.AddEquity("DBA", Resolution.Hour)
        #self.forex = self.AddForex(self.symbol, Resolution.Minute, Market.Oanda)
        #self.SetBrokerageModel(BrokerageName.Alpaca)
        #self.SetBrokerageModel(BrokerageName.Oanda)
        
    def OnData(self, data):
        if not self.Portfolio.Invested and self.Time.month==5:
            self.SetHoldings("XLK",1)
            self.SetHoldings("DBA",-1)
            
        if self.Portfolio.Invested and self.Time.month==9:
            self.Liquidate()
            
        if self.Portfolio.Invested and self.Time.month==2:
            self.Liquidate()
            
        if not self.Portfolio.Invested and self.Time.month==10:
            self.SetHoldings("DBA",1)
            self.SetHoldings("XLK",-1)