コード例 #1
0
 public Trade(Stock stock, DateTime tradeTime, decimal quantity, TradeAction action, decimal price)
 {
     Stock = stock;
     TradeTime = tradeTime;
     Quantity = quantity;
     Action = action;
     Price = price;
 }
コード例 #2
0
 /// <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);
     }
 }
コード例 #3
0
        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;
             
        }
コード例 #4
0
 /// <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);
 }
コード例 #5
0
 /// <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);
 }