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

Direction & Period enums

Two string-backed enums: Direction (BUY = buy, SELL = sell) and Period (DAILY, WEEKLY, MONTHLY). Their domain methods:

use Illuminate\Support\Carbon;
use RoundlyConsulting\TradingAnalytics\Enums\Direction;
use RoundlyConsulting\TradingAnalytics\Enums\Period;

Direction::BUY->isBuy();     // true
Direction::SELL->isSell();   // true
Direction::from('sell');     // Direction::SELL

Period::DAILY->bucketFor(Carbon::parse('2024-03-05'));   // '2024-03-05'
Period::WEEKLY->bucketFor(Carbon::parse('2024-03-05'));  // '2024-W10'
Period::MONTHLY->bucketFor(Carbon::parse('2024-03-05')); // '2024-03'

Select and validation helpers

Both enums adopt the shared helper toolkit from enums-for-laravel, so they expose a full select/validation surface out of the box. Labels go through Laravel’s translator:

Direction::validationRule();   // "in:buy,sell"
Period::validationRule();      // "in:daily,weekly,monthly"

Period::toOptions()->all();    // ['daily' => 'Daily', 'weekly' => 'Weekly', 'monthly' => 'Monthly']
Direction::options();          // Collection<EnumOption{value,label,name}> for JS/Inertia selects
Period::labels()->all();       // ['Daily', 'Weekly', 'Monthly']
Period::values()->all();       // ['daily', 'weekly', 'monthly']

For example, to let users choose the reporting period:

$validated = $request->validate([
    'period' => ['nullable', Period::validationRule()],
]);

$analytics = TradingAnalytics::for($trades)
    ->usingWinRatePeriod(Period::from($validated['period'] ?? 'daily'))
    ->calculate();

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.