template <class numericType> numericType calculatePERatio<numericType>::operator() (const Stock<numericType>& stock) { if ((stock.getTickerPrice() == 0) || (stock.getLastDividend() == 0)) { return (numericType)0; } return (numericType)(stock.getTickerPrice()/stock.getLastDividend()); }
double StockUtil::PERatio(Stock stock, double marketPrice) { double div = stock.getLastDividend(); if(div == 0.0){return 0;} return marketPrice/div; }
double StockUtil::DividendYield(Stock stock, double marketPrice) { if(marketPrice == 0.0){return 0;} switch(stock.getStockType() ) { case COMMON: return (stock.getLastDividend() / marketPrice); case PREFFERED: return (stock.getFixedDividend() * stock.getParValue())/ marketPrice; default: return 0; } }