Calculate trading performance analytics — P&L, returns, streaks, profit factor — for Laravel.
roundly-consulting/trading-analytics-for-laravel is a Laravel package for calculate trading performance analytics — p&l, returns, streaks, profit factor — for laravel..
It currently has 5 GitHub stars and 6 downloads on Packagist (latest version 1.1.1).
Install it with composer require roundly-consulting/trading-analytics-for-laravel.
Discover more Laravel packages by roundly-consulting
or browse all Laravel packages to compare alternatives.
Last updated
Trading performance analytics for Laravel — P&L, returns, drawdown, expectancy, streaks, Sharpe and
Sortino ratios and more, globally and per pair, base and quote currency. Feed it trades, rows or an
ordered query; every amount is computed with bcmath in a single pass, so there is no float drift
and memory stays flat however long the history is.
Requires PHP 8.4 with ext-bcmath, and Laravel 12 or 13.
composer require roundly-consulting/trading-analytics-for-laravel
Build trades from plain values (or read your own rows with Trade::fromRow()):
use RoundlyConsulting\TradingAnalytics\DataTransferObjects\Trade;
use RoundlyConsulting\TradingAnalytics\Enums\Direction;
$trades = [
Trade::make(baseCurrency: 'BTC', quoteCurrency: 'USD', openPrice: '45000.00', closePrice: '45500.00',
size: '0.1', direction: Direction::BUY, openTime: '2024-01-15 12:30', commission: '15.00', closeTime: '2024-01-15 14:30'),
Trade::make(baseCurrency: 'ETH', quoteCurrency: 'USD', openPrice: '2500.00', closePrice: '2450.00',
size: '2', direction: Direction::BUY, openTime: '2024-01-16 09:00', closeTime: '2024-01-16 11:00'),
];
Run the engine over them:
use Illuminate\Support\Facades\DB;
use RoundlyConsulting\TradingAnalytics\Facades\TradingAnalytics;
$analytics = TradingAnalytics::for($trades)->scale(2)->calculate();
// …or stream a query ordered by close time, one page of rows at a time:
$history = TradingAnalytics::calculate(
DB::table('trades')->where('user_id', $user->id)->orderBy('close_time')->orderBy('id'),
);
Read the figures — exact bcmath strings, ready to return as JSON:
$analytics->realizedProfitAndLoss->net->global->total->total->toRawString(); // "-65.00"
$analytics->wins->winRatio->global->total->toRawString(); // "0.50"
$analytics->volume->forPair('BTC/USD')->buy->total->toRawString(); // "0.10"
$analytics->maxDrawdown->percentage;
$analytics->riskAdjustedReturns->sharpeRatio;
return $analytics; // the full result matrix as JSON
The full documentation — configuration, every feature and its API, and testing — lives on our website: roundly-consulting.com/open-source/docs/trading-analytics-for-laravel
Release notes are in CHANGELOG.md. To contribute, see the contributing guide.
This package is free and open source, built and maintained by Roundly Consulting. If it saves you time, please consider supporting our open-source work — a one-time donation, a monthly pledge on Patreon or a crypto donation helps fund maintenance, new features and new packages.
The MIT License (MIT). Please see LICENSE.md for more information.