예제 #1
0
 private void frmStockAnalysis_Load(object sender, EventArgs e)
 {
     lblInformations.Text  = string.Empty;
     stockAnaliysisManager = new StockAnalysisManager(request);
     stockAnaliysisManager.RefreshList();
     gridFill(stockAnaliysisManager);
 }
예제 #2
0
        private void frmStockAnalysis_Load(object sender, EventArgs e)
        {
            var chartType = SeriesChartType.Spline;

            lvList.Items.Clear();

            chartPeriodGain.Series.Clear();
            Series totalGainSeries    = new Series();
            Series totalConstSeries   = new Series();
            Series expectedGainSeries = new Series();

            totalConstSeries.ChartType         = chartType;
            totalConstSeries.MarkerBorderColor = Color.MediumVioletRed;
            totalConstSeries.MarkerColor       = Color.MediumVioletRed;
            totalConstSeries.Color             = Color.Crimson;
            totalConstSeries.MarkerSize        = 5;
            totalConstSeries.MarkerStep        = 1;
            totalConstSeries.MarkerBorderWidth = 5;
            totalConstSeries.BorderWidth       = 3;
            totalConstSeries.MarkerStyle       = MarkerStyle.Circle;
            totalConstSeries.Name = Translate.GetMessage("const");

            totalGainSeries.ChartType         = chartType;
            totalGainSeries.MarkerBorderColor = Color.SteelBlue;
            totalGainSeries.MarkerColor       = Color.SteelBlue;
            totalGainSeries.Color             = Color.RoyalBlue;
            totalGainSeries.MarkerSize        = 5;
            totalGainSeries.BorderWidth       = 3;
            totalGainSeries.MarkerStep        = 1;
            totalGainSeries.MarkerBorderWidth = 5;
            totalGainSeries.MarkerStyle       = MarkerStyle.Circle;
            totalGainSeries.Name = Translate.GetMessage("gain");

            expectedGainSeries.ChartType         = chartType;
            expectedGainSeries.MarkerBorderColor = Color.Goldenrod;
            expectedGainSeries.MarkerColor       = Color.Goldenrod;
            expectedGainSeries.Color             = Color.Gold;
            expectedGainSeries.MarkerSize        = 5;
            expectedGainSeries.BorderWidth       = 3;
            expectedGainSeries.MarkerStep        = 1;
            expectedGainSeries.MarkerBorderWidth = 5;
            expectedGainSeries.MarkerStyle       = MarkerStyle.Circle;
            expectedGainSeries.Name = Translate.GetMessage("expected-gain");
            List <StockAnalysisManagerList> list = new List <StockAnalysisManagerList>();


            foreach (var period in Session.Entities.GetPeriods().Where(c => c.StartDate < DateTime.Now))
            {
                StockAnalysisManager analysisManager = new StockAnalysisManager(new StockAnalysisRequest
                {
                    Period = period
                });
                analysisManager.RefreshList();
                list.Add(new StockAnalysisManagerList {
                    Period = period, StockAnalysisManager = analysisManager
                });
            }

            decimal totalGain = 0;

            foreach (var item in list.Where(c => !c.Period.IsPublic).OrderBy(c => c.Period.StartDate))
            {
                totalGain += item.StockAnalysisManager.TotalGain;
                item.CumulativeEndOfDay = totalGain + item.StockAnalysisManager.ExpectedGain;
            }

            foreach (var item in list.OrderByDescending(c => c.Period.StartDate))
            {
                var li = new ListViewItem();
                li.Text = item.Period.PeriodId.ToString();
                li.SubItems.Add(new ListViewItem.ListViewSubItem()
                {
                    Name = "month",
                    Text = item.Period.PeriodName
                });
                li.SubItems.Add(new ListViewItem.ListViewSubItem()
                {
                    Name = "gain",
                    Text = item.StockAnalysisManager.TotalGain.ToMoneyStirng(2)
                });
                li.SubItems.Add(new ListViewItem.ListViewSubItem()
                {
                    Name = "const",
                    Text = item.StockAnalysisManager.TotalConst.ToMoneyStirng(2)
                });
                li.SubItems.Add(new ListViewItem.ListViewSubItem()
                {
                    Name = "expectedGain",
                    Text = item.StockAnalysisManager.ExpectedGain.ToMoneyStirng(2)
                });
                li.SubItems.Add(new ListViewItem.ListViewSubItem()
                {
                    Name = "endOfDay",
                    Text = (item.StockAnalysisManager.TotalGain + item.StockAnalysisManager.ExpectedGain).ToMoneyStirng(2)
                });
                li.SubItems.Add(new ListViewItem.ListViewSubItem()
                {
                    Name = "cumulativeEndOfDay",
                    Text = item.Period.IsPublic ? string.Empty : item.CumulativeEndOfDay.ToMoneyStirng(2)
                });
                if (item.Period.IsPublic)
                {
                    li.BackColor = Color.DarkSlateGray;
                }

                lvList.Items.Add(li);
            }

            foreach (var item in list.Where(c => !c.Period.IsPublic).OrderBy(c => c.Period.StartDate))
            {
                DataPoint pointTotalAgain = new DataPoint();
                pointTotalAgain.SetValueXY(item.Period.PeriodName, item.StockAnalysisManager.TotalGain);
                pointTotalAgain.ToolTip = $"{Session.DefaultAccount.MoneyType.MoneyTypeToString()} {item.StockAnalysisManager.TotalGain.ToMoneyStirng(2)}";
                totalGainSeries.Points.Add(pointTotalAgain);
                DataPoint pointTotalConst = new DataPoint();
                pointTotalConst.SetValueXY(item.Period.PeriodName, item.StockAnalysisManager.TotalConst);
                pointTotalConst.ToolTip = $"{Session.DefaultAccount.MoneyType.MoneyTypeToString()} {item.StockAnalysisManager.TotalConst.ToMoneyStirng(2)}";
                totalConstSeries.Points.Add(pointTotalConst);
                DataPoint pointExceptedGain = new DataPoint();
                pointExceptedGain.SetValueXY(item.Period.PeriodName, item.StockAnalysisManager.ExpectedGain);
                pointExceptedGain.ToolTip = $"{Session.DefaultAccount.MoneyType.MoneyTypeToString()} {item.StockAnalysisManager.ExpectedGain.ToMoneyStirng(2)}";
                expectedGainSeries.Points.Add(pointExceptedGain);
            }

            chartPeriodGain.Series.Add(totalGainSeries);
            chartPeriodGain.Series.Add(totalConstSeries);
            series.Add(totalGainSeries);
            series.Add(totalConstSeries);
            series.Add(expectedGainSeries);
        }
예제 #3
0
        private void gridFill(StockAnalysisManager analysisManager)
        {
            #region Grid
            decimal totalValue = 0;
            foreach (var item in analysisManager.StockAnalyses.OrderBy(c => c.LastTransactionDate))
            {
                var li = new ListViewItem();
                li.Text = item.Guid.ToString();
                li.SubItems.Add(new ListViewItem.ListViewSubItem()
                {
                    Name = "StockCode",
                    Text = item.StockCode
                });
                li.SubItems.Add(new ListViewItem.ListViewSubItem()
                {
                    Name = "Status",
                    Text = item.TotalAmount > 0 ? Translate.GetMessage("available") : ((item.TotalValue - item.TotalConst) > 0 ? Translate.GetMessage("avantage") : Translate.GetMessage("loss"))
                });
                if (item.TotalAmount == 0)
                {
                    if ((item.TotalValue - item.TotalConst) > 0)
                    {
                        li.BackColor = Color.PaleGreen;
                        li.ForeColor = Color.Black;
                    }
                    else
                    {
                        li.BackColor = Color.PaleVioletRed;
                        li.ForeColor = Color.Black;
                    }
                }
                else
                {
                    li.BackColor = Color.Tan;
                    li.ForeColor = Color.Black;
                }

                decimal?curValue = null;
                if (Session.Entities.GetCurrentStocks().Any(c => c.StockCode == item.StockCode && c.UpdateDate <= request.Period.EndDate))
                {
                    curValue = Session.Entities.GetCurrentStocks().Where(c => c.UpdateDate <= request.Period.EndDate).OrderByDescending(c => c.UpdateDate).FirstOrDefault(c => c.StockCode == item.StockCode).Price;
                }
                decimal value = item.TotalAmount == 0 ? (item.TotalSellAmount * item.SellPrice - item.TotalConst) : (item.TotalBuyAmount * (curValue.HasValue ? curValue.Value : item.BuyPrice));
                if (item.TotalAmount > 0)
                {
                    totalValue += value;
                }

                li.SubItems.Add(new ListViewItem.ListViewSubItem()
                {
                    Name = "TotalAmount",
                    Text = item.TotalAmount == 0 ? item.StockTransactions.Where(c => c.TransactionType == TransactionType.Buy).Sum(c => c.Amount).ToMoneyStirng(0) : item.TotalAmount.ToMoneyStirng(0)
                });
                li.SubItems.Add(new ListViewItem.ListViewSubItem()
                {
                    Name = "BuyPrice",
                    Text = item.BuyPrice.ToMoneyStirng(6)
                });
                li.SubItems.Add(new ListViewItem.ListViewSubItem()
                {
                    Name = "SellPrice",
                    Text = item.TotalAmount > 0 && curValue.HasValue ? $"[{curValue.Value.ToMoneyStirng(6)}]" : (item.SellPrice > 0 ? item.SellPrice.ToMoneyStirng(6) : "")
                });
                decimal gain = item.TotalAmount == 0 ? (item.TotalValue - item.TotalConst) : (curValue.HasValue ? (item.TotalBuyAmount * curValue.Value - item.TotalBuyAmount * item.BuyPrice - item.TotalConst) : 0);
                li.SubItems.Add(new ListViewItem.ListViewSubItem()
                {
                    Name = "Gain",
                    Text = gain == 0 ? "" : gain.ToMoneyStirng(2)
                });
                li.SubItems.Add(new ListViewItem.ListViewSubItem()
                {
                    Name = "Date",
                    Text = item.LastTransactionDate.ToShortDateString()
                });
                li.SubItems.Add(new ListViewItem.ListViewSubItem()
                {
                    Name = "TotalValue",
                    Text = value.ToMoneyStirng(2)
                });

                lvList.Items.Add(li);
            }
            lblInformations.Text = $"[{Translate.GetMessage("total-gain")}: {analysisManager.TotalGain.ToMoneyStirng(2)}, {Translate.GetMessage("total-const")}: {analysisManager.TotalConst.ToMoneyStirng(2)}, {Translate.GetMessage("available-value")}: {totalValue.ToMoneyStirng(2)}, {Translate.GetMessage("expected-gain")}: {analysisManager.ExpectedGain.ToMoneyStirng(2)}]";
            #endregion
        }