Overall Statistics
Total Trades
281
Average Win
0.53%
Average Loss
-0.17%
Compounding Annual Return
5.983%
Drawdown
2.300%
Expectancy
1.163
Net Profit
31.154%
Sharpe Ratio
2.084
Loss Rate
48%
Win Rate
52%
Profit-Loss Ratio
3.15
Alpha
0.062
Beta
-0.188
Annual Standard Deviation
0.028
Annual Variance
0.001
Information Ratio
1.371
Tracking Error
0.028
Treynor Ratio
-0.311
Total Fees
$1210.76
namespace QuantConnect.Rotation
{
    public class GlobalRotation : QCAlgorithm
    {
    	
    
        // these are the growth symbols we'll rotate through
        List<string> GrowthSymbols = new List<string>
        {
            "BSJJ", // US S&P mid cap 400
            "HYD", // iShares S&P europe 350
            "VMBS", // iShared MSCI emerging markets
            "SRLN", // iShares S&P latin america
        };

        // these are the safety symbols we go to when things are looking bad for growth
        List<string> SafetySymbols = new List<string>
        {
            "CASHX", // Vangaurd TSY 25yr+
        //    "SHY"  // Barclays Low Duration TSY
        };

        // we'll hold some computed data in these guys
        List<SymbolData> SymbolData = new List<SymbolData>();

        public override void Initialize()
        {
        	
        	Schedule.On(DateRules.Every(DayOfWeek.Monday), TimeRules.At(9, 31), () =>
            {
                Log("Mon at 12pm: Fired at: " + Time);
            });
            
            SetCash(25000);
            SetStartDate(2014, 1, 1);
            SetEndDate(2018, 9, 1);

            foreach (var symbol in GrowthSymbols.Union(SafetySymbols))
            {
                // ideally we would use daily data
                AddSecurity(SecurityType.Equity, symbol, Resolution.Minute);
                var oneMonthPerformance = MOM(symbol, 21, Resolution.Daily);
                var threeMonthPerformance = MOM(symbol, 42, Resolution.Daily);

                SymbolData.Add(new SymbolData
                {
                    Symbol = symbol,
                    OneMonthPerformance = oneMonthPerformance,
                    ThreeMonthPerformance = threeMonthPerformance
                });
            }
        }

        public void OnData(TradeBars data)
        {
            	
            
                    // pick which one is best from growth and safety symbols
                    var orderedObjScores = SymbolData.OrderByDescending(x => x.ObjectiveScore).ToList();
                    foreach (var orderedObjScore in orderedObjScores)
                    {
                        Log(">>SCORE>>" + orderedObjScore.Symbol + ">>" + orderedObjScore.ObjectiveScore);
                    }
                    var bestGrowth = orderedObjScores.First();

                    if (bestGrowth.ObjectiveScore > 0)
                    {
                        if (Portfolio[bestGrowth.Symbol].Quantity == 0)
                        {
                            Log("PREBUY>>LIQUIDATE>>");
                            Liquidate();
                        }
                        Log(">>BUY>>" + bestGrowth.Symbol + "@" + (100 * bestGrowth.OneMonthPerformance).ToString("00.00"));
                        SetHoldings(bestGrowth.Symbol, 1.0);
                    }
                    else
                    {
                        // if no one has a good objective score then let's hold cash this month to be safe
                        Log(">>LIQUIDATE>>CASH");
                        Liquidate();
                    }
                }
            }
        }
    

    class SymbolData
    {
        public string Symbol;

        public Momentum OneMonthPerformance { get; set; }
        public Momentum ThreeMonthPerformance { get; set; }

        public decimal ObjectiveScore
        {
            get
            {
                // we weight the one month performance higher
              //  decimal weight1 = 100;
              //  decimal weight2 = 75;

             //   return (weight1 * OneMonthPerformance + weight2 * ThreeMonthPerformance) / (weight1 + weight2);
                
                                // we weight the one month performance higher
                decimal weight1 = 49;
                decimal weight2 = 51;

                return (weight1 * OneMonthPerformance + weight2 * ThreeMonthPerformance);
            }
        }
    }