SizeRisk#
API documentation for tradeexecutor.state.size_risk.SizeRisk Python class in Trading Strategy framework.
- class SizeRisk[source]#
Bases:
object
Result of a price impact estimation during decide_trades().
Used by py:class:~tradeexecutor.strategy.trade_sizer.TradeSizer to return the estimations of the safe trade sizes (not too much price impact, not too much liquidity risk)
Capture and save data about the price impact, so we can diagnose this later. Not just the result, but the variables that lead to the result.
Allows us to use this to cap the max position size when we enter to a position.
Note
A position size is different from a trade size, as we may grow a larger position using a multiple trades to enter
See also
tradeexecutor.strategy.trade_pricing
for price impact / slippage analysistradeexecutor.strategy.alpha_model.AlphaModel.normalise_weights()
to haveportfolio specific weight % cap for each position
- __init__(timestamp, pair, sizing_type, path, capped, block_number=None, mid_price=None, avg_price=None, asked_quantity=None, asked_size=None, accepted_quantity=None, accepted_size=None, diagnostics_data=None)#
- Parameters:
timestamp (datetime.datetime | None) –
pair (TradingPairIdentifier) –
sizing_type (SizingType) –
path (list[tradeexecutor.state.identifier.TradingPairIdentifier]) –
capped (bool) –
block_number (int | None) –
mid_price (float | None) –
avg_price (float | None) –
asked_quantity (decimal.Decimal | None) –
asked_size (float | None) –
accepted_quantity (decimal.Decimal | None) –
accepted_size (float | None) –
diagnostics_data (dict | None) –
- Return type:
None
Methods
__init__
(timestamp, pair, sizing_type, path, ...)from_dict
(kvs, *[, infer_missing])from_json
(s, *[, parse_float, parse_int, ...])schema
(*[, infer_missing, only, exclude, ...])to_dict
([encode_json])to_json
(*[, skipkeys, ensure_ascii, ...])Attributes
For which timepoint this price impact estimation was made
pair
Buy or sell
Path of the trade One trade can have multiple swaps if there is an intermediary pair.
Was this trade hitting the maximum cap.
Block number we used for onchain estimation
Venue mid price per token
Avg price per token when accepted size is filled
How much we want to get
How much we want to get
What was the capped size by the
What was the capped size
Store various diagnostics data items ehre
- timestamp: datetime.datetime | None#
For which timepoint this price impact estimation was made
Can be set to None if not relevant.
- sizing_type: SizingType#
Buy or sell
- path: list[tradeexecutor.state.identifier.TradingPairIdentifier]#
Path of the trade One trade can have multiple swaps if there is an intermediary pair.
- capped: bool#
Was this trade hitting the maximum cap.
This means the trade size was reduced due to risk.
- asked_quantity: decimal.Decimal | None#
How much we want to get
- accepted_quantity: decimal.Decimal | None#
What was the capped size by the
- diagnostics_data: dict | None#
Store various diagnostics data items ehre
Each implementation can store e.g. percents
- __init__(timestamp, pair, sizing_type, path, capped, block_number=None, mid_price=None, avg_price=None, asked_quantity=None, asked_size=None, accepted_quantity=None, accepted_size=None, diagnostics_data=None)#
- Parameters:
timestamp (datetime.datetime | None) –
pair (TradingPairIdentifier) –
sizing_type (SizingType) –
path (list[tradeexecutor.state.identifier.TradingPairIdentifier]) –
capped (bool) –
block_number (int | None) –
mid_price (float | None) –
avg_price (float | None) –
asked_quantity (decimal.Decimal | None) –
asked_size (float | None) –
accepted_quantity (decimal.Decimal | None) –
accepted_size (float | None) –
diagnostics_data (dict | None) –
- Return type:
None