Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
94 / 94 |
|
100.00% |
88 / 88 |
CRAP | |
100.00% |
1 / 1 |
| FinanceFormulas | |
100.00% |
94 / 94 |
|
100.00% |
88 / 88 |
91 | |
100.00% |
1 / 1 |
| __construct | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| getAnnualPercentageYield | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getStateAnnualInterestRateOfAPY | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getFutureValueOfAnnuity | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getNumberOfPeriodsOfFVA | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getPeriodicPaymentOfFVA | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getFutureValueOfAnnuityConinuousCompounding | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getCashFlowOfFVACC | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getTimeOfFVACC | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getAnnuityPaymentPV | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getNumberOfAPPV | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getPresentValueOfAPPV | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getAnnuityPaymentFV | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getNumberOfAPFV | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getFutureValueOfAPFV | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getAnnutiyPaymentFactorPV | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getNumberOfAPFPV | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getPresentValueOfAnnuity | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getNumberOfPeriodsOfPVA | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getPeriodicPaymentOfPVA | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getPresentValueAnnuityFactor | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getPeriodsOfPVAF | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getPresentValueOfAnnuityDue | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getPeriodicPaymentOfPVAD | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getPeriodsOfPVAD | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getFutureValueOfAnnuityDue | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getPeriodicPaymentOfFVAD | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getPeriodsOfFVAD | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getAssetToSalesRatio | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getAssetTurnoverRatio | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getAverageCollectionPeriod | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getReceivablesTurnover | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getCompoundInterest | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getPrincipalOfCompundInterest | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getPeriodsOfCompundInterest | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getContinuousCompounding | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getPrincipalOfContinuousCompounding | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getPeriodsOfContinuousCompounding | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getRateOfContinuousCompounding | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getCurrentRatio | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getDaysInInventory | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getDebtCoverageRatio | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getDebtRatio | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getDebtToEquityRatio | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getDebtToIncomeRatio | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getDiscountedPaybackPeriod | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getDoublingTime | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getDoublingRate | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getDoublingTimeContinuousCompounding | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getDoublingContinuousCompoundingRate | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getEquivalentAnnualAnnuity | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getPeriodsOfEAA | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getNetPresentValueOfEAA | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getFreeCashFlowToEquity | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getFreeCashFlowToFirm | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getFutureValue | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getFutureValueContinuousCompounding | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getFutureValueFactor | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getGeometricMeanReturn | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getGrowingAnnuityFV | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getGrowingAnnuityPaymentPV | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getGrowingAnnuityPaymentFV | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getGrowingAnnuityPV | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getGrowingPerpetuityPV | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getInterestCoverageRatio | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getInventoryTurnoverRatio | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getNetPresentValue | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
3 | |||
| getNetProfitMargin | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getNetWorkingCapital | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getNumberOfPeriodsPVFV | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getPaybackPeriod | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getPresentValueOfPerpetuity | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getPresentValue | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getPresentValueContinuousCompounding | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getPresentValueFactor | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getQuickRatio | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getRateOfInflation | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getRealRateOfReturn | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getReceivablesTurnoverRatio | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getRetentionRatio | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getReturnOnAssets | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getReturnOnEquity | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getReturnOnInvestment | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getSimpleInterest | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getSimpleInterestRate | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getSimpleInterestPrincipal | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getSimpleInterestTime | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getRelativeMarketShareByShare | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getRelativeMarketShareBySales | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Jingga |
| 4 | * |
| 5 | * PHP Version 8.1 |
| 6 | * |
| 7 | * @package phpOMS\Business\Finance |
| 8 | * @copyright Dennis Eichhorn |
| 9 | * @license OMS License 2.0 |
| 10 | * @version 1.0.0 |
| 11 | * @link https://jingga.app |
| 12 | */ |
| 13 | declare(strict_types=1); |
| 14 | |
| 15 | namespace phpOMS\Business\Finance; |
| 16 | |
| 17 | use phpOMS\Math\Statistic\Average; |
| 18 | |
| 19 | /** |
| 20 | * Finance class. |
| 21 | * |
| 22 | * @package phpOMS\Business\Finance |
| 23 | * @license OMS License 2.0 |
| 24 | * @link https://jingga.app |
| 25 | * @since 1.0.0 |
| 26 | * |
| 27 | * @SuppressWarnings(PHPMD.CamelCaseParameterName) |
| 28 | * @SuppressWarnings(PHPMD.CamelCaseVariableName) |
| 29 | */ |
| 30 | final class FinanceFormulas |
| 31 | { |
| 32 | /** |
| 33 | * Constructor |
| 34 | * |
| 35 | * @since 1.0.0 |
| 36 | * @codeCoverageIgnore |
| 37 | */ |
| 38 | private function __construct() |
| 39 | { |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Annual Percentage Yield |
| 44 | * |
| 45 | * The annual percentage yield (APY) calculates the yield taking compounding |
| 46 | * into consideration. |
| 47 | * |
| 48 | * @latex APY = \left(1+ \frac{r}{n}\right)^{n}-1 |
| 49 | * |
| 50 | * @param float $r Stated annual interest rate |
| 51 | * @param int $n number of times compounded |
| 52 | * |
| 53 | * @return float Returns the APY |
| 54 | * |
| 55 | * @since 1.0.0 |
| 56 | */ |
| 57 | public static function getAnnualPercentageYield(float $r, int $n) : float |
| 58 | { |
| 59 | return \pow(1 + $r / $n, $n) - 1; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Annual Percentage Yield |
| 64 | * |
| 65 | * @latex r = \left(\left(APY + 1\right)^{\frac{1}{n}} - 1\right) \cdot n |
| 66 | * |
| 67 | * @param float $apy Annual percentage yield |
| 68 | * @param int $n Number of times compounded |
| 69 | * |
| 70 | * @return float |
| 71 | * |
| 72 | * @since 1.0.0 |
| 73 | */ |
| 74 | public static function getStateAnnualInterestRateOfAPY(float $apy, int $n) : float |
| 75 | { |
| 76 | return (\pow($apy + 1, 1 / $n) - 1) * $n; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Annuity - Future Value |
| 81 | * |
| 82 | * @param float $P Periodic payment |
| 83 | * @param float $r Stated annual interest rate |
| 84 | * @param int $n Number of periods |
| 85 | * |
| 86 | * @return float |
| 87 | * |
| 88 | * @since 1.0.0 |
| 89 | */ |
| 90 | public static function getFutureValueOfAnnuity(float $P, float $r, int $n) : float |
| 91 | { |
| 92 | return $P * (\pow(1 + $r, $n) - 1) / $r; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Annuity - Future Value |
| 97 | * |
| 98 | * @param float $fva Future value annuity |
| 99 | * @param float $P Periodic payment |
| 100 | * @param float $r Stated annual interest rate |
| 101 | * |
| 102 | * @return int |
| 103 | * |
| 104 | * @since 1.0.0 |
| 105 | */ |
| 106 | public static function getNumberOfPeriodsOfFVA(float $fva, float $P, float $r) : int |
| 107 | { |
| 108 | return (int) \round(\log($fva / $P * $r + 1) / \log(1 + $r)); |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Future Value |
| 113 | * |
| 114 | * @param float $fva Future value annuity |
| 115 | * @param float $r Stated annual interest rate |
| 116 | * @param int $n Number of periods |
| 117 | * |
| 118 | * @return float |
| 119 | * |
| 120 | * @since 1.0.0 |
| 121 | */ |
| 122 | public static function getPeriodicPaymentOfFVA(float $fva, float $r, int $n) : float |
| 123 | { |
| 124 | return $fva / ((\pow(1 + $r, $n) - 1) / $r); |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Annuity - Future Value w/ Continuous Compounding |
| 129 | * |
| 130 | * @param float $cf Cach flow |
| 131 | * @param float $r Rate |
| 132 | * @param int $t Time |
| 133 | * |
| 134 | * @return float |
| 135 | * |
| 136 | * @since 1.0.0 |
| 137 | */ |
| 138 | public static function getFutureValueOfAnnuityConinuousCompounding(float $cf, float $r, int $t) : float |
| 139 | { |
| 140 | return $cf * (\exp($r * $t) - 1) / (\exp($r) - 1); |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Annuity - Future Value w/ Continuous Compounding |
| 145 | * |
| 146 | * @param float $fvacc Future value annuity continuous compoinding |
| 147 | * @param float $r Rate |
| 148 | * @param int $t Time |
| 149 | * |
| 150 | * @return float |
| 151 | * |
| 152 | * @since 1.0.0 |
| 153 | */ |
| 154 | public static function getCashFlowOfFVACC(float $fvacc, float $r, int $t) : float |
| 155 | { |
| 156 | return $fvacc / ((\exp($r * $t) - 1) / (\exp($r) - 1)); |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * Annuity - Future Value w/ Continuous Compounding |
| 161 | * |
| 162 | * @param float $fvacc Future value annuity continuous compoinding |
| 163 | * @param float $cf Cach flow |
| 164 | * @param float $r Rate |
| 165 | * |
| 166 | * @return int |
| 167 | * |
| 168 | * @since 1.0.0 |
| 169 | */ |
| 170 | public static function getTimeOfFVACC(float $fvacc, float $cf, float $r) : int |
| 171 | { |
| 172 | return (int) \round(\log($fvacc / $cf * (\exp($r) - 1) + 1) / $r); |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Annuity - Payment (PV) |
| 177 | * |
| 178 | * @param float $pv Present value |
| 179 | * @param float $r Rate per period |
| 180 | * @param int $n Number of periods |
| 181 | * |
| 182 | * @return float |
| 183 | * |
| 184 | * @since 1.0.0 |
| 185 | */ |
| 186 | public static function getAnnuityPaymentPV(float $pv, float $r, int $n) : float |
| 187 | { |
| 188 | return $r * $pv / (1 - \pow(1 + $r, -$n)); |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * Annuity - Payment (PV) |
| 193 | * |
| 194 | * @param float $p Payment |
| 195 | * @param float $pv Present value |
| 196 | * @param float $r Rate per period |
| 197 | * |
| 198 | * @return int |
| 199 | * |
| 200 | * @since 1.0.0 |
| 201 | */ |
| 202 | public static function getNumberOfAPPV(float $p, float $pv, float $r) : int |
| 203 | { |
| 204 | return (int) \round(-\log(-($r * $pv / $p - 1)) / \log(1 + $r)); |
| 205 | } |
| 206 | |
| 207 | /** |
| 208 | * Annuity - Payment (PV) |
| 209 | * |
| 210 | * @param float $p Payment |
| 211 | * @param float $r Rate per period |
| 212 | * @param int $n Number of periods |
| 213 | * |
| 214 | * @return float |
| 215 | * |
| 216 | * @since 1.0.0 |
| 217 | */ |
| 218 | public static function getPresentValueOfAPPV(float $p, float $r, int $n) : float |
| 219 | { |
| 220 | return $p / $r * (1 - \pow(1 + $r, -$n)); |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * Annuity - Payment (FV) |
| 225 | * |
| 226 | * @param float $fv Present value |
| 227 | * @param float $r Rate per period |
| 228 | * @param int $n Number of periods |
| 229 | * |
| 230 | * @return float |
| 231 | * |
| 232 | * @since 1.0.0 |
| 233 | */ |
| 234 | public static function getAnnuityPaymentFV(float $fv, float $r, int $n) : float |
| 235 | { |
| 236 | return $r * $fv / (\pow(1 + $r, $n) - 1); |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * Annuity - Payment (FV) |
| 241 | * |
| 242 | * @param float $p Payment |
| 243 | * @param float $fv Present value |
| 244 | * @param float $r Rate per period |
| 245 | * |
| 246 | * @return int |
| 247 | * |
| 248 | * @since 1.0.0 |
| 249 | */ |
| 250 | public static function getNumberOfAPFV(float $p, float $fv, float $r) : int |
| 251 | { |
| 252 | return (int) \round(\log($fv * $r / $p + 1) / \log(1 + $r)); |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * Annuity - Payment (FV) |
| 257 | * |
| 258 | * @param float $p Payment |
| 259 | * @param float $r Present value |
| 260 | * @param int $n Rate per period |
| 261 | * |
| 262 | * @return float |
| 263 | * |
| 264 | * @since 1.0.0 |
| 265 | */ |
| 266 | public static function getFutureValueOfAPFV(float $p, float $r, int $n) : float |
| 267 | { |
| 268 | return $p / $r * (\pow(1 + $r, $n) - 1); |
| 269 | } |
| 270 | |
| 271 | /** |
| 272 | * Annuity - Payment Factor (PV) |
| 273 | * |
| 274 | * @param float $r Rate per period |
| 275 | * @param int $n Number of periods |
| 276 | * |
| 277 | * @return float |
| 278 | * |
| 279 | * @since 1.0.0 |
| 280 | */ |
| 281 | public static function getAnnutiyPaymentFactorPV(float $r, int $n) : float |
| 282 | { |
| 283 | return $r / (1 - \pow(1 + $r, -$n)); |
| 284 | } |
| 285 | |
| 286 | /** |
| 287 | * Annuity - Payment Factor (PV) |
| 288 | * |
| 289 | * @param float $p Payment factor |
| 290 | * @param float $r Rate per period |
| 291 | * |
| 292 | * @return int Returns the PV |
| 293 | * |
| 294 | * @since 1.0.0 |
| 295 | */ |
| 296 | public static function getNumberOfAPFPV(float $p, float $r) : int |
| 297 | { |
| 298 | return (int) \round(-\log(-($r / $p - 1)) / \log(1 + $r)); |
| 299 | } |
| 300 | |
| 301 | /** |
| 302 | * Annuity - Present Value |
| 303 | * |
| 304 | * @param float $P Periodic payment |
| 305 | * @param float $r Stated annual interest rate |
| 306 | * @param int $n Number of periods |
| 307 | * |
| 308 | * @return float |
| 309 | * |
| 310 | * @since 1.0.0 |
| 311 | */ |
| 312 | public static function getPresentValueOfAnnuity(float $P, float $r, int $n) : float |
| 313 | { |
| 314 | return $P * (1 - \pow(1 + $r, -$n)) / $r; |
| 315 | } |
| 316 | |
| 317 | /** |
| 318 | * Annuity - Present Value |
| 319 | * |
| 320 | * @param float $pva Future value annuity |
| 321 | * @param float $P Periodic payment |
| 322 | * @param float $r Stated annual interest rate |
| 323 | * |
| 324 | * @return int |
| 325 | * |
| 326 | * @since 1.0.0 |
| 327 | */ |
| 328 | public static function getNumberOfPeriodsOfPVA(float $pva, float $P, float $r) : int |
| 329 | { |
| 330 | return (int) \round(-\log(-($pva / $P * $r - 1)) / \log(1 + $r)); |
| 331 | } |
| 332 | |
| 333 | /** |
| 334 | * Annuity - Present Value |
| 335 | * |
| 336 | * @param float $pva Future value annuity |
| 337 | * @param float $r Stated annual interest rate |
| 338 | * @param int $n Number of periods |
| 339 | * |
| 340 | * @return float |
| 341 | * |
| 342 | * @since 1.0.0 |
| 343 | */ |
| 344 | public static function getPeriodicPaymentOfPVA(float $pva, float $r, int $n) : float |
| 345 | { |
| 346 | return $pva / ((1 - \pow(1 + $r, -$n)) / $r); |
| 347 | } |
| 348 | |
| 349 | /** |
| 350 | * Annuity - PV Factor |
| 351 | * |
| 352 | * @param float $r Rate per period |
| 353 | * @param int $n Number of periods |
| 354 | * |
| 355 | * @return float |
| 356 | * |
| 357 | * @since 1.0.0 |
| 358 | */ |
| 359 | public static function getPresentValueAnnuityFactor(float $r, int $n) : float |
| 360 | { |
| 361 | return (1 - \pow(1 + $r, -$n)) / $r; |
| 362 | } |
| 363 | |
| 364 | /** |
| 365 | * Annuity - PV Factor |
| 366 | * |
| 367 | * @param float $p Payment factor |
| 368 | * @param float $r Rete per period |
| 369 | * |
| 370 | * @return int |
| 371 | * |
| 372 | * @since 1.0.0 |
| 373 | */ |
| 374 | public static function getPeriodsOfPVAF(float $p, float $r) : int |
| 375 | { |
| 376 | return (int) \round(-\log(-($p * $r - 1)) / \log(1 + $r)); |
| 377 | } |
| 378 | |
| 379 | /** |
| 380 | * Annuity Due - Present Value |
| 381 | * |
| 382 | * @param float $P Periodic payment |
| 383 | * @param float $r Rate per period |
| 384 | * @param int $n Number of periods |
| 385 | * |
| 386 | * @return float |
| 387 | * |
| 388 | * @since 1.0.0 |
| 389 | */ |
| 390 | public static function getPresentValueOfAnnuityDue(float $P, float $r, int $n) : float |
| 391 | { |
| 392 | return $P + $P * ((1 - \pow(1 + $r, -($n - 1))) / $r); |
| 393 | } |
| 394 | |
| 395 | /** |
| 396 | * Annuity Due - Present Value |
| 397 | * |
| 398 | * Using alternative formula for PV |
| 399 | * |
| 400 | * @param float $PV Present value |
| 401 | * @param float $r Rate per period |
| 402 | * @param int $n Number of periods |
| 403 | * |
| 404 | * @return float |
| 405 | * |
| 406 | * @since 1.0.0 |
| 407 | */ |
| 408 | public static function getPeriodicPaymentOfPVAD(float $PV, float $r, int $n) : float |
| 409 | { |
| 410 | return $PV * $r / (1 - \pow(1 + $r, -$n)) * 1 / (1 + $r); |
| 411 | } |
| 412 | |
| 413 | /** |
| 414 | * Annuity Due - Present Value |
| 415 | * |
| 416 | * @param float $PV Present value |
| 417 | * @param float $P Periodic payment |
| 418 | * @param float $r Rate per period |
| 419 | * |
| 420 | * @return int |
| 421 | * |
| 422 | * @since 1.0.0 |
| 423 | */ |
| 424 | public static function getPeriodsOfPVAD(float $PV, float $P, float $r) : int |
| 425 | { |
| 426 | return (int) \round(-(\log(-($PV - $P) / $P * $r + 1) / \log(1 + $r) - 1)); |
| 427 | } |
| 428 | |
| 429 | /** |
| 430 | * Annuity Due - Future Value |
| 431 | * |
| 432 | * @param float $P Periodic payment |
| 433 | * @param float $r Rate per period |
| 434 | * @param int $n Number of periods |
| 435 | * |
| 436 | * @return float |
| 437 | * |
| 438 | * @since 1.0.0 |
| 439 | */ |
| 440 | public static function getFutureValueOfAnnuityDue(float $P, float $r, int $n) : float |
| 441 | { |
| 442 | return (1 + $r) * $P * (\pow(1 + $r, $n) - 1) / $r; |
| 443 | } |
| 444 | |
| 445 | /** |
| 446 | * Annuity Due - Future Value |
| 447 | * |
| 448 | * @param float $FV Future value |
| 449 | * @param float $r Rate per period |
| 450 | * @param int $n Number of periods |
| 451 | * |
| 452 | * @return float |
| 453 | * |
| 454 | * @since 1.0.0 |
| 455 | */ |
| 456 | public static function getPeriodicPaymentOfFVAD(float $FV, float $r, int $n) : float |
| 457 | { |
| 458 | return $FV / ((1 + $r) * ((\pow(1 + $r, $n) - 1) / $r)); |
| 459 | } |
| 460 | |
| 461 | /** |
| 462 | * Annuity Due - Future Value |
| 463 | * |
| 464 | * @param float $FV Future value |
| 465 | * @param float $P Periodic payment |
| 466 | * @param float $r Rate per period |
| 467 | * |
| 468 | * @return int |
| 469 | * |
| 470 | * @since 1.0.0 |
| 471 | */ |
| 472 | public static function getPeriodsOfFVAD(float $FV, float $P, float $r) : int |
| 473 | { |
| 474 | return (int) \round(\log($FV / (1 + $r) / $P * $r + 1) / \log(1 + $r)); |
| 475 | } |
| 476 | |
| 477 | /** |
| 478 | * Asset to Sales Ratio |
| 479 | * |
| 480 | * @param float $assets Assets |
| 481 | * @param float $revenue Revenue |
| 482 | * |
| 483 | * @return float |
| 484 | * |
| 485 | * @since 1.0.0 |
| 486 | */ |
| 487 | public static function getAssetToSalesRatio(float $assets, float $revenue) : float |
| 488 | { |
| 489 | return $assets / $revenue; |
| 490 | } |
| 491 | |
| 492 | /** |
| 493 | * Asset Turnover Ratio |
| 494 | * |
| 495 | * @param float $assets Assets |
| 496 | * @param float $revenue Revenue |
| 497 | * |
| 498 | * @return float |
| 499 | * |
| 500 | * @since 1.0.0 |
| 501 | */ |
| 502 | public static function getAssetTurnoverRatio(float $assets, float $revenue) : float |
| 503 | { |
| 504 | return $revenue / $assets; |
| 505 | } |
| 506 | |
| 507 | /** |
| 508 | * Average Collection Period |
| 509 | * |
| 510 | * @param float $receivables Receivables turnover (use getReceivablesTurnover) |
| 511 | * @param int $period Period |
| 512 | * |
| 513 | * @return float |
| 514 | * |
| 515 | * @since 1.0.0 |
| 516 | */ |
| 517 | public static function getAverageCollectionPeriod(float $receivables, int $period = 365) : float |
| 518 | { |
| 519 | return $period / $receivables; |
| 520 | } |
| 521 | |
| 522 | /** |
| 523 | * Receivables Turnover |
| 524 | * |
| 525 | * @param float $sales Sales in period |
| 526 | * @param float $receivables Avg. account receivables |
| 527 | * |
| 528 | * @return float |
| 529 | * |
| 530 | * @since 1.0.0 |
| 531 | */ |
| 532 | public static function getReceivablesTurnover(float $sales, float $receivables) : float |
| 533 | { |
| 534 | return $sales / $receivables; |
| 535 | } |
| 536 | |
| 537 | /** |
| 538 | * Compound Interest |
| 539 | * |
| 540 | * @param float $P Principal |
| 541 | * @param float $r Rate per period |
| 542 | * @param int $n Number of periods |
| 543 | * |
| 544 | * @return float |
| 545 | * |
| 546 | * @since 1.0.0 |
| 547 | */ |
| 548 | public static function getCompoundInterest(float $P, float $r, int $n) : float |
| 549 | { |
| 550 | return $P * (\pow(1 + $r, $n) - 1); |
| 551 | } |
| 552 | |
| 553 | /** |
| 554 | * Principal of compound interest |
| 555 | * |
| 556 | * @param float $C Compound interest |
| 557 | * @param float $r Rate per period |
| 558 | * @param int $n Number of periods |
| 559 | * |
| 560 | * @return float |
| 561 | * |
| 562 | * @since 1.0.0 |
| 563 | */ |
| 564 | public static function getPrincipalOfCompundInterest(float $C, float $r, int $n) : float |
| 565 | { |
| 566 | return $C / (\pow(1 + $r, $n) - 1); |
| 567 | } |
| 568 | |
| 569 | /** |
| 570 | * Principal of compound interest |
| 571 | * |
| 572 | * @param float $P Principal |
| 573 | * @param float $C Compound interest |
| 574 | * @param float $r Rate per period |
| 575 | * |
| 576 | * @return float |
| 577 | * |
| 578 | * @since 1.0.0 |
| 579 | */ |
| 580 | public static function getPeriodsOfCompundInterest(float $P, float $C, float $r) : float |
| 581 | { |
| 582 | return \log($C / $P + 1) / \log(1 + $r); |
| 583 | } |
| 584 | |
| 585 | /** |
| 586 | * Continuous Compounding |
| 587 | * |
| 588 | * @param float $P Principal |
| 589 | * @param float $r Rate per period |
| 590 | * @param int $t Time |
| 591 | * |
| 592 | * @return float |
| 593 | * |
| 594 | * @since 1.0.0 |
| 595 | */ |
| 596 | public static function getContinuousCompounding(float $P, float $r, int $t) : float |
| 597 | { |
| 598 | return $P * \exp($r * $t); |
| 599 | } |
| 600 | |
| 601 | /** |
| 602 | * Continuous Compounding |
| 603 | * |
| 604 | * @param float $C Compounding |
| 605 | * @param float $r Rate per period |
| 606 | * @param int $t Time |
| 607 | * |
| 608 | * @return float |
| 609 | * |
| 610 | * @since 1.0.0 |
| 611 | */ |
| 612 | public static function getPrincipalOfContinuousCompounding(float $C, float $r, int $t) : float |
| 613 | { |
| 614 | return $C / \exp($r * $t); |
| 615 | } |
| 616 | |
| 617 | /** |
| 618 | * Continuous Compounding |
| 619 | * |
| 620 | * @param float $P Principal |
| 621 | * @param float $C Compounding |
| 622 | * @param float $r Rate per period |
| 623 | * |
| 624 | * @return float |
| 625 | * |
| 626 | * @since 1.0.0 |
| 627 | */ |
| 628 | public static function getPeriodsOfContinuousCompounding(float $P, float $C, float $r) : float |
| 629 | { |
| 630 | return \log($C / $P) / $r; |
| 631 | } |
| 632 | |
| 633 | /** |
| 634 | * Continuous Compounding |
| 635 | * |
| 636 | * @param float $P Principal |
| 637 | * @param float $C Compounding |
| 638 | * @param float $t Time |
| 639 | * |
| 640 | * @return float |
| 641 | * |
| 642 | * @since 1.0.0 |
| 643 | */ |
| 644 | public static function getRateOfContinuousCompounding(float $P, float $C, float $t) : float |
| 645 | { |
| 646 | return \log($C / $P) / $t; |
| 647 | } |
| 648 | |
| 649 | /** |
| 650 | * Current Ratio |
| 651 | * |
| 652 | * @param float $assets Assets |
| 653 | * @param float $liabilities Liabilities |
| 654 | * |
| 655 | * @return float |
| 656 | * |
| 657 | * @since 1.0.0 |
| 658 | */ |
| 659 | public static function getCurrentRatio(float $assets, float $liabilities) : float |
| 660 | { |
| 661 | return $assets / $liabilities; |
| 662 | } |
| 663 | |
| 664 | /** |
| 665 | * Days in Inventory |
| 666 | * |
| 667 | * @param float $inventory Inventory turnover |
| 668 | * |
| 669 | * @return float |
| 670 | * |
| 671 | * @since 1.0.0 |
| 672 | */ |
| 673 | public static function getDaysInInventory(float $inventory) : float |
| 674 | { |
| 675 | return 365 / $inventory; |
| 676 | } |
| 677 | |
| 678 | /** |
| 679 | * Debt Coverage Ratio |
| 680 | * |
| 681 | * @param float $income Net operating income |
| 682 | * @param float $service Debt service |
| 683 | * |
| 684 | * @return float |
| 685 | * |
| 686 | * @since 1.0.0 |
| 687 | */ |
| 688 | public static function getDebtCoverageRatio(float $income, float $service) : float |
| 689 | { |
| 690 | return $income / $service; |
| 691 | } |
| 692 | |
| 693 | /** |
| 694 | * Debt Ratio |
| 695 | * |
| 696 | * @param float $liabilities Total liabilities |
| 697 | * @param float $assets Total assets |
| 698 | * |
| 699 | * @return float |
| 700 | * |
| 701 | * @since 1.0.0 |
| 702 | */ |
| 703 | public static function getDebtRatio(float $liabilities, float $assets) : float |
| 704 | { |
| 705 | return $liabilities / $assets; |
| 706 | } |
| 707 | |
| 708 | /** |
| 709 | * Debt to Equity Ratio (D/E) |
| 710 | * |
| 711 | * @param float $liabilities Total liabilities |
| 712 | * @param float $equity Total assets |
| 713 | * |
| 714 | * @return float |
| 715 | * |
| 716 | * @since 1.0.0 |
| 717 | */ |
| 718 | public static function getDebtToEquityRatio(float $liabilities, float $equity) : float |
| 719 | { |
| 720 | return $liabilities / $equity; |
| 721 | } |
| 722 | |
| 723 | /** |
| 724 | * Debt to Income Ratio (D/I) |
| 725 | * |
| 726 | * @param float $payments Periodic payments |
| 727 | * @param float $income Periodic income |
| 728 | * |
| 729 | * @return float |
| 730 | * |
| 731 | * @since 1.0.0 |
| 732 | */ |
| 733 | public static function getDebtToIncomeRatio(float $payments, float $income) : float |
| 734 | { |
| 735 | return $payments / $income; |
| 736 | } |
| 737 | |
| 738 | /** |
| 739 | * Discounted Payback Period |
| 740 | * |
| 741 | * @param float $CF Periodic cash flow |
| 742 | * @param float $O1 Initial Investment (Outflow) |
| 743 | * @param float $r Rate |
| 744 | * |
| 745 | * @return float |
| 746 | * |
| 747 | * @since 1.0.0 |
| 748 | */ |
| 749 | public static function getDiscountedPaybackPeriod(float $CF, float $O1, float $r) : float |
| 750 | { |
| 751 | return \log(1 / (1 - $O1 * $r / $CF)) / \log(1 + $r); |
| 752 | } |
| 753 | |
| 754 | /** |
| 755 | * Doubling Time |
| 756 | * |
| 757 | * @param float $r Rate of return |
| 758 | * |
| 759 | * @return float |
| 760 | * |
| 761 | * @since 1.0.0 |
| 762 | */ |
| 763 | public static function getDoublingTime(float $r) : float |
| 764 | { |
| 765 | return \log(2) / \log(1 + $r); |
| 766 | } |
| 767 | |
| 768 | /** |
| 769 | * Get rate to dobule |
| 770 | * |
| 771 | * @param float $t Time in which to double investment |
| 772 | * |
| 773 | * @return float |
| 774 | * |
| 775 | * @since 1.0.0 |
| 776 | */ |
| 777 | public static function getDoublingRate(float $t) : float |
| 778 | { |
| 779 | return \exp(\log(2) / $t) - 1; |
| 780 | } |
| 781 | |
| 782 | /** |
| 783 | * Doubling Time - Continuous Compounding |
| 784 | * |
| 785 | * @param float $r Rate of return |
| 786 | * |
| 787 | * @return float |
| 788 | * |
| 789 | * @since 1.0.0 |
| 790 | */ |
| 791 | public static function getDoublingTimeContinuousCompounding(float $r) : float |
| 792 | { |
| 793 | return \log(2) / $r; |
| 794 | } |
| 795 | |
| 796 | /** |
| 797 | * Get rate to double - Continuous Compounding |
| 798 | * |
| 799 | * @param float $t Time in which to double investment |
| 800 | * |
| 801 | * @return float |
| 802 | * |
| 803 | * @since 1.0.0 |
| 804 | */ |
| 805 | public static function getDoublingContinuousCompoundingRate(float $t) : float |
| 806 | { |
| 807 | return \log(2) / $t; |
| 808 | } |
| 809 | |
| 810 | /** |
| 811 | * Equivalent Annual Annuity |
| 812 | * |
| 813 | * @param float $NPV Net present value |
| 814 | * @param float $r Rate per period |
| 815 | * @param int $n Number of periods |
| 816 | * |
| 817 | * @return float |
| 818 | * |
| 819 | * @since 1.0.0 |
| 820 | */ |
| 821 | public static function getEquivalentAnnualAnnuity(float $NPV, float $r, int $n) : float |
| 822 | { |
| 823 | return $r * $NPV / (1 - \pow(1 + $r, -$n)); |
| 824 | } |
| 825 | |
| 826 | /** |
| 827 | * Equivalent Annual Annuity |
| 828 | * |
| 829 | * @param float $C Equivalent annuity cash flow |
| 830 | * @param float $NPV Net present value |
| 831 | * @param float $r Rate per period |
| 832 | * |
| 833 | * @return int |
| 834 | * |
| 835 | * @since 1.0.0 |
| 836 | */ |
| 837 | public static function getPeriodsOfEAA(float $C, float $NPV, float $r) : int |
| 838 | { |
| 839 | return (int) \round(-\log(1 - $r * $NPV / $C) / \log(1 + $r)); |
| 840 | } |
| 841 | |
| 842 | /** |
| 843 | * Equivalent Annual Annuity |
| 844 | * |
| 845 | * @param float $C Net present value |
| 846 | * @param float $r Rate per period |
| 847 | * @param int $n Number of periods |
| 848 | * |
| 849 | * @return float |
| 850 | * |
| 851 | * @since 1.0.0 |
| 852 | */ |
| 853 | public static function getNetPresentValueOfEAA(float $C, float $r, int $n) : float |
| 854 | { |
| 855 | return $C * (1 - \pow(1 + $r, -$n)) / $r; |
| 856 | } |
| 857 | |
| 858 | /** |
| 859 | * Free Cash Flow to Equity (FCFE = FCFF - dept payments) |
| 860 | * |
| 861 | * @param float $income Net income |
| 862 | * @param float $depamo Depreciation & amortisation |
| 863 | * @param float $capital Capital expenses |
| 864 | * @param float $wc Change in working capital |
| 865 | * @param float $borrowing Net Borrowing |
| 866 | * |
| 867 | * @return float |
| 868 | * |
| 869 | * @since 1.0.0 |
| 870 | */ |
| 871 | public static function getFreeCashFlowToEquity(float $income, float $depamo, float $capital, float $wc, float $borrowing) : float |
| 872 | { |
| 873 | return $income + $depamo - $capital - $wc + $borrowing; |
| 874 | } |
| 875 | |
| 876 | /** |
| 877 | * Free Cash Flow to Firm (FCFF) |
| 878 | * |
| 879 | * @param float $ebit EBIT |
| 880 | * @param float $t Tax rate |
| 881 | * @param float $depamo Depreciation & amortisation |
| 882 | * @param float $capital Capital expenses |
| 883 | * @param float $wc Change in working capital |
| 884 | * |
| 885 | * @return float |
| 886 | * |
| 887 | * @since 1.0.0 |
| 888 | */ |
| 889 | public static function getFreeCashFlowToFirm(float $ebit, float $t, float $depamo, float $capital, float $wc) : float |
| 890 | { |
| 891 | return $ebit * (1 - $t) + $depamo - $capital - $wc; |
| 892 | } |
| 893 | |
| 894 | /** |
| 895 | * Future Value |
| 896 | * |
| 897 | * The Future Value (FV) is used to calculate the value of a cash flow after a specific amount of periods. |
| 898 | * |
| 899 | * @latex FV = C_{0} \cdot \left(1 + r\right)^{n} |
| 900 | * |
| 901 | * @param float $C Cash flow at period 0 |
| 902 | * @param float $r Rate of return |
| 903 | * @param int $n Numbers of periods |
| 904 | * |
| 905 | * @return float |
| 906 | * |
| 907 | * @since 1.0.0 |
| 908 | */ |
| 909 | public static function getFutureValue(float $C, float $r, int $n) : float |
| 910 | { |
| 911 | return $C * \pow(1 + $r, $n); |
| 912 | } |
| 913 | |
| 914 | /** |
| 915 | * Future Value - Continuous Compounding |
| 916 | * |
| 917 | * @param float $PV Present value |
| 918 | * @param float $r Rate of return |
| 919 | * @param int $t Time |
| 920 | * |
| 921 | * @return float |
| 922 | * |
| 923 | * @since 1.0.0 |
| 924 | */ |
| 925 | public static function getFutureValueContinuousCompounding(float $PV, float $r, int $t) : float |
| 926 | { |
| 927 | return $PV * \exp($r * $t); |
| 928 | } |
| 929 | |
| 930 | /** |
| 931 | * Future Value Factor |
| 932 | * |
| 933 | * The future value factor is used to calculate a facture which can be used to calculate |
| 934 | * the future value after a certain amount of periods at a give interest rate. |
| 935 | * |
| 936 | * @latex f = \left(1 + r\right)^{n} |
| 937 | * |
| 938 | * @param float $r Rate of return |
| 939 | * @param int $n Number of periods |
| 940 | * |
| 941 | * @return float |
| 942 | * |
| 943 | * @since 1.0.0 |
| 944 | */ |
| 945 | public static function getFutureValueFactor(float $r, int $n) : float |
| 946 | { |
| 947 | return \pow(1 + $r, $n); |
| 948 | } |
| 949 | |
| 950 | /** |
| 951 | * Geometric mean of return values |
| 952 | * |
| 953 | * Also known as compounded annual growth rate. |
| 954 | * |
| 955 | * @param array<int|float> $r Rate of return |
| 956 | * |
| 957 | * @return float |
| 958 | * |
| 959 | * @since 1.0.0 |
| 960 | */ |
| 961 | public static function getGeometricMeanReturn(array $r) : float |
| 962 | { |
| 963 | return Average::geometricMean($r); |
| 964 | } |
| 965 | |
| 966 | /** |
| 967 | * Growing Annuity - Future Value |
| 968 | * |
| 969 | * @param float $P First payment |
| 970 | * @param float $r Rate of return |
| 971 | * @param float $g Growth rate |
| 972 | * @param int $n Number of periods |
| 973 | * |
| 974 | * @return float |
| 975 | * |
| 976 | * @since 1.0.0 |
| 977 | */ |
| 978 | public static function getGrowingAnnuityFV(float $P, float $r, float $g, int $n) : float |
| 979 | { |
| 980 | return $P * (\pow(1 + $r, $n) - \pow(1 + $g, $n)) / ($r - $g); |
| 981 | } |
| 982 | |
| 983 | /** |
| 984 | * Growing Annuity - Payment (PV) |
| 985 | * |
| 986 | * @param float $PV Present value |
| 987 | * @param float $r Rate of return |
| 988 | * @param float $g Growth rate |
| 989 | * @param int $n Number of periods |
| 990 | * |
| 991 | * @return float |
| 992 | * |
| 993 | * @since 1.0.0 |
| 994 | */ |
| 995 | public static function getGrowingAnnuityPaymentPV(float $PV, float $r, float $g, int $n) : float |
| 996 | { |
| 997 | return $PV * ($r - $g) / (1 - \pow((1 + $g) / (1 + $r), $n)); |
| 998 | } |
| 999 | |
| 1000 | /** |
| 1001 | * Growing Annuity - Payment (FV) |
| 1002 | * |
| 1003 | * @param float $FV Present value |
| 1004 | * @param float $r Rate of return |
| 1005 | * @param float $g Growth rate |
| 1006 | * @param int $n Number of periods |
| 1007 | * |
| 1008 | * @return float |
| 1009 | * |
| 1010 | * @since 1.0.0 |
| 1011 | */ |
| 1012 | public static function getGrowingAnnuityPaymentFV(float $FV, float $r, float $g, int $n) : float |
| 1013 | { |
| 1014 | return $FV * ($r - $g) / (\pow(1 + $r, $n) - \pow(1 + $g, $n)); |
| 1015 | } |
| 1016 | |
| 1017 | /** |
| 1018 | * Growing Annuity - Present Value |
| 1019 | * |
| 1020 | * @param float $P First payment |
| 1021 | * @param float $r Rate of return |
| 1022 | * @param float $g Growth rate |
| 1023 | * @param int $n Number of periods |
| 1024 | * |
| 1025 | * @return float |
| 1026 | * |
| 1027 | * @since 1.0.0 |
| 1028 | */ |
| 1029 | public static function getGrowingAnnuityPV(float $P, float $r, float $g, int $n) : float |
| 1030 | { |
| 1031 | return $P / ($r - $g) * (1 - \pow((1 + $g) / (1 + $r), $n)); |
| 1032 | } |
| 1033 | |
| 1034 | /** |
| 1035 | * Growing Perpetuity - Present Value |
| 1036 | * |
| 1037 | * @param float $D Dividend or coupon at period 1 |
| 1038 | * @param float $r Rate of return |
| 1039 | * @param float $g Growth rate |
| 1040 | * |
| 1041 | * @return float |
| 1042 | * |
| 1043 | * @since 1.0.0 |
| 1044 | */ |
| 1045 | public static function getGrowingPerpetuityPV(float $D, float $r, float $g) : float |
| 1046 | { |
| 1047 | return $D / ($r - $g); |
| 1048 | } |
| 1049 | |
| 1050 | /** |
| 1051 | * Interest Coverage Ratio |
| 1052 | * |
| 1053 | * @param float $ebit EBIT |
| 1054 | * @param float $expense Interest expense |
| 1055 | * |
| 1056 | * @return float |
| 1057 | * |
| 1058 | * @since 1.0.0 |
| 1059 | */ |
| 1060 | public static function getInterestCoverageRatio(float $ebit, float $expense) : float |
| 1061 | { |
| 1062 | return $ebit / $expense; |
| 1063 | } |
| 1064 | |
| 1065 | /** |
| 1066 | * Inventory Turnover Ratio |
| 1067 | * |
| 1068 | * @param float $sales Sales |
| 1069 | * @param float $inventory Inventory |
| 1070 | * |
| 1071 | * @return float |
| 1072 | * |
| 1073 | * @since 1.0.0 |
| 1074 | */ |
| 1075 | public static function getInventoryTurnoverRatio(float $sales, float $inventory) : float |
| 1076 | { |
| 1077 | return $sales / $inventory; |
| 1078 | } |
| 1079 | |
| 1080 | /** |
| 1081 | * Net Present Value |
| 1082 | * |
| 1083 | * @param array<int|float> $C Cash flow ($C[0] = initial investment) |
| 1084 | * @param float $r Discount rate |
| 1085 | * |
| 1086 | * @return float |
| 1087 | * |
| 1088 | * @throws \UnexpectedValueException Throws this exception if the length of the array is 0 |
| 1089 | * |
| 1090 | * @since 1.0.0 |
| 1091 | */ |
| 1092 | public static function getNetPresentValue(array $C, float $r) : float |
| 1093 | { |
| 1094 | $count = \count($C); |
| 1095 | |
| 1096 | if ($count === 0) { |
| 1097 | return 0.0; |
| 1098 | } |
| 1099 | |
| 1100 | $npv = -$C[0]; |
| 1101 | |
| 1102 | for ($i = 1; $i < $count; ++$i) { |
| 1103 | $npv += $C[$i] / \pow(1 + $r, $i); |
| 1104 | } |
| 1105 | |
| 1106 | return $npv; |
| 1107 | } |
| 1108 | |
| 1109 | /** |
| 1110 | * Net Profit Margin |
| 1111 | * |
| 1112 | * @param float $income Net income |
| 1113 | * @param float $sales Sales revenue |
| 1114 | * |
| 1115 | * @return float |
| 1116 | * |
| 1117 | * @since 1.0.0 |
| 1118 | */ |
| 1119 | public static function getNetProfitMargin(float $income, float $sales) : float |
| 1120 | { |
| 1121 | return $income / $sales; |
| 1122 | } |
| 1123 | |
| 1124 | /** |
| 1125 | * Net Working Capital |
| 1126 | * |
| 1127 | * @param float $assets Current assets |
| 1128 | * @param float $liabilities Current liabilities |
| 1129 | * |
| 1130 | * @return float |
| 1131 | * |
| 1132 | * @since 1.0.0 |
| 1133 | */ |
| 1134 | public static function getNetWorkingCapital(float $assets, float $liabilities) : float |
| 1135 | { |
| 1136 | return $assets - $liabilities; |
| 1137 | } |
| 1138 | |
| 1139 | /** |
| 1140 | * Number of Periods - PV & FV |
| 1141 | * |
| 1142 | * @param float $FV Future value |
| 1143 | * @param float $PV Present value |
| 1144 | * @param float $r Rate per period |
| 1145 | * |
| 1146 | * @return float |
| 1147 | * |
| 1148 | * @since 1.0.0 |
| 1149 | */ |
| 1150 | public static function getNumberOfPeriodsPVFV(float $FV, float $PV, float $r) : float |
| 1151 | { |
| 1152 | return \log($FV / $PV) / \log(1 + $r); |
| 1153 | } |
| 1154 | |
| 1155 | /** |
| 1156 | * Payback Period |
| 1157 | * |
| 1158 | * @param float $investment Initial investment |
| 1159 | * @param float $cash Periodic cash flow |
| 1160 | * |
| 1161 | * @return float |
| 1162 | * |
| 1163 | * @since 1.0.0 |
| 1164 | */ |
| 1165 | public static function getPaybackPeriod(float $investment, float $cash) : float |
| 1166 | { |
| 1167 | return $investment / $cash; |
| 1168 | } |
| 1169 | |
| 1170 | /** |
| 1171 | * Perpetuity |
| 1172 | * |
| 1173 | * @param float $D Dividend or coupon per period |
| 1174 | * @param float $r Discount rate |
| 1175 | * |
| 1176 | * @return float |
| 1177 | * |
| 1178 | * @since 1.0.0 |
| 1179 | */ |
| 1180 | public static function getPresentValueOfPerpetuity(float $D, float $r) : float |
| 1181 | { |
| 1182 | return $D / $r; |
| 1183 | } |
| 1184 | |
| 1185 | /** |
| 1186 | * Number of Periods - PV & FV |
| 1187 | * |
| 1188 | * @param float $C Cash flow at period 1 |
| 1189 | * @param float $r Rate of return |
| 1190 | * @param int $n Number of periods |
| 1191 | * |
| 1192 | * @return float |
| 1193 | * |
| 1194 | * @since 1.0.0 |
| 1195 | */ |
| 1196 | public static function getPresentValue(float $C, float $r, int $n) : float |
| 1197 | { |
| 1198 | return $C / \pow(1 + $r, $n); |
| 1199 | } |
| 1200 | |
| 1201 | /** |
| 1202 | * PV - Continuous Compounding |
| 1203 | * |
| 1204 | * @param float $C Cash flow |
| 1205 | * @param float $r Rate of return |
| 1206 | * @param int $t Time |
| 1207 | * |
| 1208 | * @return float |
| 1209 | * |
| 1210 | * @since 1.0.0 |
| 1211 | */ |
| 1212 | public static function getPresentValueContinuousCompounding(float $C, float $r, int $t) : float |
| 1213 | { |
| 1214 | return $C / \exp($r * $t); |
| 1215 | } |
| 1216 | |
| 1217 | /** |
| 1218 | * Present Value Factor |
| 1219 | * |
| 1220 | * @param float $r Rate of return |
| 1221 | * @param int $n Number of periods |
| 1222 | * |
| 1223 | * @return float |
| 1224 | * |
| 1225 | * @since 1.0.0 |
| 1226 | */ |
| 1227 | public static function getPresentValueFactor(float $r, int $n) : float |
| 1228 | { |
| 1229 | return 1 / \pow(1 + $r, $n); |
| 1230 | } |
| 1231 | |
| 1232 | /** |
| 1233 | * Quick Ratio |
| 1234 | * |
| 1235 | * @param float $assets Quick assets (current assets - inventory) |
| 1236 | * @param float $liabilities Current liabilities |
| 1237 | * |
| 1238 | * @return float |
| 1239 | * |
| 1240 | * @since 1.0.0 |
| 1241 | */ |
| 1242 | public static function getQuickRatio(float $assets, float $liabilities) : float |
| 1243 | { |
| 1244 | return $assets / $liabilities; |
| 1245 | } |
| 1246 | |
| 1247 | /** |
| 1248 | * Rate of Inflation |
| 1249 | * |
| 1250 | * @param float $newCPI Consumer price index new |
| 1251 | * @param float $oldCPI Consumer price index old |
| 1252 | * |
| 1253 | * @return float |
| 1254 | * |
| 1255 | * @since 1.0.0 |
| 1256 | */ |
| 1257 | public static function getRateOfInflation(float $newCPI, float $oldCPI) : float |
| 1258 | { |
| 1259 | return $newCPI / $oldCPI - 1; |
| 1260 | } |
| 1261 | |
| 1262 | /** |
| 1263 | * Real Rate of Return |
| 1264 | * |
| 1265 | * @param float $nominal Nominal rate |
| 1266 | * @param float $inflation Inflation rate |
| 1267 | * |
| 1268 | * @return float |
| 1269 | * |
| 1270 | * @since 1.0.0 |
| 1271 | */ |
| 1272 | public static function getRealRateOfReturn(float $nominal, float $inflation) : float |
| 1273 | { |
| 1274 | return (1 + $nominal) / (1 + $inflation) - 1; |
| 1275 | } |
| 1276 | |
| 1277 | /** |
| 1278 | * Receivables Turnover Ratio |
| 1279 | * |
| 1280 | * @param float $sales Sales revenue |
| 1281 | * @param float $receivable Avg. accounts receivable |
| 1282 | * |
| 1283 | * @return float |
| 1284 | * |
| 1285 | * @since 1.0.0 |
| 1286 | */ |
| 1287 | public static function getReceivablesTurnoverRatio(float $sales, float $receivable) : float |
| 1288 | { |
| 1289 | return $sales / $receivable; |
| 1290 | } |
| 1291 | |
| 1292 | /** |
| 1293 | * Receivables Turnover Ratio |
| 1294 | * |
| 1295 | * @param float $income Net income |
| 1296 | * @param float $dividends Dividends |
| 1297 | * |
| 1298 | * @return float |
| 1299 | * |
| 1300 | * @since 1.0.0 |
| 1301 | */ |
| 1302 | public static function getRetentionRatio(float $income, float $dividends) : float |
| 1303 | { |
| 1304 | return ($income - $dividends) / $income; |
| 1305 | } |
| 1306 | |
| 1307 | /** |
| 1308 | * Return on Assets (ROA) |
| 1309 | * |
| 1310 | * @param float $income Net income |
| 1311 | * @param float $assets Avg. total assets |
| 1312 | * |
| 1313 | * @return float |
| 1314 | * |
| 1315 | * @since 1.0.0 |
| 1316 | */ |
| 1317 | public static function getReturnOnAssets(float $income, float $assets) : float |
| 1318 | { |
| 1319 | return $income / $assets; |
| 1320 | } |
| 1321 | |
| 1322 | /** |
| 1323 | * Return on Equity (ROE) |
| 1324 | * |
| 1325 | * @param float $income Net income |
| 1326 | * @param float $equity Avg. stockholder's equity |
| 1327 | * |
| 1328 | * @return float |
| 1329 | * |
| 1330 | * @since 1.0.0 |
| 1331 | */ |
| 1332 | public static function getReturnOnEquity(float $income, float $equity) : float |
| 1333 | { |
| 1334 | return $income / $equity; |
| 1335 | } |
| 1336 | |
| 1337 | /** |
| 1338 | * Return on Investment (ROI) |
| 1339 | * |
| 1340 | * @param float $earnings Earnings |
| 1341 | * @param float $investment Initial investment |
| 1342 | * |
| 1343 | * @return float |
| 1344 | * |
| 1345 | * @since 1.0.0 |
| 1346 | */ |
| 1347 | public static function getReturnOnInvestment(float $earnings, float $investment) : float |
| 1348 | { |
| 1349 | return $earnings / $investment - 1; |
| 1350 | } |
| 1351 | |
| 1352 | /** |
| 1353 | * Simple Interest |
| 1354 | * |
| 1355 | * @param float $P Principal |
| 1356 | * @param float $r Rate |
| 1357 | * @param int $t Time |
| 1358 | * |
| 1359 | * @return float |
| 1360 | * |
| 1361 | * @since 1.0.0 |
| 1362 | */ |
| 1363 | public static function getSimpleInterest(float $P, float $r, int $t) : float |
| 1364 | { |
| 1365 | return $P * $r * $t; |
| 1366 | } |
| 1367 | |
| 1368 | /** |
| 1369 | * Simple Interest Rate |
| 1370 | * |
| 1371 | * @param float $I Interest |
| 1372 | * @param float $P Principal |
| 1373 | * @param int $t Time |
| 1374 | * |
| 1375 | * @return float |
| 1376 | * |
| 1377 | * @since 1.0.0 |
| 1378 | */ |
| 1379 | public static function getSimpleInterestRate(float $I, float $P, int $t) : float |
| 1380 | { |
| 1381 | return $I / ($P * $t); |
| 1382 | } |
| 1383 | |
| 1384 | /** |
| 1385 | * Simple Interest Principal |
| 1386 | * |
| 1387 | * @param float $I Interest |
| 1388 | * @param float $r Rate |
| 1389 | * @param int $t Time |
| 1390 | * |
| 1391 | * @return float |
| 1392 | * |
| 1393 | * @since 1.0.0 |
| 1394 | */ |
| 1395 | public static function getSimpleInterestPrincipal(float $I, float $r, int $t) : float |
| 1396 | { |
| 1397 | return $I / ($r * $t); |
| 1398 | } |
| 1399 | |
| 1400 | /** |
| 1401 | * Simple Interest Principal |
| 1402 | * |
| 1403 | * @param float $I Interest |
| 1404 | * @param float $P Principal |
| 1405 | * @param float $r Rate |
| 1406 | * |
| 1407 | * @return int |
| 1408 | * |
| 1409 | * @since 1.0.0 |
| 1410 | */ |
| 1411 | public static function getSimpleInterestTime(float $I, float $P, float $r) : int |
| 1412 | { |
| 1413 | return (int) \round($I / ($P * $r)); |
| 1414 | } |
| 1415 | |
| 1416 | /** |
| 1417 | * Relative market share by share |
| 1418 | * |
| 1419 | * @param float $ownShare Own market share |
| 1420 | * @param float $competitorShare Largest competitor market share |
| 1421 | * |
| 1422 | * @return float |
| 1423 | * |
| 1424 | * @since 1.0.0 |
| 1425 | */ |
| 1426 | public static function getRelativeMarketShareByShare(float $ownShare, float $competitorShare) : float |
| 1427 | { |
| 1428 | return $ownShare / $competitorShare; |
| 1429 | } |
| 1430 | |
| 1431 | /** |
| 1432 | * Relative market share by sales |
| 1433 | * |
| 1434 | * @param float $ownSales Own sales |
| 1435 | * @param float $competitorSales Largest competitor sales |
| 1436 | * |
| 1437 | * @return float |
| 1438 | * |
| 1439 | * @since 1.0.0 |
| 1440 | */ |
| 1441 | public static function getRelativeMarketShareBySales(float $ownSales, float $competitorSales) : float |
| 1442 | { |
| 1443 | return $ownSales / $competitorSales; |
| 1444 | } |
| 1445 | } |