Exemple #1
0
        public static double CalcMaxDrawdownPercent(DataSeries <Value> accountValue)
        {
            bool   inDrawdown         = false;
            var    last               = (double)accountValue.First();
            var    lastHigh           = last;
            double worstInDrawdown    = double.PositiveInfinity;
            double maxDrawdownPercent = 0;

            foreach (var v in accountValue.Skip(1))
            {
                inDrawdown = inDrawdown || v < last;
                if (!inDrawdown)
                {
                    lastHigh = Math.Max(lastHigh, v);
                }
                else
                {
                    worstInDrawdown = Math.Min(worstInDrawdown, v);
                    if (v >= lastHigh)
                    {
                        inDrawdown         = false;
                        maxDrawdownPercent = Math.Max(maxDrawdownPercent, (lastHigh - worstInDrawdown) / lastHigh);
                        lastHigh           = v;
                        worstInDrawdown    = double.PositiveInfinity;
                    }
                }
                last = v;
            }

            return(maxDrawdownPercent);
        }
Exemple #2
0
 public static DataSeries <Bar> TrimToWindow(DataSeries <Bar> bars, Tuple2 <int> window)
 {
     return(new DataSeries <Bar>(bars.Symbol, bars.Skip(window.Item1).Take(window.Item2 - window.Item1 + 1)));
 }