PHPackages                             rhossis/mathfinance - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. rhossis/mathfinance

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

rhossis/mathfinance
===================

Package for financial math functions

v4.0.2(1y ago)11BSD-3-ClausePHPPHP &gt;=7.4.0

Since May 27Pushed 1y ago1 watchersCompare

[ Source](https://github.com/rhossis/mathfinance)[ Packagist](https://packagist.org/packages/rhossis/mathfinance)[ Docs](https://github.com/rhossis/mathfinance)[ RSS](/packages/rhossis-mathfinance/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (1)Versions (5)Used By (0)

🧮 math
======

[](#-math)

Package for financial math functions

📘 Description
-------------

[](#-description)

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.

---

💾 Installing
------------

[](#-installing)

### 📦 Install application via Composer

[](#-install-application-via-composer)

```
require "rhossis/mathfinance" : "^4.0.0"
```

---

🚀 Usage
-------

[](#-usage)

### 📖 Overview

[](#-overview)

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.

---

### 🧱 Named Constants

[](#-named-constants)

```
// 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);
```

---

### 🧮 Using the Math Package

[](#-using-the-math-package)

#### 🔁 Calculating Accrued Interest on Bonds

[](#-calculating-accrued-interest-on-bonds)

```
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);
```

---

### 📈 Bond Interest Calculation Guide

[](#-bond-interest-calculation-guide)

> 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.

[📘 View Full Guide](BOND_INTEREST_CALCULATION_GUIDE.md)

---

### 🔢 Computing Financial Math

[](#-computing-financial-math)

```
$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);
```

---

### 🧪 Testing

[](#-testing)

Unit tests are provided using PHPUnit.

---

### 🤝 Contribute

[](#-contribute)

- Fork the project :)
- Email \[@rhossis\].
- Contributors will be credited in the project.

---

### ⚖️ License

[](#️-license)

**BSD-3-Clause**

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance46

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

402d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/09103ea1b91963aa5f73d64473a315264746c96d899cd871efdc332d127bdee0?d=identicon)[rhossis](/maintainers/rhossis)

---

Top Contributors

[![cymapgt](https://avatars.githubusercontent.com/u/12482626?v=4)](https://github.com/cymapgt "cymapgt (4 commits)")

---

Tags

mathfinance

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rhossis-mathfinance/health.svg)

```
[![Health](https://phpackages.com/badges/rhossis-mathfinance/health.svg)](https://phpackages.com/packages/rhossis-mathfinance)
```

###  Alternatives

[brick/math

Arbitrary-precision arithmetic library

2.2k548.2M430](/packages/brick-math)[markrogoyski/math-php

Math Library for PHP. Features descriptive statistics and regressions; Continuous and discrete probability distributions; Linear algebra with matrices and vectors, Numerical analysis; special mathematical functions; Algebra

2.4k7.6M53](/packages/markrogoyski-math-php)[phpseclib/bcmath_compat

PHP 5.x-8.x polyfill for bcmath extension

16821.5M27](/packages/phpseclib-bcmath-compat)[torann/currency

This provides Laravel with currency functions such as currency formatting and conversion using up-to-date exchange rates.

4031.1M6](/packages/torann-currency)[rubix/tensor

A library and extension that provides objects for scientific computing in PHP.

2801.6M5](/packages/rubix-tensor)[jlawrence/eos

Parse and solve math equations without using 'eval()'.

1071.2M11](/packages/jlawrence-eos)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
