Exemple #1
0
        void Draw(String key, SortedList<DateTime, double> pnl, DrawDown dd)
        {
            this.chart1.Series.Clear();
            this.chart1.Series.Add(key);
            this.chart1.Series[key].LegendText = key;
            this.chart1.Series[key].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;

            foreach (KeyValuePair<DateTime, double> kv in pnl)
            {
                int index = this.chart1.Series[key].Points.AddXY(kv.Key, kv.Value);
                if (dd.StartDate == kv.Key)
                {
                    this.chart1.Series[key].Points[index].Label = String.Format("MDD start {0}", kv.Key.ToString("yyyy-MM-dd"));
                }
                if (dd.EndDate == kv.Key)
                {
                    this.chart1.Series[key].Points[index].Label = String.Format("MDD end {0}", kv.Key.ToString("yyyy-MM-dd"));
                }
            }
        }
Exemple #2
0
        static DrawDown GetDrawDown(
            DateTime startDate, DateTime endDate, SortedList<DateTime, double> input)
        {
            DateTime curDate = startDate;

            double startDateCumPnL = input[startDate];
            DrawDown dd = new DrawDown();
            dd.StartDate = startDate;
            dd.EndDate = endDate;

            while (curDate <= endDate)
            {
                if (input.ContainsKey(curDate))
                {
                    double curDateCumPnL = input[curDate];
                    double diff = curDateCumPnL - startDateCumPnL;

                    if (diff <= dd.Value)
                    {
                        //update
                        dd.Value = diff;
                        dd.EndDate = curDate;
                    }
                }
                curDate = curDate.AddDays(1);
            }

            return dd;
        }
Exemple #3
0
        public static DrawDown GetMaxDrawDown(SortedList<DateTime, double> input)
        {
            DrawDown mdd = new DrawDown();
            DateTime end = input.Keys[input.Keys.Count - 1];

            foreach (DateTime cur in input.Keys)
            {
                DrawDown dd = GetDrawDown(cur, end, input);
                if (dd.Value < mdd.Value)
                {
                    mdd = dd;
                }
            }
            return mdd;
        }