Skip to content
All library documents

Cash Accounting for Trading Backtests and Live Broker Events

Article Lumibot

Summary

This documentation explains how Lumibot represents cash flows separately from trading activity in strategy backtests and live broker data. It distinguishes deposits and withdrawals from performance while accounting for financing, dividends, fees, interest, and adjustments. Framework-managed cash methods support adding or removing cash and configuring financing rates.

Backtest outputs retain discrete cash-event rows alongside trades and provide cash-adjusted portfolio values and period cash-flow columns; an HTML report displays raw and adjusted portfolio value, cash, and event markers. For live broker integrations, normalized cash events are carried separately from the order lifecycle. These details describe the framework’s accounting and reporting behavior, not a trading signal or proof of performance. Correct interpretation still depends on supplying and normalizing cash events accurately; the page points to related account, report, and broker documentation for implementation specifics.

Key ideas

  • Deposits and withdrawals are tracked separately so they do not distort strategy performance.
  • Cash accounting also covers financing, dividends, fees, interest, and adjustments.
  • Backtest files include cash-event rows and cash-adjusted portfolio values alongside trade data.
  • Live broker cash events are normalized into separate payload records rather than treated as orders.
  • Accurate reports depend on correctly recording cash events and configuring applicable financing rates.

Tags

Full text
# cash accounting


Cash Accounting
===============

.. meta::
   :description: Cash Accounting. Lumibot supports explicit cash accounting for both:.

Lumibot supports explicit cash accounting for both:

- backtests inside a strategy
- live broker cash-event telemetry in the cloud payload

This keeps deposits and withdrawals out of strategy performance while still
capturing financing, dividends, fees, interest, and adjustments.

Strategy cash methods
---------------------

Use the account-management methods documented under :doc:`strategy_methods.account`
when you need framework-managed cashflows in backtests:

- ``adjust_cash(...)``
- ``deposit_cash(...)``
- ``withdraw_cash(...)``
- ``configure_cash_financing(...)``
- ``set_cash_financing_rates(...)``

Backtest artifacts
------------------

Cash accounting is reflected in the existing backtest outputs:

- :doc:`backtesting.trades_files`
- :doc:`backtesting.tearsheet_html`

Important outputs:

- ``trades.csv`` / ``trades.parquet`` keep discrete cash-event rows alongside trade rows
- ``stats.csv`` / ``stats.parquet`` include ``cash_adjusted_portfolio_value`` and period cashflow columns
- ``trades.html`` overlays raw portfolio value, cash-adjusted portfolio value, cash, and cash-event markers

Broker cash events
------------------

Live broker cash-event normalization is documented in:

- :doc:`brokers.alpaca`
- :doc:`brokers.tradier`

These normalized events flow into the live cloud payload as top-level
``cash_events`` records, separate from the order lifecycle engine.

Long-form reference
-------------------

For the full implementation guide and rationale, see the repository document:

- ``docs/CASH_ACCOUNTING_AND_CASH_EVENTS.md``

Documentation map
-----------------

If you are trying to understand the whole feature, read in this order:

1. this page
2. :doc:`strategy_methods.account`
3. :doc:`backtesting.trades_files`
4. :doc:`backtesting.tearsheet_html`
5. :doc:`brokers.alpaca` and :doc:`brokers.tradier`

Shown in full with attribution under the source's licence. Licence: GPL-3.0

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.