Skip to content
All library documents

Building a Forex Portfolio Model for Live Trading and Backtesting

Article QuantStart

Summary

This diary entry describes an attempt to build a portfolio component for an event-driven automated forex system connected to a broker API. The goal is to keep a local portfolio’s balance, realized and unrealized profit and loss, and open positions aligned with the practice account, so the same components can support both live trading and more realistic backtests. It explains pip-based profit calculations, exposure and average entry prices, and the roles of strategy, portfolio, price streaming, execution, and event handling components.

The implementation was still incomplete: it supported a GBP-denominated account and GBP/USD, and testing covered opening and closing long positions but not short positions. Local and broker balances still differed after trades. The account is therefore a development report, not evidence of a validated backtester. Its discussion is useful for understanding currency-specific P&L accounting and the need to reconcile simulated state against broker records, while its limitations call for broader currency, position-side, and unit testing before relying on results.

Key ideas

  • A local portfolio model can support both live trading and backtesting when it tracks account state in a way that can be reconciled with the broker.
  • Forex profit calculations depend on pip movement, traded units, exposure, and the account’s base currency.
  • The described system separates market data, signal generation, portfolio decisions, order execution, and event routing.
  • The implementation was limited to GBP base currency and GBP/USD, with testing restricted to long positions.
  • Differences between local and broker balances remained unresolved, so the implementation was not yet validated for dependable backtests.

Tags

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