public Trade(Stock stock, DateTime tradeTime, decimal quantity, TradeAction action, decimal price) { Stock = stock; TradeTime = tradeTime; Quantity = quantity; Action = action; Price = price; }
/// <summary> /// Calculates share dividend. /// </summary> /// <param name="stock">Stock for dividend calculation</param> /// <param name="price">Stock price</param> /// <returns>Stock dividend</returns> public static decimal CalculateDividend(Stock stock, decimal price) { if (stock.Type == StockType.Common) { return CalculateDividendYieldCommon(stock.LastDividend, price); } else { return CalculateDividentYieldPreffered(stock.FixedDividend, stock.ParValue, price); } }
public static List<Stock> getStocks(){ List<Stock> listSotck = new List<Stock>(); for (int i = 0; i <= 4; i++) { Stock newStock = new Stock(); newStock.symbol = stockData[i, 0]; newStock.type = stockData[i, 1]; newStock.lastDividend = int.Parse(stockData[i, 2]); if (stockData[i, 3] == null) newStock.fixedDividend = 0; else newStock.fixedDividend = Double.Parse(stockData[i, 3]); newStock.parValue = int.Parse(stockData[i, 4]); listSotck.Add(newStock); } return listSotck; }
/// <summary> /// Calculates share price based on previous trade on stock market. /// </summary> /// <param name="stock">Stock for calcuation</param> /// <param name="trades">All performed trades on stock marked.</param> /// <returns>Atock price for selected stock</returns> public static decimal CalculateStockPrice(Stock stock, List<Trade> trades) { var stockTrades = trades.Where(t => t.Stock == stock).ToList(); return stockTrades.Sum(t => t.Price * t.Quantity) / stockTrades.Sum(t => t.Quantity); }
/// <summary> /// Calculates P/E ration of selected stock. /// </summary> /// <param name="stock">Stock for calculation</param> /// <param name="price">Stock price</param> /// <returns>P/E ration of selected stock.</returns> public static decimal CalculatePeRatio(Stock stock, decimal price) { return CalculatePeRatio(stock.LastDividend, price); }