PHP code example of ksfraser / portfolio-math

1. Go to this page and download the library: Download ksfraser/portfolio-math library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ksfraser / portfolio-math example snippets


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

$twr = new TWRCalculatorService(new StockmarketRepository());
$result = $twr->calculate('P1', '2026-01-01', '2027-01-01');
echo $result->getTWR();
bash
vendor/bin/phpunit --bootstrap tests/bootstrap.php tests/