How nkastelan/ed works
Project type & purpose (what you’re diagramming)
This is a single-process C++ event-driven backtesting engine for trading strategies (“Ed”). The architecture is built around an event loop + event queue that routes market data updates through:
DataHandler → Strategy → Portfolio → ExecutionHandler, with events as the coupling mechanism.
It’s not a microservice system; it’s a modular in-process system where “components” are C++ classes/modules and “integration points” are events and data structures.
Read the file tree as architecture (map folders/files to components)
From the tree:
• Core engine / orchestration
• src/main.cpp (entrypoint; wires everything)
• src/backtest.hpp/.cpp (the backtest “engine” / coordinator; likely owns the event loop)
• Event system
• src/event.hpp/.cpp (event base types; probably MarketEvent, SignalEvent, OrderEvent, FillEvent etc.)
• Market data ingestion
• src/dataHandler.hpp/.cpp (reads CSV, emits market events)
• data/Binance_ETHUSDT_day.csv (example historical dataset input)
• Strategy layer
• src/strategies/strategy.hpp (interface/abstract base)
• src/strategies/tradingStrategy.cpp (actual strategy implementation)
• src/strategies/benchmark.cpp (baseline strategy; buy-and-hold / benchmark logic)
• Portfolio / risk / PnL
• src/portfolio.hpp/.cpp (positions, holdings, equity curve; turns signals into orders)
• Execution simulation
• src/executionHandler.hpp/.cpp (simulated broker/exchange; turns orders into fills)
• External/native dependency
• Dependencies/ta-lib/... (TA-Lib headers/lib; technical indicators; used by strategies)
CLI / App Entrypoint
• main.cpp
Backtest Engine / Event Loop
• backtest.*
• responsibilities: initialize components, maintain simulation time, pop/push events, stop conditions
Event Queue / Event Bus (in-process)
• could be a std::queue<Event> owned by backtest engine
Event Types
• event.* (define event hierarchy and payloads)
Data Handler
• dataHandler.*
• input: CSV in data/
• output: MarketEvents
Strategy (interface)
• strategies/strategy.hpp
Strategy Implementations
• strategies/tradingStrategy.cpp
• strategies/benchmark.cpp
Indicator Library (TA-Lib)
• Dependencies/ta-lib
• used by strategy implementation(s)
Portfolio
• portfolio.*
• tracks positions/holdings/cash; produces orders; updates on fills
Execution Handler
• executionHandler.*
• simulates fills, slippage/commission (if present), produces fill events
Outputs / Reporting (current + planned)
• currently may be stdout/logs; future: PDF reports, Monte Carlo, visualizations (from README)
Historical Data → DataHandler
• CSV (data/Binance_ETHUSDT_day.csv) → DataHandler
DataHandler emits Market events
• DataHandler → EventQueue: MarketEvent
Strategy consumes Market events and emits Signals
• EventQueue → Strategy: MarketEvent
• Strategy → EventQueue: SignalEvent
Portfolio consumes Signals and emits Orders
• EventQueue → Portfolio: SignalEvent
• Portfolio → EventQueue: OrderEvent
ExecutionHandler consumes Orders and emits Fills
• EventQueue → ExecutionHandler: OrderEvent
• ExecutionHandler → EventQueue: FillEvent
Portfolio consumes Fills and updates state
• EventQueue → Portfolio: FillEvent
• Portfolio updates: cash/positions/equity curve (internal state)
Backtest engine controls the loop
• Backtest repeatedly:
• asks DataHandler for next bar (or data tick)
• pushes events
• dispatches events until queue is empty
• advances time / terminates when data exhausted
• Event-Driven Architecture (EDA), in-process
• Queue-based dispatch loop
• Strategy Pattern
• strategy.hpp defines interface; multiple implementations (benchmark, tradingStrategy)
• Separation of concerns
• market data vs signal generation vs portfolio construction vs execution simulation
• Pluggability
• strategies interchangeable; execution handler can be swapped to model different fills; data handler can be extended for new sources
“Don’t overthink it” decomposition checklist (ensure you didn’t miss anything)
• Where the event queue lives (likely inside Backtest engine)
• Who creates and who consumes each event type
• The source of truth for portfolio state (Portfolio)
• The data source (CSV) and ingestion boundary (DataHandler)
• The indicator dependency (TA-Lib) and which module calls it (Strategy impl)
• The entrypoint wiring (main constructs the concrete strategy + handlers)