| Overall Statistics |
|
Total Trades 1 Average Win 0% Average Loss -0.36% Compounding Annual Return -6.237% Drawdown 1.400% Expectancy -1 Net Profit -0.357% Sharpe Ratio -1.051 Loss Rate 100% Win Rate 0% Profit-Loss Ratio 0 Alpha -0.103 Beta 0.289 Annual Standard Deviation 0.052 Annual Variance 0.003 Information Ratio -2.783 Tracking Error 0.079 Treynor Ratio -0.191 Total Fees $3.57 |
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/QCAlgorithm/blob/master/QuantConnect.Algorithm/QCAlgorithm.cs
*/
public class BasicTemplateAlgorithm : QCAlgorithm
{
TradeBar _tslaDaily;
string symbol = "SPY";
RelativeStrengthIndex rsis;
RelativeStrengthIndex rsiw;
RelativeStrengthIndex rsie;
//Initialize the data and resolution you require for your strategy:
public override void Initialize()
{
//Start and End Date range for the backtest:
SetStartDate(2015, 5, 1);
SetEndDate(2015, 5, 20);
//Cash allocation
SetCash(75000);
//Add as many securities as you like. All the data will be passed into the event handler:
AddSecurity(SecurityType.Equity, symbol, Resolution.Minute);
Securities[symbol].SetDataNormalizationMode(DataNormalizationMode.Raw);
rsiw = RSI(symbol, 14, MovingAverageType.Wilders, Resolution.Daily);
rsis = RSI(symbol, 14, MovingAverageType.Simple, Resolution.Daily);
rsie = RSI(symbol, 14, MovingAverageType.Exponential, Resolution.Daily);
var dailyConsolidator = new TradeBarConsolidator(TimeSpan.FromDays(1));
dailyConsolidator.DataConsolidated += OnDataDaily;
SubscriptionManager.AddConsolidator("SPY",dailyConsolidator);
}
private void OnDataDaily(object sender,TradeBar consolidated)
{
if (Time.Year < 2015) return;
_tslaDaily = consolidated;
// Log(string.Format("S:{0}|W:{1}|E:{2}",
// rsis.Current.Value.ToString("0.00"),
// rsiw.Current.Value.ToString("0.00"),
// rsie.Current.Value.ToString("0.00"))
// );
Log(Time.ToString("u") + " Close price: " + consolidated.Close);
}
//Data Event Handler: New data arrives here. "TradeBars" type is a dictionary of strings so you can access it by symbol.
public void OnData(TradeBars data)
{
if (!Portfolio.Invested)
{
SetHoldings(symbol, 0.5m);
}
}
}
}