| Overall Statistics |
|
Total Trades 0 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Net Profit 0% Sharpe Ratio 0 Probabilistic Sharpe Ratio 0% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta 0 Annual Standard Deviation 0 Annual Variance 0 Information Ratio -2.796 Tracking Error 0.091 Treynor Ratio 0 Total Fees $0.00 |
from math import floor
class BasicTemplateFuturesAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2019, 12, 20)
self.SetEndDate(2020, 2, 20)
self.SetCash(1000000)
self.btc = self.AddFuture(Futures.Currencies.BTC)
self.btc.SetFilter(0, 160)
self.symbol = self.btc.Symbol
#1. Widen the free portfolio percentage to 30% to avoid margin calls for futures
self.Settings.FreePortfolioValuePercentage = 0.30
self.SetWarmup(10)
def OnMarginCallWarning(self):
self.Error("You received a margin call warning..")
def OnData(self, slice):
if not slice.Bars.ContainsKey(self.symbol) : return
for chain in slice.FutureChains:
self.popularContracts = [contract for contract in chain.Value if contract.OpenInterest > 0]
if len(self.popularContracts) == 0:
continue
sortedByOIContracts = sorted(self.popularContracts, key=lambda k : k.OpenInterest, reverse=True)
self.liquidContract = sortedByOIContracts[0]
if not self.Portfolio.Invested:
#2. Delete the old code for manually calculating the position size (lines 30-33)
#3. Replace the manually calculated math above with
# the SetHoldings function to automatically calculate your position size
self.SetHoldings(self.liquidContract.Symbol, 1)