/// <summary> /// Get current purchases for the given security /// </summary> /// <returns></returns> public IEnumerable <SecurityPurchase> GetPurchases(Security security) { SecurityFifoQueue queue = null; if (queues.TryGetValue(security, out queue)) { foreach (SecurityPurchase p in queue.GetHoldings()) { yield return(p); } } }
/// <summary> /// Find the oldest holdings that still have UnitsRemaining, and decrement them by the /// number of units we are selling. This might have to sell from multiple SecurityPurchases /// in order to cover the requested number of units. If there are not enough units to cover /// the sale then we have a problem. /// </summary> /// <param name="dateSold">The date of the sale</param> /// <param name="units">The number of units sold</param> /// <param name="amount">The total amount we received from the sale</param> /// <returns></returns> public IEnumerable <SecuritySale> Sell(Security s, DateTime dateSold, decimal units, decimal amount) { SecurityFifoQueue queue; if (!queues.TryGetValue(s, out queue)) { queue = new SecurityFifoQueue() { Security = s, Account = this.Account }; queues[s] = queue; } return(queue.Sell(dateSold, units, amount)); }
/// <summary> /// Record an Add or Buy for a given security. /// </summary> ///<param name="s">The security we are buying</param> /// <param name="datePurchased">The date of the purchase</param> /// <param name="units">THe number of units purchased</param> /// <param name="costBasis">The cost basis for the purchase (usually what you paid for it including trading fees)</param> public void Buy(Security s, DateTime datePurchased, decimal units, decimal costBasis) { SecurityFifoQueue queue; if (!queues.TryGetValue(s, out queue)) { queue = new SecurityFifoQueue() { Security = s, Account = this.Account }; queues[s] = queue; } queue.Buy(datePurchased, units, costBasis); }