Ejemplo n.º 1
0
        public void SellShares(Company c, int amountToSell)
        {
            var itemIndex     = Portfolio.FindIndex(x => x.Name == c.Name);
            int currentShares = Portfolio.ElementAt(itemIndex).Shares;

            if (currentShares == amountToSell)
            {
                Portfolio.RemoveAt(itemIndex);
            }
            else
            {
                Portfolio.ElementAt(itemIndex).Shares -= amountToSell;
            }
        }
Ejemplo n.º 2
0
        public void AddToPortfolio(Company c)
        {
            var itemIndex = Portfolio.FindIndex(x => x.Name == c.Name);

            if (itemIndex != -1)
            {
                var    company       = Portfolio.ElementAt(itemIndex);
                int    currentShares = company.Shares;
                double currentValue  = company.Value;
                int    newShares     = c.Shares;
                double newPrice      = c.Value;
                company.Shares += c.Shares;
                company.Value   = Math.Round(calcNewValue(currentValue, newPrice, currentShares, newShares, (currentShares + newShares)), 2, MidpointRounding.AwayFromZero);
            }
            else
            {
                Portfolio.Add(c);
            }
        }