| Overall Statistics |
|
Total Trades 48 Average Win 11.13% Average Loss -8.75% Compounding Annual Return 12.748% Drawdown 41.300% Expectancy 1.019 Net Profit 581.276% Sharpe Ratio 0.706 Loss Rate 11% Win Rate 89% Profit-Loss Ratio 1.27 Alpha 0.077 Beta 0.574 Annual Standard Deviation 0.157 Annual Variance 0.024 Information Ratio 0.367 Tracking Error 0.142 Treynor Ratio 0.193 Total 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
AddEquity("SPY", Resolution.Daily);
AddEquity("TLT", Resolution.Daily);
AddEquity("GLD", Resolution.Daily);
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"), () =>
{
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");
}
}
}
}