Overall Statistics |
Total Trades 7 Average Win 8.77% Average Loss -14.86% Compounding Annual Return 6.104% Drawdown 14.900% Expectancy 0.060 Net Profit 0.060% Sharpe Ratio 3.15 Probabilistic Sharpe Ratio 0% Loss Rate 33% Win Rate 67% Profit-Loss Ratio 0.59 Alpha 20.545 Beta 55.082 Annual Standard Deviation 2.573 Annual Variance 6.621 Information Ratio 3.271 Tracking Error 2.547 Treynor Ratio 0.147 Total Fees $12.95 |
using QuantConnect.Securities.Future; namespace QuantConnect { public partial class BootCampTask : QCAlgorithm { private decimal notionalValue; private decimal contractsToBuy; private FuturesChain contractChain; private Future future; private FuturesContract liquidContract; public override void Initialize() { SetStartDate(2016, 12, 20); SetEndDate(2016, 12, 24); SetCash(1000000); AddEquity("SPY"); future = AddFuture("ZB"); future.SetFilter(0, 190); Schedule.On(DateRules.EveryDay("SPY"), TimeRules.AfterMarketOpen("SPY", 30), () => { if(liquidContract != null) { var oldFuture = (Future)Securities[liquidContract.Symbol]; if (oldFuture.Holdings.Quantity != 0) { MarketOrder(liquidContract.Symbol, -oldFuture.Holdings.Quantity); } } if(contractChain != null && contractChain.Count() >= 1) { var contracts = contractChain.OrderBy(x => x.Expiry); liquidContract = contracts.First(); if (liquidContract.Expiry <= Time.Date.AddDays(8) & contractChain.Count() >= 2) { liquidContract = contracts.Skip(1).First(); } var ContractFuture = (Future)Securities[liquidContract.Symbol]; if (ContractFuture.Holdings.Quantity == 0) { MarketOrder(liquidContract.Symbol, 1); } } }); Schedule.On(DateRules.EveryDay("SPY"), TimeRules.AfterMarketOpen("SPY", 60), () => { }); } public override void OnMarginCallWarning() { Error("You received a Margin Call Warning! The assets will be liquidated to cover losses."); } public void OnData(Slice slice) { FuturesChain chain; if (slice.FuturesChains.TryGetValue(future.Symbol, out chain)) { contractChain = chain; } } } }