コード例 #1
0
        private EquityCurve EcFromEquitySummaries(Dictionary <DateTime, decimal> summaries, Dictionary <DateTime, decimal> depositsWithdrawals)
        {
            if (summaries.Count == 0)
            {
                return(new EquityCurve(100, summaries.First().Key));
            }

            var     ec        = new EquityCurve(100, summaries.First().Key);
            decimal lastTotal = summaries.First().Value;
            bool    first     = true;

            foreach (var kvp in summaries)
            {
                if (first)
                {
                    first = false;
                    continue;
                }
                DateTime date             = kvp.Key;
                decimal  total            = kvp.Value;
                decimal  externalCashFlow = depositsWithdrawals.ContainsKey(date) ? depositsWithdrawals[date] : 0;

                if (lastTotal != 0)
                //make sure we avoid division by zero...equity can't change if we have 0 to start with anyway
                {
                    double ret = (double)(((total - externalCashFlow) - lastTotal) / lastTotal);
                    ec.AddReturn(ret, date);
                }
                lastTotal = total;
            }
            ec.CalcFinalValues(summaries.Last().Key);
            return(ec);
        }
コード例 #2
0
        private EquityCurve EcFromEquitySummaries(List <EquitySummary> summaries, Dictionary <DateTime, decimal> depositsWithdrawals)
        {
            if (summaries.Count == 0)
            {
                return(new EquityCurve());
            }

            var     ec        = new EquityCurve();
            decimal lastTotal = summaries[0].Total;

            for (int i = 1; i < summaries.Count; i++)
            {
                var     es = summaries[i];
                decimal externalCashFlow = depositsWithdrawals.ContainsKey(es.Date) ? depositsWithdrawals[es.Date] : 0;

                if (lastTotal != 0)
                //make sure we avoid division by zero...equity can't change if we have 0 to start with anyway
                {
                    double ret = (double)(((es.Total - externalCashFlow) - lastTotal) / lastTotal);
                    ec.AddReturn(ret, es.Date);
                }
                lastTotal = es.Total;
            }
            ec.CalcFinalValues(summaries.Last().Date);
            return(ec);
        }
コード例 #3
0
        private EquityCurve EcFromEquitySummaries(Dictionary<DateTime, decimal> summaries, Dictionary<DateTime, decimal> depositsWithdrawals)
        {
            if (summaries.Count == 0) return new EquityCurve(100, DateTime.Now);

            var ec = new EquityCurve(100, summaries.First().Key);
            decimal lastTotal = summaries.First().Value;
            bool first = true;
            foreach(var kvp in summaries)
            {
                if (first)
                {
                    first = false;
                    continue;
                }
                DateTime date = kvp.Key;
                decimal total = kvp.Value;
                decimal externalCashFlow = depositsWithdrawals.ContainsKey(date) ? depositsWithdrawals[date] : 0;

                if (lastTotal != 0)
                //make sure we avoid division by zero...equity can't change if we have 0 to start with anyway
                {
                    double ret = (double)(((total - externalCashFlow) - lastTotal) / lastTotal);
                    ec.AddReturn(ret, date);
                }
                lastTotal = total;
            }
            ec.CalcFinalValues(summaries.Last().Key);
            return ec;
        }