Overall Statistics
Total Trades
1
Average Win
0%
Average Loss
0%
Compounding Annual Return
-12.970%
Drawdown
8.900%
Expectancy
0
Net Profit
0%
Sharpe Ratio
-1.416
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-0.111
Beta
0.028
Annual Standard Deviation
0.077
Annual Variance
0.006
Information Ratio
-1.05
Tracking Error
0.175
Treynor Ratio
-3.807
Total Fees
$1.85
namespace QuantConnect
{
    public class BasicTemplateNaturalGasAlgorithm : QCAlgorithm
    {
		private bool marketOnOpenIsSet = false;

        // Natural gas futures
        private const string RootNatGas = Futures.Energies.NaturalGas;

        public override void Initialize()
        {
            SetStartDate(2016, 1, 1);
			SetEndDate(2016, 4, 1);

            var futureNatGas = AddFuture(RootNatGas, Resolution.Minute);

            // set our expiry filter for this futures chain
            futureNatGas.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(182));
        }

        public override void OnData(Slice slice)
        {
            if (!Portfolio.Invested && !marketOnOpenIsSet)
            {
                foreach(var chain in slice.FutureChains)
                {
                    // find the front contract expiring no earlier than in 90 days
                    var contract = (
                        from futuresContract in chain.Value.OrderBy(x => x.Expiry)
                        where futuresContract.Expiry > Time.Date.AddDays(90)
                        select futuresContract
                        ).FirstOrDefault();

                    // if found, trade it
                    if (contract != null)
                    {
                        MarketOnOpenOrder(contract.Symbol, 1);
                        marketOnOpenIsSet = true;
                    }
                }
            }
        }

        public override void OnOrderEvent(OrderEvent orderEvent)
        {
            Log(orderEvent.ToString());
        }
    }
}