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
-11.99
Tracking Error
0.012
Treynor Ratio
0
Total Fees
$0.00
using QuantConnect.Securities.Future;
using QuantConnect.Data.Market;

namespace QuantConnect.Algorithm.CSharp
{
    public class BuyAndHoldFuturesTemplate : QCAlgorithm
    {
        private Future _future;
        private FuturesContract _activeContract;
        private bool _isInitializedForFutures = false;
        private int _DaysBeforeExpiryToRollover = 1;

        public override void Initialize()
        {
            SetStartDate(2019, 1, 1);
            SetEndDate(2019, 1, 2);
            SetCash(100000);

            _future = AddFuture(Futures.Indices.SP500EMini, Resolution.Minute);
            _future.SetFilter(0, 600);

            var contracts = FutureChainProvider.GetFutureContractList(_future.Symbol, new DateTime(2019, 1, 1));
            Debug($"list of contracts from FutureChainProvider: {string.Join(", ", contracts.Select(x => x.Value).ToList())}");

            var futuresChain = new FuturesChain(contracts.First(), new DateTime(2019, 1, 1));
            var recentContracts = futuresChain
                .OrderBy(x => (x.Expiry - Time.Date).TotalDays)
                .ToList();
            if (recentContracts.Count == 0)
            {
                _activeContract = null;
                Debug($"ERROR - No contracts in var {nameof(recentContracts)}, no active contract assigned, no scheduled rollover. Liquidating portfolio.");

                return;
            }
            Debug($"list of sorted recent contracts: {string.Join(", ", recentContracts.Select(x => x.Symbol.Value).ToList())}");
        }
    }
}