Overall Statistics |
Total Trades 5 Average Win 0.53% Average Loss -4.70% Compounding Annual Return -7.508% Drawdown 12.200% Expectancy -0.444 Net Profit -3.239% Sharpe Ratio -0.419 Probabilistic Sharpe Ratio 14.779% Loss Rate 50% Win Rate 50% Profit-Loss Ratio 0.11 Alpha -0.018 Beta 0.666 Annual Standard Deviation 0.145 Annual Variance 0.021 Information Ratio 0.043 Tracking Error 0.084 Treynor Ratio -0.091 Total Fees $107.30 |
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.usd = self.AddFuture(Futures.Indices.SP500EMini, Resolution.Minute) self.usd.SetFilter(30, 90) self.prevLiquidContract = None 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] # Check if the we are currently invested in the most liquid contract if not self.Portfolio[self.liquidContract.Symbol].Invested: # Sell the old contract if there was one and it hasn't expired if self.prevLiquidContract is not None and \ self.liquidContract != self.prevLiquidContract and \ self.prevLiquidContract.Expiry > self.Time: self.SetHoldings(self.prevLiquidContract.Symbol, 0) # Liquidate old contract self.Debug(f"Old contract {self.prevLiquidContract.Symbol} liquidated") # Buy the most liquid contract self.Debug(f"New Position: {self.liquidContract.Symbol}. Expiry: {self.liquidContract.Expiry}") self.SetHoldings(self.liquidContract.Symbol, 0.08) self.prevLiquidContract = self.liquidContract
from 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())