<?php
/**
* The company custom Repository holds
* convenience methods for generating
* common formulae using data in the database
*
* <code>
* $em->getCompanyById($id)->getEnterpriseValue();
* </code>
*/
class Company extends Repository
{
private $sharePrice;
private $numShares;
private $netIncome;
private $priceScale;
private $liquidity;
private $miscIncome;
private $balanceSheetCCE;
private $dividends;
public function __construct($entityName, EntityManager $entityManager) {
/**
* Set up the default column names to search for.
*/
$this->sharePrice = "sharePrice";
$this->numShares = "numShares";
$this->netIncome = "netIncome";
$this->priceScale = 1000;
$this->liquidity = "liquidity";
$this->miscIncome = "miscIncome";
$this->balanceSheetCCE = "balanceSheetCCE";
$this->dividends = "dividends";
/**
* marketCap
* Generate the marketCap like so
*
* @return Integer market cap
*/
$this->addMethod('marketCap', function ($dataObject) {
$sharePrice = $dataObject->get($this->sharePrice);
$numShares = $dataObject->get($this->numShares);
return $sharePrice * $numShares;
});
/**
* priceToEarningsRatio
* Generate the P/E Ratio
*
* @return Integer P/E Ratio
*/
$this->addMethod('priceToEarningsRatio', function ($dataObject) {
$sharePrice = $dataObject->get($this->sharePrice);
$numShares = $dataObject->get($this->numShares);
$netIncome = $dataObject->get($this->netIncome);
return ($sharePrice * $numShares) / ($netIncome * $this->priceScale);
});
/**
* enterpriseValue
* Generate Enterprise Value
*
* @return Integer Enterprise Value
*/
$this->addMethod('enterpriseValue', function ($dataObject) {
$sharePrice = $dataObject->get($this->sharePrice);
$numShares = $dataObject->get($this->numShares);
$liquidity = $dataObject->get($this->liquidity);
$miscIncome = $dataObject->get($this->miscIncome);
$balanceSheetCCE = $dataObject->get($this->balanceSheetCCE);
return ($sharePrice * $numShares) + (($liquidity + $miscIncome - $balanceSheetCCE) * $this->priceScale);
});
/**
* dividendYield
* Generate the Dividend Yield
*
* @return Integer Dividend Yield
*/
$this->addMethod('dividendYield', function ($dataObject) {
$sharePrice = $dataObject->get($this->sharePrice);
$numShares = $dataObject->get($this->numShares);
$dividends = $dataObject->get($this->dividends);
return ($dividends / $numShares) / ($sharePrice * 100);
});
parent::__construct();
}
}