trading_agent.risk.margin_estimator
¶
Estimates the margin an order blocks, with the rules UBI's own broker selector uses.
UBI has no route that returns an order's margin, but its documentation (architecture/broker-selection.md) states the rules its selector uses and how close they came to the brokers' calculators on 2026-09-30. The rates are deliberately high, because an estimate that is too high only refuses an order that could have gone through, while one that is too low lets through an order that is too large.
Typical usage example:
margin = MarginEstimator(margin_configuration).margin(request)
MarginEstimator
¶
Estimates margin from quantity, price, product and segment.
Creates the estimator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rates
|
MarginRatesConfiguration
|
The margin rates per kind of instrument. |
required |
Source code in src/trading_agent/risk/margin_estimator.py
margin
¶
Estimates the margin one order blocks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
OrderRequest
|
The order. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The estimated margin in rupees. |
Source code in src/trading_agent/risk/margin_estimator.py
derivative_rate
¶
The margin rate for a future, or for a sold option, by kind of underlying.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
segment
|
str
|
UBI's segment. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The rate, such as 0.15 for index derivatives. |