Overall Statistics
Total Trades
40
Average Win
132.52%
Average Loss
-39.82%
Compounding Annual Return
32.097%
Drawdown
68.300%
Expectancy
1.164
Net Profit
2821.538%
Sharpe Ratio
0.947
Loss Rate
50%
Win Rate
50%
Profit-Loss Ratio
3.33
Alpha
0.199
Beta
0.917
Annual Standard Deviation
0.283
Annual Variance
0.08
Information Ratio
0.823
Tracking Error
0.235
Treynor Ratio
0.292
Total Fees
$487.72
namespace QuantConnect 
{   
    /*
    *   QuantConnect University: Full Basic Template:
    *
    *   The underlying QCAlgorithm class is full of helper methods which enable you to use QuantConnect.
    *   We have explained some of these here, but the full algorithm can be found at:
    *   https://github.com/QuantConnect/Lean/tree/master/Algorithm
    */
    /// <summary>
    /// Basic template algorithm simply initializes the date range and cash
    /// </summary>
     public class LRP : QCAlgorithm
    {
        //the leverage for each holding
        decimal leverage = 3.8m;//Config.GetValue<decimal>("leverage", 3.5m);
        //the days interval to perform rebalance
        int days = 391;//Config.GetInt("days", 30);
        DateTime rebalanced;

        decimal tlt = 0.3m;//Config.GetValue<decimal>("tlt", 0.5m);
        decimal spy = 0.5m;//Config.GetValue<decimal>("spy", 0.4m);
        decimal gld = 0.1m;

        /// <summary>
        /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
        /// </summary>
        public override void Initialize()
        {
            SetStartDate(2004, 11, 19);  //Set Start Date
            SetEndDate(2017, 1, 1);    //Set End Date
            SetCash(100000);             //Set Strategy Cash. Should be 3 month T Bills.

            //using etf rather than futures
            AddEquity("SPY", Resolution.Daily, Market.USA, false, 4);
            AddEquity("TLT", Resolution.Daily, Market.USA, false, 4);
            AddEquity("GLD", Resolution.Daily, Market.USA, false, 4);

            gld = 1 - tlt - spy;

            //minimum of 0.1 gld
            if (gld < 0.1m || gld + tlt + spy > 1)
            {
                Quit();
            }

            rebalanced = this.Time;

            Schedule.On(DateRules.EveryDay(), TimeRules.AfterMarketOpen("SPY"), () =>
            {
                if (rebalanced.AddDays(days) < this.Time)
                {
                    rebalanced = this.Time;
                    SetHoldings("TLT", tlt * leverage);
                    SetHoldings("SPY", spy * leverage);
                    SetHoldings("GLD", gld * leverage);
                    Debug("Rebalance");
                }
            });

        }

        public override void OnMarginCall(List<SubmitOrderRequest> requests)
        {
            //if (!LiveMode)
            //{
            //    this.Quit();
            //}
        }

        /// <summary>
        /// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
        /// </summary>
        /// <param name="data">Slice object keyed by symbol containing the stock data</param>
        public override void OnData(Slice data)
        {

            if (!Portfolio.Invested)
            {
                SetHoldings("TLT", tlt * leverage);
                SetHoldings("SPY", spy * leverage);
                SetHoldings("GLD", gld * leverage);
                Debug("Purchased Stock");
            }
        }

    }
}