Overall Statistics |
Total Trades 24 Average Win 9.84% Average Loss -4.24% Compounding Annual Return 14.048% Drawdown 13.400% Expectancy 1.115 Net Profit 62.087% Sharpe Ratio 0.963 Probabilistic Sharpe Ratio 42.439% Loss Rate 36% Win Rate 64% Profit-Loss Ratio 2.32 Alpha 0.053 Beta 0.442 Annual Standard Deviation 0.122 Annual Variance 0.015 Information Ratio -0.209 Tracking Error 0.134 Treynor Ratio 0.265 Total Fees $1504.05 |
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(2009, 5, 1); SetEndDate(2012, 12, 31); SetCash(1000000); AddEquity("SPY"); future = AddFuture("NQ"); 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(); var oldContract = liquidContract; 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) { var oldFuture = (Future)Securities[oldContract.Symbol]; if (oldFuture.Holdings.Quantity != 0) { MarketOrder(oldContract.Symbol, -oldFuture.Holdings.Quantity); } decimal midPrice = (ContractFuture.AskPrice + ContractFuture.BidPrice)/2; var multiplier = ContractFuture.SymbolProperties.ContractMultiplier; var notionalValue = midPrice * multiplier; var MaxSafeQty = Portfolio.TotalPortfolioValue / notionalValue; // SHOULD NEVER GET MARGIN CALLED!!! MaxSafeQty = decimal.Round(MaxSafeQty); Debug("Contract Multiplier: " + ContractFuture.SymbolProperties.ContractMultiplier); MarketOrder(liquidContract.Symbol, MaxSafeQty); } } }); 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; } } } }