Files
tradon/modules/purchase_trade/docs_source/business/valuation-pnl-mtm.en.md
2026-05-14 14:31:23 +02:00

96 lines
2.6 KiB
Markdown

# Valuation, PnL, MTM
Status: `partial migration`
Language: `en`<br>
Mirror page: [valuation-pnl-mtm.md](valuation-pnl-mtm.md)
## BR-PT-VAL-001 - Valuation covers purchase, sale, and sale-first flows
Source: `BR-PT-004`, `BR-PT-006`, `BR-PT-011`
### Consultant Rule
PnL must exist for purchases and for sales, even when a sale is not yet matched
to a purchase.
### Developer Notes
- An unmatched `sale.line` must generate at least `sale priced`, `sale fee`,
and `derivative` when applicable.
- A basis sale with no price detail must still produce a zero line or the
economic fallback price according to the applicable rule.
- Do not arbitrarily attach a single sale when several sales are matched to the
same open balance.
## BR-PT-VAL-002 - Valuation references
Source: `BR-PT-005`
### Consultant Rule
The PnL reference must describe the nature of the valued line: purchase or sale,
open or physical.
### Developer Notes
- Allowed references: `Purchase/Open`, `Purchase/Physic`, `Sale/Open`,
`Sale/Physic`.
- A virtual lot must not be output with a physical reference.
## BR-PT-VAL-003 - MTM excludes fees
Source: `BR-PT-007`
### Consultant Rule
Mark-to-market applies to prices and derivatives, not to fees.
### Developer Notes
- MTM is allowed for `pur. priced`, `sale priced`, `derivative`.
- Fees are outside MTM: `pur. fee`, `sale fee`, `shipment fee`, `line fee`.
- For fees: `mtm_price`, `mtm`, `strategy` must stay empty.
## BR-PT-VAL-004 - Current snapshot and economic identity
Source: session `2026-05-14`
### Consultant Rule
`valuation_valuation_line` represents the latest known PnL image.
It is not a history table.
- A new generation replaces the previous generation for the same economic
reality.
- An unmatched sale owns its own PnL.
- A matched sale is owned by the linked purchase line.
- The PnL of a matched sale must not be generated twice: once from the sale
side and once from the purchase side.
### Developer Notes
- Before creating rows in `valuation.valuation.line`, delete the current
snapshot with the same economic identity.
- Economic identity:
- `sale_line` when present, otherwise `line`;
- `lot`;
- `type`;
- `reference`;
- `counterparty`;
- `product`;
- `state`;
- `strategy`.
- Do not include in the identity:
- `date`;
- `price`;
- `quantity`;
- `amount`;
- `mtm_price`;
- `mtm`.
- These fields are recalculated results and must be replaced by the latest
generation.
- `generate_from_sale_line()` does not create a sale snapshot when the
`sale.line` is already matched to a `purchase.line`; it redirects to the
owner purchase line generation.