Overall Statistics Total Trades48Average Win11.13%Average Loss-8.75%Compounding Annual Return12.748%Drawdown41.300%Expectancy1.019Net Profit581.276%Sharpe Ratio0.706Loss Rate11%Win Rate89%Profit-Loss Ratio1.27Alpha0.077Beta0.574Annual Standard Deviation0.157Annual Variance0.024Information Ratio0.367Tracking Error0.142Treynor Ratio0.193Total Fees\$89.91
```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 = 2m;//Config.GetValue<decimal>("leverage", 1m);
//the days interval to perform rebalance
int days = 330;//Config.GetInt("days", 30);
DateTime rebalanced;

decimal tlt = 0.3m;//Config.GetValue<decimal>("tlt", 0.5m);
decimal spy = 0.4m;//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(2001, 1, 07);  //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
SetBrokerageModel(Brokerages.BrokerageName.InteractiveBrokersBrokerage, AccountType.Margin);

gld = 1 - tlt - spy;

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");
}
}

}
}```