| Overall Statistics |
|
Total Trades 10 Average Win 4.68% Average Loss 0% Compounding Annual Return 86.829% Drawdown 12.800% Expectancy 0 Net Profit 30.184% Sharpe Ratio 2.735 Probabilistic Sharpe Ratio 78.764% Loss Rate 0% Win Rate 100% Profit-Loss Ratio 0 Alpha 0.665 Beta -0.021 Annual Standard Deviation 0.244 Annual Variance 0.059 Information Ratio 2.27 Tracking Error 0.322 Treynor Ratio -31.896 Total Fees $297.85 |
from math import floor
class FuturesHarryBrownStyle(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2010, 4, 20)
self.SetEndDate(2010, 9, 20)
self.SetCash(1000000)
self.Settings.FreePortfolioValuePercentage = 0.3
self.gold = self.AddSecurity(SecurityType.Future, "GC", Resolution.Minute)
self.gold.SetFilter(0, 90)
self.spEmini = self.AddFuture(Futures.Indices.SP500EMini)
self.spEmini.SetFilter(0, 90)
self.bonds = self.AddFuture(Futures.Financials.Y30TreasuryBond)
self.bonds.SetFilter(0, 90)
self.currentHoldings = {}
def OnMarginCallWarning(self):
self.Error("You received a margin call warning..")
def OnData(self, slice):
for chain in slice.FutureChains:
self.popularContracts = [contract for contract in chain.Value if contract.LastPrice > 0 ]#and contract.OpenInterest > 10]
if len(self.popularContracts) == 0:
continue
sortedByOIContracts = sorted(self.popularContracts, key=lambda k : k.OpenInterest, reverse=True)
self.liquidContract = sortedByOIContracts[0]
underlying = str((self.liquidContract))[:2]
if self.Portfolio[self.liquidContract.Symbol].Invested:
return
if underlying not in self.currentHoldings:
self.SetHoldings(self.liquidContract.Symbol, 0.08)
#self.Debug(f"New Position: {self.liquidContract.Symbol}. Expiry: {self.liquidContract.Expiry}")
self.currentHoldings[underlying] = self.liquidContract
#self.Portfolio.LogMarginInformation
elif self.liquidContract.Expiry > self.currentHoldings[underlying].Expiry:
# Sell the old & Delete asset from currentHoldings (for cleancode)
self.Liquidate(self.currentHoldings[underlying].Symbol)
#self.Debug(f"Old contract {self.currentHoldings[underlying].Symbol} liquidated. Expiry: {self.currentHoldings[underlying].Expiry}")
del self.currentHoldings[underlying]
# Buy the new, and update currentHoldingsDict
self.SetHoldings(self.liquidContract.Symbol, 0.08)
#self.Debug(f"New Position: {self.liquidContract.Symbol}. Expiry: {self.liquidContract.Expiry}")
self.currentHoldings[underlying] = self.liquidContract
#self.Portfolio.LogMarginInformationfrom Selection.FutureUniverseSelectionModel import FutureUniverseSelectionModel
from datetime import date, timedelta
class FrontMonthUniverseSelectionModel(FutureUniverseSelectionModel):
def __init__(self, select_future_chain_symbols):
super().__init__(timedelta(1), select_future_chain_symbols)
def Filter(self, filter):
return (filter.FrontMonth())