LaravelPackages.net
Acme Inc.
Toggle sidebar
roundly-consulting/trading-analytics-for-laravel

Calculate trading performance analytics — P&L, returns, streaks, profit factor — for Laravel.

6
5
1.1.1
About roundly-consulting/trading-analytics-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 Analytics for Laravel — Roundly open source

Latest release Tests Code style Donate Patreon Crypto

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.

Donate to Roundly open source Become a patron on Patreon Donate crypto: BTC, ETH, BNB or SOL

License

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

Comments