NewWe open-sourced 50+ Laravel packages
Custom AI apps, agents and automation — Roundly ConsultingRoundly
All packages

The package works with zero configuration; publishing the config file only lets you change the defaults in one place. The published config/trading-analytics.php:

return [
    // Default decimal precision (bcmath scale) for every calculation.
    'scale' => env('TRADING_ANALYTICS_SCALE', 10),

    // Default win-rate bucketing period: daily, weekly, or monthly.
    'win_rate_period' => env('TRADING_ANALYTICS_WIN_RATE_PERIOD', 'daily'),
];

Every key

KeyTypeDefaultEnvPurpose
scaleint10TRADING_ANALYTICS_SCALEDecimal places used when a run does not call ->scale(). A whole number of at least 0 (TRADING_ANALYTICS_SCALE=8 works); a blank value (TRADING_ANALYTICS_SCALE=) is not set, so 10 applies; ten or 10.5 throw an InvalidConfigurationException naming the key.
win_rate_periodstringdailyTRADING_ANALYTICS_WIN_RATE_PERIODWin-rate bucket when a run does not call ->usingWinRatePeriod(): daily, weekly or monthly. A blank value is not set, so daily applies; anything else throws an InvalidConfigurationException listing them — a typo never falls back to daily.

Environment

Both keys are env-driven, so you rarely need to publish the file at all:

TRADING_ANALYTICS_SCALE=4
TRADING_ANALYTICS_WIN_RATE_PERIOD=weekly

Per-run overrides

A run’s explicit ->scale(...) / ->usingWinRatePeriod(...) always overrides the configured default:

use RoundlyConsulting\TradingAnalytics\Enums\Period;
use RoundlyConsulting\TradingAnalytics\Facades\TradingAnalytics;

// A run's own settings always win over the configured defaults
$analytics = TradingAnalytics::for($trades)
    ->scale(2)
    ->usingWinRatePeriod(Period::WEEKLY)
    ->calculate();

$analytics->getScale(); // 2

The configured defaults are read when the engine is built, so a malformed scale or win_rate_period throws InvalidConfigurationException even for a run that then sets its own ->scale() or ->usingWinRatePeriod().

Outside a booted Laravel app (no config bound), the built-in defaults — scale 10 and daily — apply automatically, so the engine also runs in plain scripts and unit tests.

Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

More ways to support, including crypto

By donating, you agree to our donation terms.

Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.