Overall Statistics
Total Trades
41
Average Win
24.30%
Average Loss
-0.05%
Compounding Annual Return
41.846%
Drawdown
34.100%
Expectancy
231.206
Net Profit
1058.670%
Sharpe Ratio
1.208
Loss Rate
54%
Win Rate
46%
Profit-Loss Ratio
502.11
Alpha
0.324
Beta
-0.029
Annual Standard Deviation
0.266
Annual Variance
0.071
Information Ratio
0.746
Tracking Error
0.297
Treynor Ratio
-11.134
Total Fees
$1460.19
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 = "USMV"; // US low volatility etf oct 2011
    //    private string symbol = "DDM";  // dow 2x ETF  6/2006
    //    private string symbol = "DIA";
    //    private string symbol = "UMDD";  // 3x mid cap etf 2/22/2010
       private string symbol = "UDOW";  // 3x DOW
        //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(2010, 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 " + 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"));
                }
            }      
        }
    }
}