| Recommend this page to a friend! |
| Info | Documentation | Reputation | Support forum | Blog | Links |
| Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
| 2025-06-03 (Yesterday) | Not yet rated by the users | Total: Not yet counted | Not yet ranked | |||||
| Version | License | PHP version | Categories | |||
| mathfinance 4.0.0 | Custom (specified... | 5 | Algorithms, PHP 5, Finances, Math |
| Description | Author | |
This package can perform mathematical operations for financial applications. |
|
Please read this document to learn how to install the PHP Math Finance package and use its classes to perform financial calculations.
Package for financial math functions
This package contains assorted methods for fixed income instrument calculations, enabling developers to perform accurate and reliable financial math operations such as interest calculations, depreciation, bond valuation, and more.
require "rhossis/mathfinance" : "^4.0.0"
The math class provides several financial math functions. These methods largely mirror Microsoft Excel functions and extend the legacy PEAR math classes. The package also comes with a bond interest calculation class, which is compliant with interest calculations used in various exchanges worldwide, such as Central Bank of Kenyas 364 days calculation.
// Precision level
define('MATHFINANCE_PRECISION', 1E-6);
// Payment types
define('MATHFINANCE_PAYEND', 0);
define('MATHFINANCE_PAYBEGIN', 1);
// Day count methods
define('MATHFINANCE_COUNTNASD', 0);
define('MATHFINANCE_COUNTACTUALACTUAL', 1);
define('MATHFINANCE_COUNTACTUAL360', 2);
define('MATHFINANCE_COUNTACTUAL365', 3);
define('MATHFINANCE_COUNTEUROPEAN', 4);
// Extended day count methods
define('MATHFINANCE_COUNTNEW_GERMAN', 1);
define('MATHFINANCE_COUNTNEW_GERMANSPEC', 2);
define('MATHFINANCE_COUNTNEW_ENGLISH', 3);
define('MATHFINANCE_COUNTNEW_FRENCH', 4);
define('MATHFINANCE_COUNTNEW_US', 5);
define('MATHFINANCE_COUNTNEW_ISMAYEAR', 6);
define('MATHFINANCE_COUNTNEW_ISMA99N', 7);
define('MATHFINANCE_COUNTNEW_ISMA99U', 8);
// Error flags
define('MATHFINANCE_ERROR_BADDCM', 1);
define('MATHFINANCE_ERROR_BADDATES', 2);
// Accrued interest calculation constants
define('MATHFINANCE_SWX_BOND_AI_GERMAN', 1);
define('MATHFINANCE_SWX_BOND_AI_SPEC_GERMAN', 2);
define('MATHFINANCE_SWX_BOND_AI_ENGLISH', 3);
define('MATHFINANCE_SWX_BOND_AI_FRENCH', 4);
define('MATHFINANCE_SWX_BOND_AI_US', 5);
define('MATHFINANCE_SWX_BOND_AI_ISMA_YEAR', 6);
define('MATHFINANCE_SWX_BOND_AI_ISMA_99N', 7);
define('MATHFINANCE_SWX_BOND_AI_ISMA_99U', 8);
define('MATHFINANCE_SWX_BOND_AI_KENYA', 9);
define('MATHFINANCE_SWX_BOND_AI_CBK_KENYA', 10);
use rhossis\mathfinance\MathFinance\abstractclass\Swx\BondAccruedInterest;
$d1M1Y1 = '2013-12-31';
$d2M2Y2 = '2014-06-30';
$d3M3Y3 = '2014-12-31';
$fValue = 1;
$maturityDate = '2014-12-31';
$bondObj = new BondAccruedInterest();
$dCM = MATHFINANCE_SWX_BOND_AI_SPEC_GERMAN;
$interestFactor = $bondObj->accruedInterestFactor($dCM, $d1M1Y1, $d2M2Y2, $d3M3Y3, $fValue, $maturityDate);
> A detailed guide to the formulas and logic for computing bond interest for fixed income instruments including actual/actual, 30/360, and RFR-based methods.
$mfo = new rhossis\mathfinance\MathFinance();
$mfo->effectiveRate($nominal_rate, $npery);
$mfo->nominalRate($effect_rate, $npery);
$mfo->presentValue($rate, $nper, $pmt, $fv = 0, $type = 0);
$mfo->futureValue($rate, $nper, $pmt, $pv = 0, $type = 0);
$mfo->payment($rate, $nper, $pv, $fv = 0, $type = 0);
$mfo->periods($rate, $pmt, $pv, $fv = 0, $type = 0);
$mfo->rate($nper, $pmt, $pv, $fv = 0, $type = 0, $guess = 0.1);
$mfo->interestPayment($rate, $per, $nper, $pv, $fv = 0, $type = 0);
$mfo->principalPayment($rate, $per, $nper, $pv, $fv = 0, $type = 0);
$mfo->interestAndPrincipal($rate, $per, $nper, $pv, $fv, $type);
$mfo->netPresentValue($rate, $values);
$mfo->internalRateOfReturn($values, $guess = 0.1);
$mfo->modifiedInternalRateOfReturn($values, $finance_rate, $reinvest_rate);
$mfo->daysDifference($date1, $date2, $basis);
$mfo->daysPerYear($year, $basis);
$mfo->tBillYield($settlement, $maturity, $pr);
$mfo->tBillPrice($settlement, $maturity, $discount);
$mfo->tBillEquivalentYield($settlement, $maturity, $discount);
$mfo->discountRate($settlement, $maturity, $pr, $redemption, $basis = 0);
$mfo->priceDiscount($settlement, $maturity, $discount, $redemption, $basis = 0);
$mfo->depreciationFixedDeclining($cost, $salvage, $life, $period, $month = 12);
$mfo->depreciationStraightLine($cost, $salvage, $life);
Unit tests are provided using PHPUnit.
BSD-3-Clause
| File | Role | Description | ||
|---|---|---|---|---|
| Data | Auxiliary data | |||
| Data | Auxiliary data | |||
| Data | Auxiliary data | |||
| Lic. | License text | |||
| Doc. | Documentation | |||
| The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
| Version Control | Unique User Downloads | |||||||
| 100% |
|
| Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.