Overall Statistics
Total Orders
0
Average Win
0%
Average Loss
0%
Compounding Annual Return
0%
Drawdown
0%
Expectancy
0
Start Equity
100000
End Equity
100000
Net Profit
0%
Sharpe Ratio
0
Sortino Ratio
0
Probabilistic Sharpe Ratio
0%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0
Beta
0
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
0
Tracking Error
0
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
Portfolio Turnover
0%
#region imports
    using QuantConnect.Algorithm;
    using System;
    using System.Collections.Generic;
#endregion

namespace DebuggerError
{
    public class WellDressedBlueBear : QCAlgorithm
    {
        public override void Initialize()
        {
            var h2DatesStrg = GetParameter("h2_date_range", "5/2012");
            var h2ContractDates = ParseContractDatesParam(h2DatesStrg);
            Quit();
        }

        public static List<DateTime> ParseDateRanges(string datesStrg)
        {
            string[] ranges = datesStrg.Split(',');
            List<DateTime> rangePairs = new List<DateTime>();
            for (int i = 0; i < ranges.Length; i++)
            {
                string[] range = ranges[i].Trim().Split('-');
                if ((range.Length <= 0) || (range.Length > 2)) return (null);
                DateTime? rStart = ParseDateStrg(range[0]);
                if (rStart == null) return (null);
                /*=======================================================
                 * if a single month, add full chain
                 *======================================================*/
                if (range.Length == 1)
                {
                    DateTime chainYear = (DateTime)rStart;
                    while (chainYear.Year < DateTime.Now.Year)
                    {
                        rangePairs.Add(chainYear);
                        rangePairs.Add(chainYear);
                        chainYear = chainYear.AddYears(1);
                    }
                }
                else
                {
                    DateTime? rEnd = String.IsNullOrEmpty(range[1]) ? DateTime.Now : ParseDateStrg(range[1]);
                    if ((rEnd == null) || (rStart > rEnd)) return (null);
                    rangePairs.Add((DateTime)rStart);
                    rangePairs.Add((DateTime)rEnd);
                }
            }
            return (rangePairs.Count == 0 ? null : rangePairs);
        }

        public static List<DateTime> ParseContractDatesParam(string datesStrg)
        {
            List<DateTime> monthList = null;
            List<DateTime> rangePairs = ParseDateRanges(datesStrg);
            if (rangePairs != null)
            {
                monthList = new List<DateTime>();
                for (int i = 0; i < rangePairs.Count; i += 2)
                {
                    DateTime rStart = rangePairs[i];
                    DateTime rEnd = rangePairs[i + 1];
                    for (int yr = rStart.Year; yr <= rEnd.Year; yr++)
                    {
                        int strMonth = (yr == rStart.Year ? rStart.Month : 1);
                        int endMonth = (yr == rEnd.Year ? rEnd.Month : 12);
                        for (int mon = strMonth; mon <= endMonth; mon++)
                        {
                            DateTime newMon = new DateTime(yr, mon, 1);
                            if (monthList.Contains(newMon))
                            {
                                return (null);
                            }
                            monthList.Add(newMon);
                        }
                    }
                }
                if (monthList.Count == 0)
                {
                    monthList = null;
                }
            }
            if (monthList != null)
            {
                monthList.Sort();
            }
            return (monthList);
        }

        private static DateTime? ParseDateStrg(string dateStrg)
        {
            try
            {
                string[] yrMon = dateStrg.Trim().Split('/');
                if (yrMon.Length != 2) return (null);
                int month = int.Parse(yrMon[0]);
                int year = int.Parse(yrMon[1]);
                if ((month < 1) || (month > 12)) return (null);
                if (year < 100)
                {
                    year += (year >= 70 ? 1900 : 2000);
                }
                return (new DateTime(year, month, 1));
            }
            catch
            {
                return (null);
            }
        }
    }
}