Looking to hire Laravel developers? Try LaraJobs

trading-analytics-for-laravel maintained by roundly-consulting

Description
Calculate trading performance analytics — P&L, returns, streaks, profit factor — for Laravel.
Last update
2026/10/03 19:58 (dev-main)
License
Downloads
0

Comments
comments powered by Disqus

Trading Analytics for Laravel

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.

Installation

Requires PHP 8.4 with ext-bcmath, and Laravel 12 or 13.

composer require roundly-consulting/trading-analytics-for-laravel

Usage

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

Documentation

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.

Support our work

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.

License

The MIT License (MIT). Please see LICENSE.md for more information.