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

# Save and load results

> A finished Strategy carries its portfolio, broker, pulse index, and stats.

A finished `Strategy` carries its portfolio, broker, pulse index, and stats. The serializers in
`pulse.serializers` turn those objects into plain dicts (or a DataFrame) so you can persist a run to
disk, transport it between processes, or reload it later without re-running the backtest.

## Serialize a finished strategy

`StrategyDictSerializer.serialize` returns a JSON-friendly dict. Datetimes are kept as ISO strings, so
`json.dumps` with `default=str` covers the rest:

```python theme={null}
import json
from pulse.core.serializers import StrategyDictSerializer

data = StrategyDictSerializer.serialize(strategy)
with open("run.json", "w") as f:
    json.dump(data, f, default=str)
```

## Reload it

`deserialize` reconstructs the `Strategy`, including its portfolio, broker, pulse index, and stats:

```python theme={null}
import json
from pulse.core.serializers import StrategyDictSerializer

with open("run.json") as f:
    data = json.load(f)

strategy = StrategyDictSerializer.deserialize(data)
strategy.stats.annualized_sharpe_ratio   # metrics are restored, no re-run needed
```

> [!NOTE]
>
> **Plain `deserialize(data)` returns a results object**
>
> It is a base `Strategy` with no datafeed or resolver attached and no `on_update`. Use it to archive
> runs, hand results to another process, or load them into a notebook for analysis.

## Resume a run after a data update

A stored run can be continued once new settlements are prepared. Restore it onto your own strategy
class, extend its clock from a datafeed built **after** the update, and run with `resume=True`. Only
the new pulses run, and their PnL matches a continuous run over the whole calendar:

```python theme={null}
from pulse import common_settlements, create_local_components, run_sequentially

s = StrategyDictSerializer.deserialize(data, strategy=MyStrategy("COM.BRN"))
n = len(s.portfolio.datetimes)
datafeed, resolver = create_local_components()
s.pulse_index.extend(common_settlements(datafeed, s.underlying_id, start_datetime=s.last_pulse))
run_sequentially([s], initial_equity=1_000_000, datafeed=datafeed, resolver=resolver, resume=True)
new_pnl = s.portfolio.pulse_total_pnl_history[n:]   # one entry per new pulse
```

> [!WARNING]
>
> **What a resume does not carry**
>
> * Your subclass's constructor parameters and the attributes it sets on itself are not serialized.
>   Build it with the original parameters, and derive state from the book (or restore it yourself).
> * A fee calculator is not serialized: pass it back with `deserialize(..., fee_calculator=...)`.
> * Days already pulsed are final, and open trades keep the contract size they were opened with.
> * A datafeed opened before the update caches its file lists and finds no new dates. Without
>   `extend()`, or with a stale feed, the resume runs zero pulses (logged at info).
> * An `on_update` that treats the calendar's end as special (for example `close_all()` when
>   `not self.pulse_index.has_next()`) diverges once the clock is extended.
> * With a fee calculator, a trade expiring at the save point has its exit fee charged on the first
>   resumed pulse instead of the save pulse. Totals match unless `on_update` sizes off equity.

## Trades as a DataFrame

For tabular analysis or columnar storage, `TradeListPandasSerializer.serialize` turns a list of trades
into a pandas DataFrame (one row per trade, with the serialized fields as columns):

```python theme={null}
from pulse.core.serializers import TradeListPandasSerializer

df = TradeListPandasSerializer.serialize(strategy.trades)
df.to_parquet("trades.parquet")
df.to_csv("trades.csv", index=False)
```

`TradeListPandasSerializer.deserialize(df)` reverses it, returning the list of `Trade` objects.

> [!TIP]
>
> **Analysis vs persistence**
>
> For grouping, tagging, and per-leg summaries during analysis, prefer `trades_to_dataframe` (see
> [Analyze trades after a run](https://docs.allasso.ch/dev/pulse/how-to/analyze-trades.md)). Reach for `TradeListPandasSerializer` when you
> want a faithful, round-trippable dump of the trade objects.

## The other serializers

Every serializer exposes the same static `serialize` / `deserialize` pair and works standalone if you
only need one object:

| Serializer | Object |
| - | - |
| `StrategyDictSerializer` | `Strategy` (bundles the four below plus stats). |
| `PortfolioDictSerializer` | `Portfolio`. |
| `SimulationBrokerBrokerDictSerializer` | `SimulationBroker`. |
| `PulseIndexDictSerializer` | `PulseIndex`. |
| `TradeDictSerializer` | A single `Trade`. |
| `OrderDictSerializer` | An `Order`. |
| `InstrumentDictSerializer` | An `Instrument`. |
| `StatsDictSerializer` | `Stats`. |
| `TradeListPandasSerializer` | A list of trades, to/from a DataFrame. |

**Related:** [API overview - Serialization](https://docs.allasso.ch/dev/pulse/reference/api-overview.md#serialization) ·
[Analyze trades after a run](https://docs.allasso.ch/dev/pulse/how-to/analyze-trades.md) · [Reading results](https://docs.allasso.ch/dev/pulse/notebooks/reading-results.md)


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