Overall Statistics Total Trades 7715 Average Win 1.07% Average Loss -0.82% Compounding Annual Return -1.115% Drawdown 51.100% Expectancy 0.058 Net Profit -21.650% Sharpe Ratio -0.019 Probabilistic Sharpe Ratio 0.000% Loss Rate 54% Win Rate 46% Profit-Loss Ratio 1.29 Alpha -0.001 Beta -0.013 Annual Standard Deviation 0.118 Annual Variance 0.014 Information Ratio -0.359 Tracking Error 0.213 Treynor Ratio 0.169 Total Fees $8093.18 Estimated Strategy Capacity$0 Lowest Capacity Asset ICE_WT1.QuantpediaFutures 2S
# https://quantpedia.com/strategies/trading-wti-brent-spread/
#
# A 20-day moving average of WTI/Brent spread is calculated each day. If the current spread value is above SMA 20 then we enter a short position
# in the spread on close (betting that the spread will decrease to the fair value represented by SMA 20). The trade is closed at the close of the
# trading day when the spread crosses below fair value. If the current spread value is below SMA 20 then we enter a long position betting that
# the spread will increase and the trade is closed at the close of the trading day when the spread crosses above fair value.

def Initialize(self):
self.SetStartDate(2000, 1, 1)
self.SetCash(100000)

self.symbols = [
"ICE_WT1",  # WTI Crude Futures, Continuous Contract
"ICE_B1"    # Brent Crude Oil Futures, Continuous Contract
]

for symbol in self.symbols:
data.SetLeverage(5)
data.SetFeeModel(CustomFeeModel(self))

def OnData(self, data):
symbol1 = self.Symbol(self.symbols)
symbol2 = self.Symbol(self.symbols)

if symbol1 in data.Keys and symbol2 in data.Keys and data[symbol1] and data[symbol2]:
price1 = data[symbol1].Price
price2 = data[symbol2].Price

if price1 != 0 and price2 != 0:

# MA calculation.

self.SetHoldings(symbol1, -1)
self.SetHoldings(symbol2, 1)
self.SetHoldings(symbol1, 1)
self.SetHoldings(symbol2, -1)

# Quantpedia data.
# NOTE: IMPORTANT: Data order must be ascending (datewise)
class QuantpediaFutures(PythonData):
def GetSource(self, config, date, isLiveMode):
return SubscriptionDataSource("data.quantpedia.com/backtesting_data/futures/{0}.csv".format(config.Symbol.Value), SubscriptionTransportMedium.RemoteFile, FileFormat.Csv)

def Reader(self, config, line, date, isLiveMode):
data = QuantpediaFutures()
data.Symbol = config.Symbol

if not line.isdigit(): return None
split = line.split(';')

data.Time = datetime.strptime(split, "%d.%m.%Y") + timedelta(days=1)
return OrderFee(CashAmount(fee, "USD"))