Exemplo n.º 1
0
        private void UpdateAccountHoldings(IStockDataWithDate stockData)
        {
            int     numberOfStocks          = stockData.StockDataCollection.Count();
            decimal amountAvailablePerStock = _account.GetAvailableBalanceForBuying((uint)numberOfStocks) / numberOfStocks;

            foreach (IStockDataModel data in stockData.StockDataCollection)
            {
                if (!_account.AccountHoldings.ContainsKey(data.Symbol))
                {
                    // determine quantity - equal weighting
                    uint quantity = (uint)(amountAvailablePerStock / (data.Open));
                    if (_account.CanBuy(quantity, data.Open))
                    {
                        _account.Buy(data.Symbol, quantity, data.Open);
                    }
                }

                _account.UpdateHolding(data);
            }

            AccountUpdatedEvent?.Invoke(this, new AccountUpdatedEventArgs(_account, stockData.Date));
        }