PHPackages                             ksfraser/portfolio-math - 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. ksfraser/portfolio-math

ActiveLibrary

ksfraser/portfolio-math
=======================

Portfolio performance calculations: TWR, IRR, drawdown, volatility, asset allocation. Shared library for stockmarket, FrontAccounting, ksfii\_app.

v1.0.1(yesterday)01↑2900%MITPHPPHP &gt;=7.4

Since Jul 30Pushed yesterdayCompare

[ Source](https://github.com/ksfraser/portfolio-math)[ Packagist](https://packagist.org/packages/ksfraser/portfolio-math)[ RSS](/packages/ksfraser-portfolio-math/feed)WikiDiscussions master Synced today

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

ksfraser/portfolio-math
=======================

[](#ksfraserportfolio-math)

Shared portfolio performance calculation library for the KSF stack.

What It Is
----------

[](#what-it-is)

A Composer package implementing portfolio performance algorithms extracted from [portfolio-performance/portfolio](https://github.com/portfolio-performance/portfolio). All business logic lives here; app-layer wrappers (stockmarket, ksfii\_app, FrontAccounting) only map data to the interfaces and display results.

Consuming Apps
--------------

[](#consuming-apps)

AppRole`ksf_stockmarket`PHP/Apache bare-metal; computes TWR/IRR for holdings dashboard`ksfii_app`WealthSystem forecasting; consumes performance metrics for scenarios`FrontAccounting` (`ksf-fa`)Pulls GL transactions → feeds package → dashboard widgetFacilities
----------

[](#facilities)

FeatureClassTWR (True Time-Weighted Return)`KSF\Performance\Services\TWRCalculatorService`IRR (Internal Rate of Return)`KSF\Performance\Services\IRRCalculatorService`Max Drawdown`KSF\Performance\Services\DrawdownCalculatorService`Volatility / Semi-deviation`KSF\Performance\Services\VolatilityCalculatorService`Composability
-------------

[](#composability)

Apps write an adapter that implements `TransactionRepositoryInterface`:

```
final class StockmarketRepository implements TransactionRepositoryInterface {
    public function findByPortfolioAndRange(string $id, DateTimeInterface $start, DateTimeInterface $end): array { ... }
    public function findValuationsByPortfolioAndRange(string $id, DateTimeInterface $start, DateTimeInterface $end): array { ... }
}
```

Then:

```
$twr = new TWRCalculatorService(new StockmarketRepository());
$result = $twr->calculate('P1', '2026-01-01', '2027-01-01');
echo $result->getTWR();
```

Installation
------------

[](#installation)

```
composer require ksfraser/portfolio-math
```

Tests
-----

[](#tests)

```
vendor/bin/phpunit --bootstrap tests/bootstrap.php tests/
```

Target: 16/16 pass.

Notes
-----

[](#notes)

- Follow `ksf(report):` commit prefix for any changes to reporting/math features.
- New requirements are individual files in `ProjectDcs/`.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance100

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

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

2

Last Release

1d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c8870cc04b29a973eed9ad367a936ab274d744de37ff0c35fa0540a932905271?d=identicon)[ksfraser](/maintainers/ksfraser)

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ksfraser-portfolio-math/health.svg)

```
[![Health](https://phpackages.com/badges/ksfraser-portfolio-math/health.svg)](https://phpackages.com/packages/ksfraser-portfolio-math)
```

PHPackages © 2026

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