Overall Statistics
Total Trades
64
Average Win
7.71%
Average Loss
-1.71%
Compounding Annual Return
10.587%
Drawdown
31.200%
Expectancy
3.308
Net Profit
454.093%
Sharpe Ratio
0.75
Loss Rate
22%
Win Rate
78%
Profit-Loss Ratio
4.51
Alpha
0.091
Beta
-0.025
Annual Standard Deviation
0.119
Annual Variance
0.014
Information Ratio
0.217
Tracking Error
0.212
Treynor Ratio
-3.615
Total Fees
$776.39
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(2000, 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;}
                    
                    if (data.ContainsKey(sbond)==true)
                    {
                    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"));
                }
            }      
        }
    }
}