Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
| Loan | |
100.00% |
6 / 6 |
|
100.00% |
6 / 6 |
7 | |
100.00% |
1 / 1 |
| __construct | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| getPaymentsOnBalloonLoan | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getBalloonBalanceOfLoan | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getLoanPayment | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getRemainingBalanceLoan | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getLoanToDepositRatio | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getLoanToValueRatio | |
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 | /** |
| 18 | * Finance class. |
| 19 | * |
| 20 | * @package phpOMS\Business\Finance |
| 21 | * @license OMS License 2.0 |
| 22 | * @link https://jingga.app |
| 23 | * @since 1.0.0 |
| 24 | * |
| 25 | * @SuppressWarnings(PHPMD.CamelCaseParameterName) |
| 26 | * @SuppressWarnings(PHPMD.CamelCaseVariableName) |
| 27 | */ |
| 28 | final class Loan |
| 29 | { |
| 30 | /** |
| 31 | * Constructor |
| 32 | * |
| 33 | * @since 1.0.0 |
| 34 | * @codeCoverageIgnore |
| 35 | */ |
| 36 | private function __construct() |
| 37 | { |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Balloon Loan - Payments |
| 42 | * |
| 43 | * @param float $PV Present value |
| 44 | * @param float $r Rate per period |
| 45 | * @param int $n Number of periods |
| 46 | * @param float $balloon Balloon balance |
| 47 | * |
| 48 | * @return float |
| 49 | * |
| 50 | * @since 1.0.0 |
| 51 | */ |
| 52 | public static function getPaymentsOnBalloonLoan(float $PV, float $r, int $n, float $balloon = 0.0) : float |
| 53 | { |
| 54 | return ($PV - $balloon / \pow(1 + $r, $n)) * $r / (1 - \pow(1 + $r, -$n)); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Loan - Balloon Balance |
| 59 | * |
| 60 | * @param float $PV Present value (original balance) |
| 61 | * @param float $P Payment |
| 62 | * @param float $r Rate per payment |
| 63 | * @param int $n Number of payments |
| 64 | * |
| 65 | * @return float |
| 66 | * |
| 67 | * @since 1.0.0 |
| 68 | */ |
| 69 | public static function getBalloonBalanceOfLoan(float $PV, float $P, float $r, int $n) : float |
| 70 | { |
| 71 | return $PV * \pow(1 + $r, $n) - $P * (\pow(1 + $r, $n) - 1) / $r; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Loan - Payment |
| 76 | * |
| 77 | * @param float $PV Present value (original balance) |
| 78 | * @param float $r Rate per period |
| 79 | * @param int $n Number of periods |
| 80 | * |
| 81 | * @return float |
| 82 | * |
| 83 | * @since 1.0.0 |
| 84 | */ |
| 85 | public static function getLoanPayment(float $PV, float $r, int $n) : float |
| 86 | { |
| 87 | return $r * $PV / (1 - \pow(1 + $r, -$n)); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Loan - Remaining Balance |
| 92 | * |
| 93 | * @param float $PV Present value (original balance) |
| 94 | * @param float $P Payment |
| 95 | * @param float $r Rate per payment |
| 96 | * @param int $n Number of payments |
| 97 | * |
| 98 | * @return float |
| 99 | * |
| 100 | * @since 1.0.0 |
| 101 | */ |
| 102 | public static function getRemainingBalanceLoan(float $PV, float $P, float $r, int $n) : float |
| 103 | { |
| 104 | return $PV * \pow(1 + $r, $n) - $P * (\pow(1 + $r, $n) - 1) / $r; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Loan to Deposit Ratio |
| 109 | * |
| 110 | * @param float $loans Loans |
| 111 | * @param float $deposits Deposits |
| 112 | * |
| 113 | * @return float |
| 114 | * |
| 115 | * @since 1.0.0 |
| 116 | */ |
| 117 | public static function getLoanToDepositRatio(float $loans, float $deposits) : float |
| 118 | { |
| 119 | return $loans / $deposits; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Loan to Value (LTV) |
| 124 | * |
| 125 | * @param float $loan Loan amount |
| 126 | * @param float $collateral Value of collateral |
| 127 | * |
| 128 | * @return float |
| 129 | * |
| 130 | * @since 1.0.0 |
| 131 | */ |
| 132 | public static function getLoanToValueRatio(float $loan, float $collateral) : float |
| 133 | { |
| 134 | return $loan / $collateral; |
| 135 | } |
| 136 | } |