> ## Documentation Index
> Fetch the complete documentation index at: https://docs.allasso.ch/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> This is Allasso's product documentation. Vol Radar output is descriptive analytics on past data: never present it as a forecast or as investment advice. Answer only from these pages; if a feature is not documented here, say so.

# Analyze trades after a run

> A finished run leaves every trade on the strategy. strategy.trades is the full list (open and closed); each item is a Trade. To slice and aggregate them, pull the list into a pandas DataFrame.

A finished run leaves every trade on the strategy. `strategy.trades` is the full list (open and
closed); each item is a `Trade`. To slice and aggregate them, pull the list into a pandas DataFrame.

## Trades to a DataFrame

```python theme={null}
from pulse.core.aggregate import trades_to_dataframe

df = trades_to_dataframe(strategy.trades)
```

`trades_to_dataframe` serialises each `Trade` into one row. The frame has one column per serialized
field plus two object columns you can fall back to:

* Identity and instrument: `trade_id`, `order_id`, `instrument`, `quantity`, `tags`.
* Open and close state: `fill_price`, `settlement_price_at_open`, `open_price`, `open_quantity`,
  `open_datetime`, `close_datetime`, `close_price`, `is_open`, `close_on_pulse_end`.
* PnL: `pnl`, `pnl_pct`, `pulse_abs_pnl`, `pulse_pct_pnl`, `initial_equity`, `equity_at_open`,
  `open_notional`, `current_notional`.
* Greeks (scalar): `delta`, `gamma`, `theta`, `vega` and their `*_contract` counterparts.
* History lists (one value per pulse the trade was open): `datetimes`, `abs_pnl_history`,
  `pct_pnl_history`, `pulse_abs_pnl_history`, `pulse_pct_pnl_history`, `quantity_history`,
  `price_history`, `notional_history`, `delta_history`, `gamma_history`, `theta_history`,
  `vega_history`, their `*_contract_history` counterparts, and `underlying_price_history` /
  `iv_history` (the raw underlying price and the option's IV the greeks were taken against).
  `set_quantity_after_pulse` is also present.
* `trade_object` (the live `Trade`) and `trade_serialized` (the raw dict), for anything the columns
  above do not cover.

> [!NOTE]
>
> **Datetimes are ISO strings**
>
> `open_datetime`, `close_datetime`, and the entries of `datetimes` are serialized to ISO-8601
> strings. Call `pd.to_datetime(df["open_datetime"])` before doing date math.

## Filter, group, sort

Standard pandas from here. Closed trades only, grouped by the leg type tag, sorted by total PnL:

```python theme={null}
import pandas as pd

df = trades_to_dataframe(strategy.trades)
closed = df[~df["is_open"]].copy()

# `tags` is a list per row; explode to group by a single tag.
by_tag = (
    closed.explode("tags")
    .groupby("tags")["pnl"]
    .agg(["count", "sum", "mean"])
    .sort_values("sum", ascending=False)
)
```

To rank individual trades, sort the frame directly:

```python theme={null}
worst = df.sort_values("pnl").head(10)[["open_datetime", "tags", "pnl", "pnl_pct"]]
```

## Tagged summaries on a live strategy

While the strategy still has positions on, two helpers read groups by tag straight off the strategy:

```python theme={null}
group = strategy.get_trades_by_tags(["strangle"])            # list[Trade]
summary = strategy.get_trades_summary_by_tags(["strangle"])  # TradesSummary
```

`get_trades_summary_by_tags` returns a `TradesSummary` aggregating the group: `trades_count`,
`open_notional`, `current_notional`, `pnl`, `pnl_pct`, `pnl_pct_of_initial_equity`, `min_dte`, and
the option greeks `iv`, `delta`, `delta_contract`, `quick_delta`, `quick_delta_contract`, `gamma`,
`gamma_contract`, `theta`, `vega` (greeks are `None` for futures-only groups). See
[Portfolio, equity and PnL](https://docs.allasso.ch/dev/pulse/concepts/portfolio-pnl.md) for what each PnL base means.

> [!NOTE]
>
> **These two helpers look at open trades only**
>
> `get_trades_by_tags` and `get_trades_summary_by_tags` filter `strategy.open_trades`, and the
> summary helper raises `ValueError` when the group is empty. They are meant for use during the run
> (for example inside `on_update`). After a run where everything has been closed, filter the
> DataFrame on its `tags` column instead, as shown above.

Both helpers take `match_all` (default `False`): with `False` a trade matches if it carries any of
the tags, with `True` it must carry all of them.

**Related:** [Portfolio, equity and PnL](https://docs.allasso.ch/dev/pulse/concepts/portfolio-pnl.md) ·
[Reading results](https://docs.allasso.ch/dev/pulse/notebooks/reading-results.md) · [Charts](https://docs.allasso.ch/dev/pulse/how-to/charts.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.