Overall Statistics |
Total Trades 43 Average Win 7.88% Average Loss -1.75% Compounding Annual Return 11.561% Drawdown 29.500% Expectancy 3.004 Net Profit 198.976% Sharpe Ratio 0.775 Loss Rate 27% Win Rate 73% Profit-Loss Ratio 4.51 Alpha 0.098 Beta -0.016 Annual Standard Deviation 0.126 Annual Variance 0.016 Information Ratio 0.183 Tracking Error 0.224 Treynor Ratio -6.002 Total Fees $308.56 |
using System; using System.Collections; using System.Collections.Generic; namespace QuantConnect { using QuantConnect.Securities; using QuantConnect.Models; //Sell in May Algorithm Example: public partial class QCUSellInMay : QCAlgorithm, IAlgorithm { //Algorithm Variables //int quantity = 400; int ownbond = 0; int owndia = 0; int season = 0; private string symbol = "DIA"; //private string symbol = "IJR"; // ishares core S&P small cap etf private string sbond = "AGG"; // agg is agreggate bond etf ishares us //private string sbond = "PONDX"; private decimal cash = 100000; public MovingAverageConvergenceDivergence _macd; //Initialize the Strategy public override void Initialize() { SetCash(cash); SetStartDate(2007, 10, 10); SetEndDate(2017, 10, 10); AddSecurity(SecurityType.Equity, symbol, Resolution.Minute); AddSecurity(SecurityType.Equity, sbond, Resolution.Minute); _macd = MACD(symbol,12, 26, 9,MovingAverageType.Simple,Resolution.Daily); } //Handle the data events: public void OnData(TradeBars data) { if (Time.ToString("MMM") == "May") { season = 1; } if (Time.ToString("MMM") == "Oct") { season = 2; } if (data.ContainsKey(symbol)==false) return; if (_macd<0 && season == 1) { if (owndia == 1) { Order(symbol, -Portfolio[symbol].Quantity); // sell DIA and then buy bond owndia = 0;} int quantity = (int)Math.Floor(Portfolio.Cash / data[sbond].Close); Order(sbond, quantity); ownbond = 1; Debug("QCU Sell In May: Flat " + quantity + Time.ToString("Y")); } else { if (_macd>0 && season == 2) { if (ownbond ==1) {Order(sbond, -Portfolio[sbond].Quantity); ownbond = 0;}// sell the bond fund and buy DIA int quantity = (int)Math.Floor(Portfolio.Cash / data[symbol].Close); Order(symbol, quantity); owndia = 1; Debug("QCU Sell In May: Long " + Time.ToString("Y")); } } } } }