Simulation Model
This document describes the technical specifications of the simulation engine for research purposes.
This service does not execute actual financial transactions or trades. It is intended solely for researching and validating algorithms on time-series data.
The following defines the preconditions, constraints, and specifications of the simulation engine. This information is necessary for interpreting backtest results.
Historical Data Format»
The engine operates on OHLC bar units. Tick data is not supported.
| Column Index | Field | Usage |
|---|---|---|
| 0 | Time | Timestamp (ms) |
| 1 | Open | (Not used in current version) |
| 2 | Close | Entry fill price, exit fill price, unrealized P&L evaluation |
| 3 | High | Buy-side TP hit check / Sell-side SL hit check / Trailing Stop updateBuy-side TP hit detection, Sell-side SL hit detection, Trailing Stop update |
| 4 | Low | Buy-side SL hit check / Sell-side TP hit check / Trailing Stop updateBuy-side SL hit detection, Sell-side TP hit detection, Trailing Stop update |
Order Fill Model»
All fills are executed at the Close price of the applicable bar. High/Low are used for TP/SL hit detection, but the fill price is the Close price, not the TP/SL limit level.
| Operation | Fill Price | Notes |
|---|---|---|
| Market Order (new) | Close ± commission_spread |
Buy: Close − spreadSell: Close + spread |
| Limit / Stop Order (trigger) | Close ± commission_spread |
Trigger condition evaluated by High/Low, fill at Close |
| TP/SL Hit (close) | Close |
Closed at Close price, not at the TP/SL level |
| Strategy Close / Force Close | Close |
Strategy close / Forced liquidation |
Intra-Bar Processing Order»
Processing is executed in the following order for each bar. All operations are atomic at the bar level.
- Load OHLC data for the new bar
- Update Trailing Stop (raise SL level based on High/Low)
- Recalculate unrealized P&L (Close-based)
- Pending Order (Limit/Stop) trigger evaluation and fill
- TP/SL hit check and position closing
- Margin ratio check and ticket acceptance availability update
- Force-close all positions if margin ratio exceeds threshold
Position Management»
In this system, each order is managed as an independent Ticket (trade ticket). A Ticket corresponds to a deal ticket in securities/FX trading, and one Ticket is issued per order. Even when placing multiple orders in the same direction, no netting is performed — each is tracked separately as an individual Ticket with its own P&L, holding period, etc.
Order Type»
| Order Type | Description |
|---|---|
| Market Order | Market order. Fills immediately at the current bar's Close price |
| Limit Order | Limit order. Fills at Close price when the specified price is reached (Buy: buy below current price, Sell: sell above current price) |
| Stop Order | Stop order. Fills at Close price when the specified price is breached (Buy: buy above current price, Sell: sell below current price) |
| Trailing Stop | Trailing Stop. Automatically raises the SL level as price moves favorably (Buy: follows High, Sell: follows Low). The SL level is only updated in the favorable direction and maintained during reversals |
Take Profit, Stop Loss, and Trailing Stop can be optionally attached to all order types.
Ticket Management»
| Specification | Description |
|---|---|
| Per-Ticket Management | Each order is created and managed as an independent Ticket. Multiple orders in the same direction are not netted — P&L, TP/SL, and holding period are tracked individually |
| Close Method | Close individually by specifying Ticket ID. Supports TP/SL auto-close, strategy manual close, and forced close |
| Partial Close | Supported. Partially close a ticket by specifying reduce_ratio (0.0–1.0)Supported. Partially close a Ticket by specifying reduce_ratio (0.0-1.0) |
| Hedging | Long and Short Tickets can be held simultaneously. However, margin calculation does not net — it simply sums the margin of all Tickets (see below) |
Margin & Leverage»
| Item | Formula / Specification |
|---|---|
| Required Margin | Σ (units × entryPrice / leverage) for all open tickets |
| Equity | Assets + Σ unrealizedPnLBuy: (Close − entryPrice) × unitsSell: (entryPrice − Close) × units |
| Margin Ratio | RequiredMargin / Equity |
Cost Model»
| Item | Specification |
|---|---|
| Commission / Spread | Applied once at entry as an absolute price difference. Buy: entryPrice = Close − spread、Sell: entryPrice = Close + spread |
| Exit Cost | None (closed at Close price, no additional cost) |
| Slippage Model | No explicit slippage model is implemented. The structure of using High/Low for TP/SL detection and filling at Close price inherently creates slippage-equivalent deviation |
Constraints & Assumptions»
| Item | Description |
|---|---|
| Deterministic Execution | The engine contains no random number generation and returns fully reproducible results for identical inputs |
| Numerical Precision | The WASM engine (C++) uses float32 arithmetic. Frontend Exit Analysis evaluation uses Math.fround() to match precision |
| Tick Data | Not supported. All processing is completed at the OHLC bar level |
| Multi-Asset | Not supported. Each simulation runs on a single asset |