Overall Statistics
Total Trades
5
Average Win
0.79%
Average Loss
0%
Compounding Annual Return
2.509%
Drawdown
0.900%
Expectancy
0
Net Profit
1.735%
Sharpe Ratio
1.461
Loss Rate
0%
Win Rate
100%
Profit-Loss Ratio
0
Alpha
0.023
Beta
-0.021
Annual Standard Deviation
0.013
Annual Variance
0
Information Ratio
-1.735
Tracking Error
0.066
Treynor Ratio
-0.937
Total Fees
$9.25
namespace QuantConnect
{
    public class BasicTemplateFuturesAlgorithm : QCAlgorithm
    {
        public override void Initialize()
        {
            SetStartDate(2017, 1, 1);
            SetCash(1000000);

            // Gold futures
        	AddFuture(Futures.Metals.Gold).SetFilter(TimeSpan.Zero, TimeSpan.FromDays(182));
        }

        public override void OnData(Slice slice)
        {
            if (!Portfolio.Invested)
            {
                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)
                    {
                        MarketOrder(contract.Symbol, 1);
                    }
                }
            }
        }
    }
}