Overall Statistics |
Total Trades 56 Average Win 1.86% Average Loss -3.51% Compounding Annual Return -6.462% Drawdown 34.300% Expectancy -0.071 Net Profit -15.01% Sharpe Ratio -0.307 Loss Rate 39% Win Rate 61% Profit-Loss Ratio 0.53 Alpha -0.031 Beta -0.119 Annual Standard Deviation 0.171 Annual Variance 0.029 Information Ratio -1.101 Tracking Error 0.212 Treynor Ratio 0.441 Total Fees $105.26 |
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 { SimpleMovingAverage sma; ExponentialMovingAverage ema; SecurityHolding SPY; //Initialize the data and resolution you require for your strategy: public override void Initialize() { //Start and End Date range for the backtest: SetStartDate(2013, 1, 1); SetEndDate(DateTime.Now.Date.AddDays(-1)); //Cash allocation SetCash(25000); // register for hourly SPY data AddSecurity(SecurityType.Equity, "SPY", Resolution.Hour); // define our 6 period SMA, we'll pump 4-hour data into this guy sma = new SimpleMovingAverage("SMA6", 6); // define out 9 period EMA, we'll pump 4-hour data into this guy as well ema = new ExponentialMovingAverage("EMA19", 19); // define a 4 hour consolidator, each consolidator can only be bound to // a single symbol, so if we wanted to also do AAPL data, we would need // another consolidator for AAPL var fourHourSpy = ResolveConsolidator("SPY", TimeSpan.FromHours(4)); // register our sma to receive data from our fourHourSpy consolidator, making our // sma a 6 period 4-hour SMA RegisterIndicator("SPY", sma, fourHourSpy); // register our ema to receive data from our fourHourSpy consolidator, making our // ema a 6 period 4-hour SMA RegisterIndicator("SPY", ema, fourHourSpy); // Plot our indicators on each new update PlotIndicator("SPY", sma, ema); SPY = Portfolio["SPY"]; } //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 (!sma.IsReady || !ema.IsReady) return; const decimal threshold = 0.000075m; if (SPY.Quantity <= 0 && ema > sma*(1+threshold)) { SetHoldings("SPY", .75m); } else if (SPY.Quantity >= 0 && ema < sma*(1-threshold)) { SetHoldings("SPY", -.75m); } } } }