Separating Portfolio Accounting from Trade and Risk Handling
Summary
The article explains an event-driven backtesting design that separates a lean Portfolio class from a PortfolioHandler. The Portfolio stores cash and positions, updates position values after transactions, and calculates portfolio cash, equity, and realized and unrealized profit and loss. The handler is assigned coordination tasks such as applying position sizing and risk checks and sending orders for execution.
The article outlines the surrounding components, including strategies, price and execution handlers, events, and performance statistics. Its examples describe equity transactions and cite a unit test whose final cash and profit-and-loss figures are compared with brokerage demo-account records. The design is presented as an evolving software project, not as evidence of trading performance. At this stage it supports equities and ETFs; the article notes that further tests would be needed for instruments such as futures, options, and foreign exchange. Robustness, logging, monitoring, and richer results tools are also left for later development.
Key ideas
- A lean Portfolio can own position and cash accounting while a separate handler coordinates orders and risk checks.
- The portfolio recomputes cash, equity, and realized and unrealized profit and loss after position changes.
- Separating responsibilities makes financial calculations and component interactions easier to test independently.
- An event-driven backtester can connect strategies, market data, portfolio management, execution, and performance reporting.
- The described implementation and tests focus on equities and ETFs, with broader instrument support still needed.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.