diff --git a/Business/Finance/FinanceFormulas.php b/Business/Finance/FinanceFormulas.php index 2ddd4f08a..b5cb4772f 100644 --- a/Business/Finance/FinanceFormulas.php +++ b/Business/Finance/FinanceFormulas.php @@ -33,6 +33,9 @@ class FinanceFormulas /** * Annual Percentage Yield + * + * The annual percentage yield (APY) calculates the yield taking compounding + * into consideration. * * @latex APY = \left(1+ \frac{r}{n}\right)^{n}-1 * @@ -811,7 +814,7 @@ class FinanceFormulas */ public static function getPeriodsOfEAA(float $C, float $NPV, float $r) : int { - return (int) round(log(-$r * $NPV / $C + 1) / log(1 + $r)); + return (int) round(-log(1 - $r * $NPV / $C) / log(1 + $r)); } /** @@ -827,7 +830,7 @@ class FinanceFormulas */ public static function getNetPresentValueOfEAA(float $C, float $r, int $n) : float { - return $C / $r * (1 - pow(1 + $r, -$n)); + return $C * (1 - pow(1 + $r, -$n)) / $r; } /** @@ -868,6 +871,10 @@ class FinanceFormulas /** * Future Value + * + * The Future Value (FV) is used to calculate the value of a cash flow after a specific amount of periods. + * + * @latex FV = C_{0} \cdot \left(1 + r\right)^{n} * * @param float $C Cash flow at period 0 * @param float $r Rate of return @@ -900,6 +907,11 @@ class FinanceFormulas /** * Future Value Factor + * + * The future value factor is used to calculate a facture which can be used to calculate + * the future value after a certain amount of periods at a give interest rate. + * + * @latex f = \left(1 + r\right)^{n} * * @param float $r Rate of return * @param int $n Number of periods @@ -924,7 +936,7 @@ class FinanceFormulas */ public static function getGeometricMeanReturn(array $r) : float { - return Average::geometricMean($r) - 1; + return Average::geometricMean($r); } /** diff --git a/DataStorage/Cache/CacheFactory.php b/DataStorage/Cache/CacheFactory.php index 93ac7a2f9..734596169 100644 --- a/DataStorage/Cache/CacheFactory.php +++ b/DataStorage/Cache/CacheFactory.php @@ -4,7 +4,7 @@ * * PHP Version 7.1 * - * @package TBD + * @package phpOMS\DataStorage\Cache * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 @@ -15,9 +15,9 @@ declare(strict_types=1); namespace phpOMS\DataStorage\Cache; /** - * Database connection factory. + * Cache connection factory. * - * @package Framework + * @package phpOMS\DataStorage\Cache * @license OMS License 1.0 * @link http://website.orange-management.de * @since 1.0.0 diff --git a/DataStorage/Cache/CacheInterface.php b/DataStorage/Cache/CacheInterface.php index 9b05277f2..245110ae7 100644 --- a/DataStorage/Cache/CacheInterface.php +++ b/DataStorage/Cache/CacheInterface.php @@ -4,7 +4,7 @@ * * PHP Version 7.1 * - * @package TBD + * @package phpOMS\DataStorage\Cache * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 @@ -19,7 +19,7 @@ use phpOMS\Stdlib\Base\Exception\InvalidEnumValue; /** * Cache interface. * - * @package Framework + * @package phpOMS\DataStorage\Cache * @license OMS License 1.0 * @link http://website.orange-management.de * @since 1.0.0 diff --git a/DataStorage/Cache/CachePool.php b/DataStorage/Cache/CachePool.php index 6aca6c1a3..a236b543f 100644 --- a/DataStorage/Cache/CachePool.php +++ b/DataStorage/Cache/CachePool.php @@ -4,7 +4,7 @@ * * PHP Version 7.1 * - * @package TBD + * @package phpOMS\DataStorage\Cache * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 @@ -23,7 +23,7 @@ use phpOMS\Config\OptionsTrait; * Responsible for caching scalar data types and arrays. * Caching HTML output and objects coming soon/is planned. * - * @package Framework + * @package phpOMS\DataStorage\Cache * @license OMS License 1.0 * @link http://website.orange-management.de * @since 1.0.0 diff --git a/DataStorage/Cache/CacheStatus.php b/DataStorage/Cache/CacheStatus.php index c2e6071bf..d14b36dcf 100644 --- a/DataStorage/Cache/CacheStatus.php +++ b/DataStorage/Cache/CacheStatus.php @@ -4,7 +4,7 @@ * * PHP Version 7.1 * - * @package TBD + * @package phpOMS\DataStorage\Cache * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 @@ -21,7 +21,7 @@ use phpOMS\Stdlib\Base\Enum; * * Possible caching status * - * @package Framework + * @package phpOMS\DataStorage\Cache * @license OMS License 1.0 * @link http://website.orange-management.de * @since 1.0.0 diff --git a/DataStorage/Cache/CacheType.php b/DataStorage/Cache/CacheType.php index 3a16207d6..6ad17e073 100644 --- a/DataStorage/Cache/CacheType.php +++ b/DataStorage/Cache/CacheType.php @@ -4,7 +4,7 @@ * * PHP Version 7.1 * - * @package TBD + * @package phpOMS\DataStorage\Cache * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 @@ -21,7 +21,7 @@ use phpOMS\Stdlib\Base\Enum; * * Possible caching types * - * @package Framework + * @package phpOMS\DataStorage\Cache * @license OMS License 1.0 * @link http://website.orange-management.de * @since 1.0.0 diff --git a/DataStorage/Cache/FileCache.php b/DataStorage/Cache/FileCache.php index a2f20d6ae..a48dd7388 100644 --- a/DataStorage/Cache/FileCache.php +++ b/DataStorage/Cache/FileCache.php @@ -4,7 +4,7 @@ * * PHP Version 7.1 * - * @package TBD + * @package phpOMS\DataStorage\Cache * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 @@ -23,7 +23,7 @@ use phpOMS\System\File\Local\File; * * PHP Version 7.1 * - * @package Framework + * @package phpOMS\DataStorage\Cache * @license OMS License 1.0 * @link http://website.orange-management.de * @since 1.0.0 diff --git a/DataStorage/Cache/MemCache.php b/DataStorage/Cache/MemCache.php index 8729530d1..16aaf7024 100644 --- a/DataStorage/Cache/MemCache.php +++ b/DataStorage/Cache/MemCache.php @@ -4,7 +4,7 @@ * * PHP Version 7.1 * - * @package TBD + * @package phpOMS\DataStorage\Cache * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 @@ -17,7 +17,7 @@ namespace phpOMS\DataStorage\Cache; /** * Memcache class. * - * @package Framework + * @package phpOMS\DataStorage\Cache * @license OMS License 1.0 * @link http://website.orange-management.de * @since 1.0.0 diff --git a/DataStorage/Cache/MemCached.php b/DataStorage/Cache/MemCached.php index 5685dde30..343cc9262 100644 --- a/DataStorage/Cache/MemCached.php +++ b/DataStorage/Cache/MemCached.php @@ -4,7 +4,7 @@ * * PHP Version 7.1 * - * @package TBD + * @package phpOMS\DataStorage\Cache * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 @@ -17,7 +17,7 @@ namespace phpOMS\DataStorage\Cache; /** * Memcache class. * - * @package Framework + * @package phpOMS\DataStorage\Cache * @license OMS License 1.0 * @link http://website.orange-management.de * @since 1.0.0 diff --git a/DataStorage/Cache/NullCache.php b/DataStorage/Cache/NullCache.php index e9172a643..d555b27f2 100644 --- a/DataStorage/Cache/NullCache.php +++ b/DataStorage/Cache/NullCache.php @@ -4,7 +4,7 @@ * * PHP Version 7.1 * - * @package TBD + * @package phpOMS\DataStorage\Cache * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 @@ -17,7 +17,7 @@ namespace phpOMS\DataStorage\Cache; /** * Null cache class. * - * @package Framework + * @package phpOMS\DataStorage\Cache * @license OMS License 1.0 * @link http://website.orange-management.de * @since 1.0.0 diff --git a/DataStorage/Cache/RedisCache.php b/DataStorage/Cache/RedisCache.php index ddb8eb440..71d00e6b3 100644 --- a/DataStorage/Cache/RedisCache.php +++ b/DataStorage/Cache/RedisCache.php @@ -4,7 +4,7 @@ * * PHP Version 7.1 * - * @package TBD + * @package phpOMS\DataStorage\Cache * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 @@ -19,7 +19,7 @@ namespace phpOMS\DataStorage\Cache; * * PHP Version 5.6 * - * @package Framework + * @package phpOMS\DataStorage\Cache * @license OMS License 1.0 * @link http://website.orange-management.de * @since 1.0.0 diff --git a/DataStorage/Cache/WinCache.php b/DataStorage/Cache/WinCache.php index d9b2bc1dd..edc389005 100644 --- a/DataStorage/Cache/WinCache.php +++ b/DataStorage/Cache/WinCache.php @@ -4,7 +4,7 @@ * * PHP Version 7.1 * - * @package TBD + * @package phpOMS\DataStorage\Cache * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 @@ -19,7 +19,7 @@ namespace phpOMS\DataStorage\Cache; * * PHP Version 5.6 * - * @package Framework + * @package phpOMS\DataStorage\Cache * @license OMS License 1.0 * @link http://website.orange-management.de * @since 1.0.0 diff --git a/DataStorage/Cookie/CookieJar.php b/DataStorage/Cookie/CookieJar.php index 2748ce2e8..980462138 100644 --- a/DataStorage/Cookie/CookieJar.php +++ b/DataStorage/Cookie/CookieJar.php @@ -4,7 +4,7 @@ * * PHP Version 7.1 * - * @package TBD + * @package phpOMS\DataStorage\Cookie * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 @@ -19,7 +19,7 @@ use phpOMS\DataStorage\LockException; /** * CookieJar class * - * @package Framework + * @package phpOMS\DataStorage\Cookie * @license OMS License 1.0 * @link http://website.orange-management.de * @since 1.0.0 diff --git a/DataStorage/DataMapperInterface.php b/DataStorage/DataMapperInterface.php index b7657d06f..64e1ce4e0 100644 --- a/DataStorage/DataMapperInterface.php +++ b/DataStorage/DataMapperInterface.php @@ -4,7 +4,7 @@ * * PHP Version 7.1 * - * @package TBD + * @package phpOMS\DataStorage * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 @@ -21,7 +21,7 @@ use phpOMS\DataStorage\Database\Query\Builder; * * DB, Cache, Session * - * @package Framework + * @package phpOMS\DataStorage * @license OMS License 1.0 * @link http://website.orange-management.de * @since 1.0.0 diff --git a/DataStorage/LockException.php b/DataStorage/LockException.php index 703b99f49..a37a0a713 100644 --- a/DataStorage/LockException.php +++ b/DataStorage/LockException.php @@ -4,7 +4,7 @@ * * PHP Version 7.1 * - * @package TBD + * @package phpOMS\DataStorage * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 @@ -17,7 +17,7 @@ namespace phpOMS\DataStorage; /** * Permission exception class. * - * @package Framework + * @package phpOMS\DataStorage * @license OMS License 1.0 * @link http://website.orange-management.de * @since 1.0.0 diff --git a/DataStorage/Session/HttpSession.php b/DataStorage/Session/HttpSession.php index 6030b53a8..05688b77f 100644 --- a/DataStorage/Session/HttpSession.php +++ b/DataStorage/Session/HttpSession.php @@ -4,7 +4,7 @@ * * PHP Version 7.1 * - * @package TBD + * @package phpOMS\DataStorage\Session * @copyright Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 @@ -21,7 +21,7 @@ use phpOMS\DataStorage\LockException; /** * Http session class. * - * @package Framework + * @package phpOMS\DataStorage\Session * @license OMS License 1.0 * @link http://website.orange-management.de * @since 1.0.0 diff --git a/tests/Business/Finance/FinanceFormulasTest.php b/tests/Business/Finance/FinanceFormulasTest.php index 2af546db6..1a3adb35d 100644 --- a/tests/Business/Finance/FinanceFormulasTest.php +++ b/tests/Business/Finance/FinanceFormulasTest.php @@ -230,11 +230,6 @@ class FinanceFormulasTest extends \PHPUnit\Framework\TestCase self::assertEquals($t, FinanceFormulas::getSimpleInterestTime($I, $P, $r)); } - public function testNetPresentValue() - { - self::assertTrue(abs(1009.23 - FinanceFormulas::getNetPresentValue([10000, 500, 1000, 1500, 2000, 2500, 3000, 3500], 0.05)) < 0.01); - } - public function testDiscountedPaybackPeriod() { $O1 = 5000; @@ -251,4 +246,142 @@ class FinanceFormulasTest extends \PHPUnit\Framework\TestCase self::assertTrue(abs(14.207 - FinanceFormulas::getDoublingTime($r)) < 0.01); self::assertTrue(abs($r - FinanceFormulas::getDoublingRate(14.207)) < 0.01); } + + public function testDoublingTimeContinuousCompounding() + { + $r = 0.05; + + self::assertEquals(13.863, FinanceFormulas::getDoublingTimeContinuousCompounding($r), '', 0.01); + } + + public function testEquivalentAnnualAnnuity() + { + $npv = 1000; + $r = 0.15; + $n = 7; + + self::assertEquals(240.36, FinanceFormulas::getEquivalentAnnualAnnuity($npv, $r, $n), '', 0.01); + self::assertEquals($n, FinanceFormulas::getPeriodsOfEAA(240.36, $npv, $r)); + self::assertEquals($npv, FinanceFormulas::getNetPresentValueOfEAA(240.36, $r, $n), '', 0.01); + } + + public function testFreeCashFlowToEquity() + { + $income = 1000; + $depamo = 300; + $capital = 400; + $wc = 200; + $borrowing = 500; + + self::assertEquals(1200, FinanceFormulas::getFreeCashFlowToEquity($income, $depamo, $capital, $wc, $borrowing), '', 0.01); + } + + public function testFreeCashFlowToFirm() + { + $ebit = 1000; + $depamo = 300; + $t = 0.15; + $capital = 400; + $wc = 200; + + self::assertEquals(550, FinanceFormulas::getFreeCashFlowToFirm($ebit, $t, $depamo, $capital, $wc), '', 0.01); + } + + public function testFutureValue() + { + $c = 1000; + $r = 0.15; + $n = 7; + + self::assertEquals(2660.02, FinanceFormulas::getFutureValue($c, $r, $n), '', 0.01); + } + + public function testFutureValueContinuousCompounding() + { + $pv = 1000; + $r = 0.15; + $t = 7; + + self::assertEquals(2857.65, FinanceFormulas::getFutureValueContinuousCompounding($pv, $r, $t), '', 0.01); + } + + public function testFutureValueFactor() + { + $r = 0.15; + $n = 7; + + self::assertEquals(2.66, FinanceFormulas::getFutureValueFactor($r, $n), '', 0.01); + } + + public function testGeometricMeanReturn() + { + $r = [0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07]; + + self::assertEquals(0.04123, FinanceFormulas::getGeometricMeanReturn($r), '', 0.01); + } + + public function testGrowingAnnuityFV() + { + $p = 1000; + $r = 0.15; + $g = 0.1; + $n = 7; + + self::assertEquals(14226.06, FinanceFormulas::getGrowingAnnuityFV($p, $r, $g, $n), '', 0.01); + } + + public function testGrowingAnnuityPaymentPV() + { + $p = 1000; + $r = 0.15; + $g = 0.1; + $n = 7; + + self::assertEquals(186.98, FinanceFormulas::getGrowingAnnuityPaymentPV($p, $r, $g, $n), '', 0.01); + } + + public function testGrowingAnnuityPaymentFV() + { + $fv = 1000; + $r = 0.15; + $g = 0.1; + $n = 7; + + self::assertEquals(70.29, FinanceFormulas::getGrowingAnnuityPaymentFV($fv, $r, $g, $n), '', 0.01); + } + + public function testGrowingAnnuityPV() + { + $p = 1000; + $r = 0.15; + $g = 0.1; + $n = 7; + + self::assertEquals(5348.1, FinanceFormulas::getGrowingAnnuityPV($p, $r, $g, $n), '', 0.01); + } + + public function testGrowingPerpetuityPV() + { + $d = 1000; + $r = 0.15; + $g = 0.1; + + self::assertEquals(20000, FinanceFormulas::getGrowingPerpetuityPV($d, $r, $g), '', 0.01); + } + + public function testNetPresentValue() + { + $c = [1000, 100, 200, 300, 400, 500, 600]; + $r = 0.15; + + self::assertEquals(172.13, FinanceFormulas::getNetPresentValue($c, $r), '', 0.01); + } + + public function testRealRateOfReturn() + { + $nominal = 0.15; + $inflation = 0.05; + + self::assertEquals(0.09524, FinanceFormulas::getRealRateOfReturn($nominal, $inflation), '', 0.01); + } } diff --git a/tests/Business/Finance/LoanTest.php b/tests/Business/Finance/LoanTest.php index 9d611ea2f..a2d72bc58 100644 --- a/tests/Business/Finance/LoanTest.php +++ b/tests/Business/Finance/LoanTest.php @@ -22,4 +22,43 @@ class LoanTest extends \PHPUnit\Framework\TestCase self::assertEquals(100 / 50, Loan::getLoanToDepositRatio(100, 50)); self::assertEquals(100 / 50, Loan::getLoanToValueRatio(100, 50)); } + + public function testPaymentsOnBalloonLoan() + { + $pv = 1000; + $r = 0.15; + $n = 7; + $balloon = 300; + + self::assertEquals(213.25, Loan::getPaymentsOnBalloonLoan($pv, $r, $n, $balloon), '', 0.01); + } + + public function testBalloonBalanceOfLoan() + { + $pv = 1000; + $p = 300; + $r = 0.15; + $n = 7; + + self::assertEquals(-660.02, Loan::getBalloonBalanceOfLoan($pv, $p, $r, $n), '', 0.01); + } + + public function testLoanPayment() + { + $pv = 1000; + $r = 0.15; + $n = 7; + + self::assertEquals(240.36, Loan::getLoanPayment($pv, $r, $n), '', 0.01); + } + + public function testRemainingBalanceLoan() + { + $pv = 1000; + $p = 200; + $r = 0.15; + $n = 7; + + self::assertEquals(446.66, Loan::getRemainingBalanceLoan($pv, $p, $r, $n), '', 0.01); + } } diff --git a/tests/Business/Finance/StockBondsTest.php b/tests/Business/Finance/StockBondsTest.php index 9030cfef8..05ea45f1b 100644 --- a/tests/Business/Finance/StockBondsTest.php +++ b/tests/Business/Finance/StockBondsTest.php @@ -50,4 +50,20 @@ class StockBondsTest extends \PHPUnit\Framework\TestCase { self::assertEquals(9.09, StockBonds::getDilutedEarningsPerShare(1000, 100, 10), '', 0.1); } + + public function testHoldingPeriodReturn() + { + $r = [0.01, 0.02, 0.03, 0.04]; + + self::assertEquals(0.10355, StockBonds::getHoldingPeriodReturn($r), '', 0.01); + } + + public function testNetAssetValue() + { + $assets = 1000; + $liabilities = 300; + $shares = 400; + + self::assertEquals(1.75, StockBonds::getNetAssetValue($assets, $liabilities, $shares), '', 0.01); + } }