---
title: "Per-trade P&L and ROI — Trading Analytics for Laravel | Roundly"
description: "Read a single trade’s pair, status, gross and net P&L and ROI, or serialize it to an array that carries both figures."
url: https://roundly-consulting.com/open-source/docs/trading-analytics-for-laravel/trade-helpers
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Trading Analytics for Laravel](https://roundly-consulting.com/open-source/docs/trading-analytics-for-laravel.md)

# Per-trade P&L and ROI

Each Trade computes its own figures — the same ones the engine aggregates. Every number comes back as a NumericValueAsString; the comments show its string form:

```php
$trade = Trade::make(
    baseCurrency: 'BTC',
    quoteCurrency: 'USD',
    openPrice: '40000',
    closePrice: '42000',
    size: '0.5',
    direction: 'buy',
    openTime: '2024-03-01 09:00',
    commission: '10',
    closeTime: '2024-03-01 15:00',
);

$trade->pair();         // 'BTC/USD'
$trade->isRealized();   // true — it has a close time
$trade->isOpen();       // false

$trade->profitAndLoss();                           // '1000.0000000000' — gross
$trade->profitAndLoss(subtractCommissions: true);  // '990.0000000000' — net

$trade->roi();                           // '5.00' — percent, 2 decimals
$trade->roi(subtractCommissions: true);  // '4.95'
$trade->roi(asPercentage: false);        // '0.0500000000' — a fraction
$trade->roi(asPercentage: false, scale: 20); // '0.05000000000000000000'
```

- P&L of a buy is (close price − open price) × size; of a sell, (open price − close price) × size.
- subtractCommissions: true subtracts the trade’s commission, when it has one.
- ROI divides the P&L by the position value (open price × size). By default it is a percentage rounded to 2 decimals; asPercentage: false returns the raw fraction, divided at the trade’s own amount scale — or at a higher one passed as the scale argument.
- Both are exact: the P&L keeps the trade’s amount scale, widened only when the exact result needs more decimals, so a tiny position never truncates to 0.

## As an array

toArray() includes the status flags and both P&L and ROI variants:

```php
$trade->toArray();
// [
//     'base_currency' => 'BTC',
//     'quote_currency' => 'USD',
//     'open_price' => '40000.0000000000',
//     'close_price' => '42000.0000000000',
//     'size' => '0.5000000000',
//     'direction' => 'buy',
//     'open_time' => '2024-03-01 09:00:00',
//     'close_time' => '2024-03-01 15:00:00',
//     'commission' => '10.0000000000',
//     'is_realized' => true,
//     'is_open' => false,
//     'pnl' => ['gross' => '1000.0000000000', 'net' => '990.0000000000'],
//     'roi' => ['gross' => '5.00', 'net' => '4.95'],
// ]
```

Trade also implements Jsonable and JsonSerializable, so toJson() and json\_encode() give the same payload.

## 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](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## 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.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/trading-analytics-for-laravel.md)
