Пример #1
0
        /// <summary>
        /// Gets the networth chart.
        /// </summary>
        /// <returns>The networth graph.</returns>
        private LineChartViewModel CreateNetworthChart()
        {
            var    lineChart     = new LineChartViewModel();
            var    points        = new List <double>();
            double previousValue = 0;

            foreach (var trade in this._networkTrades)
            {
                var value = trade.Price.CalculateValue();
                if (trade.IsOutgoing)
                {
                    previousValue -= value;
                }
                else
                {
                    previousValue += value;
                }

                if (previousValue < 0)
                {
                    points.Add(0);
                }
                else
                {
                    points.Add(previousValue);
                }
            }

            lineChart.Add("Networth", points);
            return(lineChart);
        }
Пример #2
0
        /// <summary>
        /// Gets the networth chart.
        /// </summary>
        /// <returns>The networth graph.</returns>
        private LineChartViewModel CreateNetworthChart()
        {
            var lineChart = new LineChartViewModel();
            var points    = new List <double>();

            if (this._networthTrades.Count() < 2)
            {
                return(lineChart);
            }

            double previousValue = 0;
            var    firstTrade    = this._networthTrades.First();
            var    lastTrade     = this._networthTrades.Last();

            var days        = (lastTrade.Date - firstTrade.Date).TotalDays;
            var tradeGroups = this._networthTrades.GroupBy(t => t.Date.Date);

            var firstDate = firstTrade.Date.Date;

            for (int i = 0; i < days + 1; i++)
            {
                var group = tradeGroups.FirstOrDefault(g => g.Key.Date == firstDate);
                if (group == null)
                {
                    points.Add(previousValue);
                    firstDate = firstDate.AddDays(1);
                    continue;
                }

                var value = group.Select(g => g.Price.CalculateValue()).Sum();
                previousValue += value;

                if (previousValue < 0)
                {
                    points.Add(0);
                }
                else
                {
                    points.Add(previousValue);
                }

                firstDate = firstDate.AddDays(1);
            }

            lineChart.Add("Networth", points);
            return(lineChart);
        }