public HoldingViewModel BuildViewModel(HoldingData data)
        {
            var viewModel = _autoMapper.Map <HoldingData, HoldingViewModel>(data);

            var cost = _calculatorEngine.CalculateCost(viewModel.Shares, viewModel.Price, viewModel.Commission, viewModel.Tax, viewModel.Levy);

            viewModel.Cost           = cost;
            viewModel.BreakEvenPrice = _calculatorEngine.CalculateBreakEvenPrice(viewModel.Shares, viewModel.Price, viewModel.Commission, viewModel.Tax, viewModel.Levy);

            var profitPrice = _calculatorEngine.CalculateProfitPrice(viewModel.Shares, viewModel.Price, viewModel.Commission, viewModel.Tax, viewModel.Levy, 1 + (viewModel.Percentage / 100));

            viewModel.ProfitPrice = profitPrice;
            viewModel.Earnings    = _calculatorEngine.CalculateEarnings(viewModel.Shares, profitPrice, viewModel.Commission, cost, viewModel.Levy);

            return(viewModel);
        }
Example #2
0
        public Decimal GetTransactionPeriodValue(IList <TransactionData> data)
        {
            var result = (from item in data.Where(x => x.TransactionType == TransactionType.Sell)
                          let buyTransaction = (TransactionData)(data.FirstOrDefault(x => x.Id == item.SellTransactionId) ?? _transactionRepository.GetTransactionById(item.SellTransactionId))
                                               let buyCost = _calculatorEngine.CalculateCost(buyTransaction.Shares, buyTransaction.Price, buyTransaction.Commission, buyTransaction.Tax, buyTransaction.Levy)
                                                             let sellCost = _calculatorEngine.CalculateCost(item.Shares, item.Price, item.Commission, item.Tax, item.Levy)
                                                                            select sellCost - buyCost).Sum();

            result += (from item in data.Where(x => x.TransactionType == TransactionType.Dividend)
                       select _calculatorEngine.CalculateEarnings(item.Shares, item.Price, 0, 0, 0)).Sum();

            return(result);
        }
Example #3
0
        public IList <DashboardViewModel> BuildViewModels()
        {
            IList <TransactionData> data;

            try
            {
                data = _transactionRepository.GetCurrentHoldings();
            }
            catch
            {
                // Get from latest Json file
                data = _transactionFileWrapper.GetCurrentHoldings();
            }

            var viewModels    = new List <DashboardViewModel>();
            var currentPrices = _stockPriceRetriever.GetPrices(data);

            foreach (var item in data)
            {
                var viewModel = _autoMapper.Map <TransactionData, DashboardViewModel>(item);

                var profitPercentage = _calculatorEngine.CalculatePercentage(item.Percentage);
                var cost             = _calculatorEngine.CalculateCost(item.Shares, item.Price, item.Commission, item.Tax, item.Levy);
                var currentPrice     = currentPrices.FirstOrDefault(x => x.Code.Replace(".L", String.Empty) == item.Code);

                viewModel.Name = currentPrice.Name;

                viewModel.BreakEvenPrice = _calculatorEngine.CalculateBreakEvenPrice(item.Shares, item.Price,
                                                                                     item.Commission, item.Tax, item.Levy);
                viewModel.ProfitPrice = _calculatorEngine.CalculateProfitPrice(item.Shares, item.Price, item.Commission,
                                                                               item.Tax, item.Levy, profitPercentage);

                viewModel.CurrentPrice = currentPrice.Ask;

                viewModel.PercentageDifference = (viewModel.CurrentPrice - viewModel.BreakEvenPrice) /
                                                 viewModel.BreakEvenPrice;

                viewModel.Earnings = _calculatorEngine.CalculateEarnings(item.Shares, currentPrice.Ask, item.Commission,
                                                                         cost, item.Levy);

                viewModels.Add(viewModel);
            }

            return(viewModels);
        }
        private void CalculateButton_OnClick(object sender, RoutedEventArgs e)
        {
            var investment = Decimal.Parse(InvestmentTextBox.Text);
            var commission = Decimal.Parse(CommissionTextBox.Text);
            var tax        = Decimal.Parse(TaxTextBox.Text);
            var levy       = Decimal.Parse(LevyTextBox.Text);
            var price      = Decimal.Parse(PriceTextBox.Text);
            var percentage = 1 + (Decimal.Parse(ProfitTextBox.Text) / 100M);

            var shares      = _calculatorEngine.CalculateShares(investment, commission, tax, levy, price);
            var cost        = _calculatorEngine.CalculateCost(shares, price, commission, tax, levy);
            var profitPrice = _calculatorEngine.CalculateProfitPrice(shares, price, commission, tax, levy, percentage);

            SharesLabel.Content         = shares;
            CostLabel.Content           = cost;
            BreakEvenPriceLabel.Content = _calculatorEngine.CalculateBreakEvenPrice(shares, price, commission, tax, levy);
            ProfitPriceLabel.Content    = profitPrice;
            EarningsLabel.Content       = _calculatorEngine.CalculateEarnings(shares, profitPrice, commission, cost, levy);
        }
Example #5
0
        public ActionResult Index(CalculatorViewModel viewModel, String calculate)
        {
            if (String.IsNullOrEmpty(calculate))
            {
                var transactionViewModel = _autoMapper.Map <CalculatorViewModel, TransactionViewModel>(viewModel);

                transactionViewModel.Shares = _calculatorEngine.CalculateShares(viewModel.Investment, viewModel.Commission,
                                                                                viewModel.Tax,
                                                                                viewModel.Levy, viewModel.Price);

                return(View("../Transactions/Add", transactionViewModel));
            }
            else
            {
                viewModel.Shares = _calculatorEngine.CalculateShares(viewModel.Investment, viewModel.Commission,
                                                                     viewModel.Tax,
                                                                     viewModel.Levy, viewModel.Price);

                viewModel.Cost = _calculatorEngine.CalculateCost(viewModel.Shares, viewModel.Price, viewModel.Commission,
                                                                 viewModel.Tax, viewModel.Levy);

                viewModel.BreakEvenPrice = _calculatorEngine.CalculateBreakEvenPrice(viewModel.Shares, viewModel.Price,
                                                                                     viewModel.Commission, viewModel.Tax, viewModel.Levy);

                var profitPercentage = _calculatorEngine.CalculatePercentage(viewModel.Profit);

                viewModel.ProfitPrice = _calculatorEngine.CalculateProfitPrice(viewModel.Shares, viewModel.Price,
                                                                               viewModel.Commission, viewModel.Tax, viewModel.Levy, profitPercentage);

                viewModel.Earnings = _calculatorEngine.CalculateEarnings(viewModel.Shares, viewModel.ProfitPrice,
                                                                         viewModel.Commission, viewModel.Cost, viewModel.Levy);

                var viewResult = new ViewResult
                {
                    ViewName = "Index",
                    ViewData = { Model = viewModel }
                };

                viewResult.ViewBag.Message = "Investment Calculated";

                return(viewResult);
            }
        }