What you will learn
- Position lots
- Fees and financing
- Realized and unrealized P&L
- Cash and margin state
Position lots
Lot accounting determines how entries and exits are matched. FIFO, average-cost or another convention can change intermediate realized P&L while total economics still need reconciliation. State the chosen method and preserve raw executions.
Fees and financing
Fees and financing should be applied at the events or intervals defined by the model. Distinguish per-side charges from costs already represented in fill prices. Include currency conversion under an explicit convention.
Realized and unrealized P&L
Realized and unrealized P&L contribute differently to balance and equity. A simulator must mark open positions consistently and avoid recognizing the same price movement twice when a position closes.
Cash and margin state
Cash and margin state can constrain which orders are allowed or force liquidation under modeled rules. A strategy that ignores funding obligations can appear feasible even when its path could not be maintained.
Worked example
A position has an unrealized gain of 20 immediately before closing at the same mark. After close, realized P&L rises by 20 and unrealized P&L falls by 20; equity should not gain another 20 solely from the reclassification.
Try it yourself
Write an accounting invariant for closing a position at the current mark with no additional costs.
Show the worked solution
Equity should remain unchanged by the realized/unrealized transfer alone. Quantity becomes zero and the gain moves into realized accounting. Any equity change requires a new price, cost or cash-flow event.
Apply this to your course project
Implement or specify a simulator and demonstrate its behavior on adversarial price paths.
Keep the calculation inputs, assumptions and decisions with your work. Practical exercises are self-reviewed; the scored knowledge checks assess the questions shown, not an independent certification of practical competence.