Overall Statistics Total Trades40Average Win132.52%Average Loss-39.82%Compounding Annual Return32.097%Drawdown68.300%Expectancy1.164Net Profit2821.538%Sharpe Ratio0.947Loss Rate50%Win Rate50%Profit-Loss Ratio3.33Alpha0.199Beta0.917Annual Standard Deviation0.283Annual Variance0.08Information Ratio0.823Tracking Error0.235Treynor Ratio0.292Total 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

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"), () =>
{
{
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");
}
}

}
}```