mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-12 06:48:41 +00:00
Add more tests and fix bugs
This commit is contained in:
parent
ae87bc9ab5
commit
c43d83d8c0
|
|
@ -33,6 +33,9 @@ class FinanceFormulas
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Annual Percentage Yield
|
* 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
|
* @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
|
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
|
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
|
* 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 $C Cash flow at period 0
|
||||||
* @param float $r Rate of return
|
* @param float $r Rate of return
|
||||||
|
|
@ -900,6 +907,11 @@ class FinanceFormulas
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Future Value Factor
|
* 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 float $r Rate of return
|
||||||
* @param int $n Number of periods
|
* @param int $n Number of periods
|
||||||
|
|
@ -924,7 +936,7 @@ class FinanceFormulas
|
||||||
*/
|
*/
|
||||||
public static function getGeometricMeanReturn(array $r) : float
|
public static function getGeometricMeanReturn(array $r) : float
|
||||||
{
|
{
|
||||||
return Average::geometricMean($r) - 1;
|
return Average::geometricMean($r);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* PHP Version 7.1
|
* PHP Version 7.1
|
||||||
*
|
*
|
||||||
* @package TBD
|
* @package phpOMS\DataStorage\Cache
|
||||||
* @copyright Dennis Eichhorn
|
* @copyright Dennis Eichhorn
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
|
|
@ -15,9 +15,9 @@ declare(strict_types=1);
|
||||||
namespace phpOMS\DataStorage\Cache;
|
namespace phpOMS\DataStorage\Cache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database connection factory.
|
* Cache connection factory.
|
||||||
*
|
*
|
||||||
* @package Framework
|
* @package phpOMS\DataStorage\Cache
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @link http://website.orange-management.de
|
* @link http://website.orange-management.de
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* PHP Version 7.1
|
* PHP Version 7.1
|
||||||
*
|
*
|
||||||
* @package TBD
|
* @package phpOMS\DataStorage\Cache
|
||||||
* @copyright Dennis Eichhorn
|
* @copyright Dennis Eichhorn
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
|
|
@ -19,7 +19,7 @@ use phpOMS\Stdlib\Base\Exception\InvalidEnumValue;
|
||||||
/**
|
/**
|
||||||
* Cache interface.
|
* Cache interface.
|
||||||
*
|
*
|
||||||
* @package Framework
|
* @package phpOMS\DataStorage\Cache
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @link http://website.orange-management.de
|
* @link http://website.orange-management.de
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* PHP Version 7.1
|
* PHP Version 7.1
|
||||||
*
|
*
|
||||||
* @package TBD
|
* @package phpOMS\DataStorage\Cache
|
||||||
* @copyright Dennis Eichhorn
|
* @copyright Dennis Eichhorn
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
|
|
@ -23,7 +23,7 @@ use phpOMS\Config\OptionsTrait;
|
||||||
* Responsible for caching scalar data types and arrays.
|
* Responsible for caching scalar data types and arrays.
|
||||||
* Caching HTML output and objects coming soon/is planned.
|
* Caching HTML output and objects coming soon/is planned.
|
||||||
*
|
*
|
||||||
* @package Framework
|
* @package phpOMS\DataStorage\Cache
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @link http://website.orange-management.de
|
* @link http://website.orange-management.de
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* PHP Version 7.1
|
* PHP Version 7.1
|
||||||
*
|
*
|
||||||
* @package TBD
|
* @package phpOMS\DataStorage\Cache
|
||||||
* @copyright Dennis Eichhorn
|
* @copyright Dennis Eichhorn
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
|
|
@ -21,7 +21,7 @@ use phpOMS\Stdlib\Base\Enum;
|
||||||
*
|
*
|
||||||
* Possible caching status
|
* Possible caching status
|
||||||
*
|
*
|
||||||
* @package Framework
|
* @package phpOMS\DataStorage\Cache
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @link http://website.orange-management.de
|
* @link http://website.orange-management.de
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* PHP Version 7.1
|
* PHP Version 7.1
|
||||||
*
|
*
|
||||||
* @package TBD
|
* @package phpOMS\DataStorage\Cache
|
||||||
* @copyright Dennis Eichhorn
|
* @copyright Dennis Eichhorn
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
|
|
@ -21,7 +21,7 @@ use phpOMS\Stdlib\Base\Enum;
|
||||||
*
|
*
|
||||||
* Possible caching types
|
* Possible caching types
|
||||||
*
|
*
|
||||||
* @package Framework
|
* @package phpOMS\DataStorage\Cache
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @link http://website.orange-management.de
|
* @link http://website.orange-management.de
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* PHP Version 7.1
|
* PHP Version 7.1
|
||||||
*
|
*
|
||||||
* @package TBD
|
* @package phpOMS\DataStorage\Cache
|
||||||
* @copyright Dennis Eichhorn
|
* @copyright Dennis Eichhorn
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
|
|
@ -23,7 +23,7 @@ use phpOMS\System\File\Local\File;
|
||||||
*
|
*
|
||||||
* PHP Version 7.1
|
* PHP Version 7.1
|
||||||
*
|
*
|
||||||
* @package Framework
|
* @package phpOMS\DataStorage\Cache
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @link http://website.orange-management.de
|
* @link http://website.orange-management.de
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* PHP Version 7.1
|
* PHP Version 7.1
|
||||||
*
|
*
|
||||||
* @package TBD
|
* @package phpOMS\DataStorage\Cache
|
||||||
* @copyright Dennis Eichhorn
|
* @copyright Dennis Eichhorn
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
|
|
@ -17,7 +17,7 @@ namespace phpOMS\DataStorage\Cache;
|
||||||
/**
|
/**
|
||||||
* Memcache class.
|
* Memcache class.
|
||||||
*
|
*
|
||||||
* @package Framework
|
* @package phpOMS\DataStorage\Cache
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @link http://website.orange-management.de
|
* @link http://website.orange-management.de
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* PHP Version 7.1
|
* PHP Version 7.1
|
||||||
*
|
*
|
||||||
* @package TBD
|
* @package phpOMS\DataStorage\Cache
|
||||||
* @copyright Dennis Eichhorn
|
* @copyright Dennis Eichhorn
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
|
|
@ -17,7 +17,7 @@ namespace phpOMS\DataStorage\Cache;
|
||||||
/**
|
/**
|
||||||
* Memcache class.
|
* Memcache class.
|
||||||
*
|
*
|
||||||
* @package Framework
|
* @package phpOMS\DataStorage\Cache
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @link http://website.orange-management.de
|
* @link http://website.orange-management.de
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* PHP Version 7.1
|
* PHP Version 7.1
|
||||||
*
|
*
|
||||||
* @package TBD
|
* @package phpOMS\DataStorage\Cache
|
||||||
* @copyright Dennis Eichhorn
|
* @copyright Dennis Eichhorn
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
|
|
@ -17,7 +17,7 @@ namespace phpOMS\DataStorage\Cache;
|
||||||
/**
|
/**
|
||||||
* Null cache class.
|
* Null cache class.
|
||||||
*
|
*
|
||||||
* @package Framework
|
* @package phpOMS\DataStorage\Cache
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @link http://website.orange-management.de
|
* @link http://website.orange-management.de
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* PHP Version 7.1
|
* PHP Version 7.1
|
||||||
*
|
*
|
||||||
* @package TBD
|
* @package phpOMS\DataStorage\Cache
|
||||||
* @copyright Dennis Eichhorn
|
* @copyright Dennis Eichhorn
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
|
|
@ -19,7 +19,7 @@ namespace phpOMS\DataStorage\Cache;
|
||||||
*
|
*
|
||||||
* PHP Version 5.6
|
* PHP Version 5.6
|
||||||
*
|
*
|
||||||
* @package Framework
|
* @package phpOMS\DataStorage\Cache
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @link http://website.orange-management.de
|
* @link http://website.orange-management.de
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* PHP Version 7.1
|
* PHP Version 7.1
|
||||||
*
|
*
|
||||||
* @package TBD
|
* @package phpOMS\DataStorage\Cache
|
||||||
* @copyright Dennis Eichhorn
|
* @copyright Dennis Eichhorn
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
|
|
@ -19,7 +19,7 @@ namespace phpOMS\DataStorage\Cache;
|
||||||
*
|
*
|
||||||
* PHP Version 5.6
|
* PHP Version 5.6
|
||||||
*
|
*
|
||||||
* @package Framework
|
* @package phpOMS\DataStorage\Cache
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @link http://website.orange-management.de
|
* @link http://website.orange-management.de
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* PHP Version 7.1
|
* PHP Version 7.1
|
||||||
*
|
*
|
||||||
* @package TBD
|
* @package phpOMS\DataStorage\Cookie
|
||||||
* @copyright Dennis Eichhorn
|
* @copyright Dennis Eichhorn
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
|
|
@ -19,7 +19,7 @@ use phpOMS\DataStorage\LockException;
|
||||||
/**
|
/**
|
||||||
* CookieJar class
|
* CookieJar class
|
||||||
*
|
*
|
||||||
* @package Framework
|
* @package phpOMS\DataStorage\Cookie
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @link http://website.orange-management.de
|
* @link http://website.orange-management.de
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* PHP Version 7.1
|
* PHP Version 7.1
|
||||||
*
|
*
|
||||||
* @package TBD
|
* @package phpOMS\DataStorage
|
||||||
* @copyright Dennis Eichhorn
|
* @copyright Dennis Eichhorn
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
|
|
@ -21,7 +21,7 @@ use phpOMS\DataStorage\Database\Query\Builder;
|
||||||
*
|
*
|
||||||
* DB, Cache, Session
|
* DB, Cache, Session
|
||||||
*
|
*
|
||||||
* @package Framework
|
* @package phpOMS\DataStorage
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @link http://website.orange-management.de
|
* @link http://website.orange-management.de
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* PHP Version 7.1
|
* PHP Version 7.1
|
||||||
*
|
*
|
||||||
* @package TBD
|
* @package phpOMS\DataStorage
|
||||||
* @copyright Dennis Eichhorn
|
* @copyright Dennis Eichhorn
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
|
|
@ -17,7 +17,7 @@ namespace phpOMS\DataStorage;
|
||||||
/**
|
/**
|
||||||
* Permission exception class.
|
* Permission exception class.
|
||||||
*
|
*
|
||||||
* @package Framework
|
* @package phpOMS\DataStorage
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @link http://website.orange-management.de
|
* @link http://website.orange-management.de
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* PHP Version 7.1
|
* PHP Version 7.1
|
||||||
*
|
*
|
||||||
* @package TBD
|
* @package phpOMS\DataStorage\Session
|
||||||
* @copyright Dennis Eichhorn
|
* @copyright Dennis Eichhorn
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
|
|
@ -21,7 +21,7 @@ use phpOMS\DataStorage\LockException;
|
||||||
/**
|
/**
|
||||||
* Http session class.
|
* Http session class.
|
||||||
*
|
*
|
||||||
* @package Framework
|
* @package phpOMS\DataStorage\Session
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @link http://website.orange-management.de
|
* @link http://website.orange-management.de
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
|
|
||||||
|
|
@ -230,11 +230,6 @@ class FinanceFormulasTest extends \PHPUnit\Framework\TestCase
|
||||||
self::assertEquals($t, FinanceFormulas::getSimpleInterestTime($I, $P, $r));
|
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()
|
public function testDiscountedPaybackPeriod()
|
||||||
{
|
{
|
||||||
$O1 = 5000;
|
$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(14.207 - FinanceFormulas::getDoublingTime($r)) < 0.01);
|
||||||
self::assertTrue(abs($r - FinanceFormulas::getDoublingRate(14.207)) < 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,4 +22,43 @@ class LoanTest extends \PHPUnit\Framework\TestCase
|
||||||
self::assertEquals(100 / 50, Loan::getLoanToDepositRatio(100, 50));
|
self::assertEquals(100 / 50, Loan::getLoanToDepositRatio(100, 50));
|
||||||
self::assertEquals(100 / 50, Loan::getLoanToValueRatio(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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,4 +50,20 @@ class StockBondsTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
self::assertEquals(9.09, StockBonds::getDilutedEarningsPerShare(1000, 100, 10), '', 0.1);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user