Esempio n. 1
0
 /// <summary>
 /// Call this at the end to add any open drawdowns to the drawdown length
 /// </summary>
 public void CalcFinalValues(DateTime dt)
 {
     if (DrawdownPct.Last() < -0.0000001)
     {
         DrawdownLengths.Add(dt - _drawdownStart);
     }
 }
Esempio n. 2
0
        public void AddChange(double change, DateTime?dt = null)
        {
            if (Equity.Count == 0)
            {
                Returns.Add(0);
                Equity.Add(change);
            }
            else
            {
                Returns.Add(Equity.Last() != 0 ? change / Equity.Last() : 0);
                Equity.Add(Equity[Equity.Count - 1] + change);
            }

            Changes.Add(change);
            _maxEquity = Math.Max(_maxEquity, Equity.Last());
            DrawdownPct.Add(_maxEquity == 0 ? 0 : Equity.Last() / _maxEquity - 1);
            DrawdownAmt.Add(Equity.Last() - _maxEquity);

            if (dt != null)
            {
                AddDrawdownLengths(dt.Value);
            }

            Dates.Add(dt);
        }
Esempio n. 3
0
        public void AddValue(double value, DateTime?dt = null)
        {
            if (Equity.Count == 0)
            {
                Returns.Add(0);
                Changes.Add(0);
            }
            else
            {
                Returns.Add(Equity.Last() != 0 ? value / Equity.Last() - 1 : 0);
                Changes.Add(value - Equity[Equity.Count - 1]);
            }

            Equity.Add(value);
            _maxEquity = Math.Max(_maxEquity, value);
            DrawdownPct.Add(_maxEquity == 0 ? 0 : value / _maxEquity - 1);
            DrawdownAmt.Add(Equity.Last() - _maxEquity);

            if (dt != null)
            {
                AddDrawdownLengths(dt.Value);
            }

            Dates.Add(dt);
        }
Esempio n. 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ret">Net Return</param>
        public void AddReturn(double ret, DateTime?dt = null)
        {
            if (Equity.Count == 0)
            {
                Equity.Add(1);
                Changes.Add(0);
            }
            else
            {
                Equity.Add(Equity.Last() * (1 + ret));
                Changes.Add(Equity[Equity.Count - 1] - Equity[Equity.Count - 2]);
            }

            _maxEquity = Math.Max(_maxEquity, Equity.Last());
            Returns.Add(ret);
            DrawdownPct.Add(_maxEquity == 0 ? 0 : Equity.Last() / _maxEquity - 1);
            DrawdownAmt.Add(Equity.Last() - _maxEquity);

            if (dt != null)
            {
                AddDrawdownLengths(dt.Value);
            }

            Dates.Add(dt);
        }
Esempio n. 5
0
        private void AddDrawdownLengths(DateTime dt)
        {
            if (Returns.Count > 1 && DrawdownPct[DrawdownPct.Count - 2] < -0.0000001 && DrawdownPct.Last() > -0.0000001)
            {
                DrawdownLengths.Add(dt - _drawdownStart);
            }

            if (DrawdownPct.Last() < -0.000001 && (Returns.Count <= 1 || DrawdownPct[DrawdownPct.Count - 2] > -0.000001))
            {
                _drawdownStart = dt;
            }
        }