public List <ProfitReport> GroupProfitByTicker(List <TradeHistory> histories)
        {
            List <ProfitReport> profitReports = histories.GroupBy
                                                (
                history => history.Ticker,
                history => history,
                (key, group) =>
            {
                StockPriceDto price = _liveDateRepo.GetLastStockPrice(key);
                ProfitReport profit = new ProfitReport
                {
                    Ticker   = key,
                    AsOfDate = DateTime.Today,
                    Cost     = CalculatePortfolioCost(group.ToList()),
                    Quantity = CalculatePortfolioQuantity(group.ToList()),
                    CurPrice = price.LatestPrice.ClosePrice,
                    PrePrice = price.LatestPrice.PrePrice
                };
                profit.MarketValue     = profit.CurPrice * profit.Quantity;
                profit.DailyProfit     = (profit.CurPrice - profit.PrePrice) * profit.Quantity;
                profit.InceptionProfit = profit.MarketValue != 0 ? profit.MarketValue - profit.Cost : 0;

                return(profit);
            }

                                                )
                                                .OrderBy(p => p.Ticker)
                                                .ToList();

            return(profitReports);
        }
Ejemplo n.º 2
0
 public ProfitList()
 {
     InitializeComponent();
     datePickerStart.SelectedDate = DateTime.Now;
     datePickerEnd.SelectedDate = DateTime.Now;
     BindedLst = new List<long>();
     RPageSum = new ProfitReport();
     RPageSum.UserID = "本页合计";
     RTotalSum = new ProfitReport();
     RTotalSum.UserID = "总合计";
     srv_Profit = WcfProxy.GetProxy;
     rbtLists.IsChecked = true;
     srv_Profit.GetProfitReportCompleted += new EventHandler<GetProfitReportCompletedEventArgs>(srv_Profit_GetProfitReportCompleted);
     srv_Profit.GetProfitDetailCompleted += new EventHandler<GetProfitDetailCompletedEventArgs>(srv_Profit_GetProfitDetailCompleted);
     TextBlock txtb = new TextBlock()
     {
         Text = "本级",
         Style = Resources["TextBlockStyle1"] as Style,
         Cursor = Cursors.Hand
     };
     txtb.Tag = user.ID;
     txtb.MouseLeftButtonDown += new MouseButtonEventHandler(txtb_MouseLeftButtonDown);
     NavMenu.Children.Add(txtb);
     cbxProfitType.ItemsSource = Constant.ProfitTypeInfos;
     cbxProfitType.SelectedIndex = 0;
     cbxProfitType.SelectionChanged += new SelectionChangedEventHandler(cbxProfitType_SelectionChanged);
     BindProfitReportList(user.ID);
     BindedLst.Add(user.ID);
     BindProfitDetailList(user.UserId);
 }
Ejemplo n.º 3
0
        public void GetNetCashBalancePerFundByInvestorTest()
        {
            var factory = new TransactionFactory().WithInvestor(() => "Investor 1")
                          .WithFund(() => "Fund 1")
                          .WithPrice(() => 100)
                          .WithShares(() => 1)
                          .WithTransactionType(() => TransactionType.Sell);
            var transactionsForInvestor1 = factory.Build(3);

            transactionsForInvestor1[0].Fund = "Fund 2";

            var transactionsForInvestor2 = factory
                                           .WithInvestor(() => "Investor 2")
                                           .WithFund(() => "Fund 3")
                                           .WithShares(() => 1)
                                           .WithPrice(() => 100)
                                           .WithTransactionType(() => TransactionType.Sell)
                                           .Build(3);

            var allTransactions = new List <Transaction>();

            allTransactions.AddRange(transactionsForInvestor1);
            allTransactions.AddRange(transactionsForInvestor2);

            var subject = new ProfitReport(allTransactions);
            var profit  = subject.GetNetCashBalancePerFundByInvestor("Investor 1");

            profit.Should().ContainKey("Fund 1").And.ContainKey("Fund 2").And.NotContainKey("Fund 3");
            profit["Fund 1"].Should().Be(200);
            profit["Fund 2"].Should().Be(100);
        }
Ejemplo n.º 4
0
        public void ProfitReport_TwoValues_Output()
        {
            double price1 = 100;
            double price2 = 300;
            var    c      = new ProfitReport();

            Assert.AreEqual(200, c.GenerateProfitReport(price1, price2));
        }
Ejemplo n.º 5
0
        void PageDataLoaded()
        {
            if (_hybridWebView == null) {
                _hybridWebView = new HybridWebView (new SystemJsonSerializer());
                _hybridWebView.HorizontalOptions = LayoutOptions.FillAndExpand;
                _hybridWebView.VerticalOptions = LayoutOptions.FillAndExpand;

                Content = _hybridWebView;
            }

            var profitReportRazorView = new ProfitReport () { Model = PageModel.ProfitData };
            var html = profitReportRazorView.GenerateString ();
            _hybridWebView.LoadContent (html.Replace("\r\n", ""));
        }
        public async Task <ProfitReport> AnalyzeSales([ActivityTrigger] RegionData regionData)
        {
            logger.LogDebug($"Running sale analysis on {regionData.FileName}");

            IReadOnlyList <SaleInfo> saleInfos = await csvParser.ParseSaleData(regionData.DataCsv);

            var report = new ProfitReport
            {
                FileName         = regionData.FileName,
                CountriesProfits = salesAnalyzer.AnalyzeProfits(saleInfos)
            };

            logger.LogDebug($"Analysis complete for region {regionData.FileName}.");
            return(report);
        }
        void PageDataLoaded()
        {
            if (_hybridWebView == null)
            {
                _hybridWebView = new HybridWebView(new SystemJsonSerializer());
                _hybridWebView.HorizontalOptions = LayoutOptions.FillAndExpand;
                _hybridWebView.VerticalOptions   = LayoutOptions.FillAndExpand;

                Content = _hybridWebView;
            }

            var profitReportRazorView = new ProfitReport()
            {
                Model = PageModel.ProfitData
            };
            var html = profitReportRazorView.GenerateString();

            _hybridWebView.LoadContent(html.Replace("\r\n", ""));
        }
Ejemplo n.º 8
0
 public void srv_Profit_GetProfitReportCompleted(object sender, GetProfitReportCompletedEventArgs e)
 {
     gridLoading.Visibility = Visibility.Collapsed;
     currentPos = 0;
     obProfitReport = e.Result;
     if (obProfitReport.Count != 0)
     {
         RTotalSum = new ProfitReport();
         RTotalSum.UserID = "总合计";
         RTotalSum.BetMoney = obProfitReport.Sum(p => p.BetMoney);
         RTotalSum.MoneyIn = obProfitReport.Sum(p => p.MoneyIn);
         RTotalSum.MoneyOut = obProfitReport.Sum(p => p.MoneyOut);
         RTotalSum.PctMoney = obProfitReport.Sum(p => p.PctMoney);
         RTotalSum.ProfitLoss = obProfitReport.Sum(p => p.ProfitLoss);
         if (e.Result.Count < 18)
         {
             obProfitReport = e.Result;
             RPageSum = new ProfitReport();
             RPageSum.UserID = "本页合计";
             RPageSum.BetMoney = obProfitReport.Take(18).Sum(p => p.BetMoney);
             RPageSum.MoneyIn = obProfitReport.Take(18).Sum(p => p.MoneyIn);
             RPageSum.MoneyOut = obProfitReport.Take(18).Sum(p => p.MoneyOut);
             RPageSum.PctMoney = obProfitReport.Take(18).Sum(p => p.PctMoney);
             RPageSum.ProfitLoss = obProfitReport.Take(18).Sum(p => p.ProfitLoss);
             obProfitReport.Add(RPageSum);
             obProfitReport.Add(RTotalSum);
             currentPos = 0;
             PagedCollectionView pageView = new PagedCollectionView(obProfitReport);
             pageView.PageSize = 20;
             dpList.PageSize = 20;
             dpList.PageSize = 20;
             dpList.Source = pageView;
             dgList.ItemsSource = pageView;
         }
         else
         {
             int page = int.Parse(Math.Ceiling(double.Parse(e.Result.Count.ToString()) / 18).ToString());
             for (int i = 0; i < page; i++)
             {
                 int stayNum = e.Result.Count - (i * 20);
                 if (stayNum > 18)
                 {
                     RPageSum = new ProfitReport();
                     RPageSum.UserID = "本页合计";
                     RPageSum.BetMoney = obProfitReport.Skip(i * 20).Take(18).Sum(p => p.BetMoney);
                     RPageSum.MoneyIn = obProfitReport.Skip(i * 20).Take(18).Sum(p => p.MoneyIn);
                     RPageSum.MoneyOut = obProfitReport.Skip(i * 20).Take(18).Sum(p => p.MoneyOut);
                     RPageSum.PctMoney = obProfitReport.Skip(i * 20).Take(18).Sum(p => p.PctMoney);
                     RPageSum.ProfitLoss = obProfitReport.Skip(i * 20).Take(18).Sum(p => p.ProfitLoss);
                     obProfitReport.Insert(i * 20 + 18, RPageSum);
                     obProfitReport.Insert(i * 20 + 19, RTotalSum);
                 }
                 else
                 {
                     RPageSum = new ProfitReport();
                     RPageSum.UserID = "本页合计";
                     RPageSum.BetMoney = obProfitReport.Skip(i * 20).Take(stayNum).Sum(p => p.BetMoney);
                     RPageSum.MoneyIn = obProfitReport.Skip(i * 20).Take(stayNum).Sum(p => p.MoneyIn);
                     RPageSum.MoneyOut = obProfitReport.Skip(i * 20).Take(stayNum).Sum(p => p.MoneyOut);
                     RPageSum.PctMoney = obProfitReport.Skip(i * 20).Take(stayNum).Sum(p => p.PctMoney);
                     RPageSum.ProfitLoss = obProfitReport.Skip(i * 20).Take(stayNum).Sum(p => p.ProfitLoss);
                     obProfitReport.Insert(i * 20 + stayNum - 1, RPageSum);
                     obProfitReport.Insert(i * 20 + stayNum, RTotalSum);
                 }
             }
             currentPos = 0;
             PagedCollectionView pageView = new PagedCollectionView(obProfitReport);
             pageView.PageSize = 20;
             dpList.PageSize = 20;
             dpList.Source = pageView;
             dgList.ItemsSource = pageView;
         }
     }
     else
     {
         PagedCollectionView pageView = new PagedCollectionView(obProfitReport);
         pageView.PageSize = 20;
         dpList.PageSize = 20;
         dpList.Source = pageView;
         dgList.ItemsSource = pageView;
     }
 }