BaseTVLSizeRiskModel#

API documentation for tradeexecutor.strategy.tvl_size_risk.BaseTVLSizeRiskModel Python class in Trading Strategy framework.

class BaseTVLSizeRiskModel[source]#

Bases: SizeRiskModel

A trade sizer that uses % of TVL of the target pool as the cap.

  • Reads TVL estimation and uses that to set the maximum size for a trade

  • Used in backtesting - fast to test as we do not need to query the historical liquidity from the archive node to get the accurate price impact

__init__(pricing_model, per_trade_cap=1.0, per_position_cap=1.0)[source]#
Parameters:
  • per_trade_cap (float) – Maximum US dollar value of a single trade, or unlimited.

  • pricing_model (PricingModel) –

  • per_position_cap (float) –

Methods

__init__(pricing_model[, per_trade_cap, ...])

param per_trade_cap:

get_acceptable_size_for_buy(timestamp, pair, ...)

get_acceptable_size_for_position(timestamp, ...)

What this the maximum position amount.

get_acceptable_size_for_sell(timestamp, ...)

get_pair_cap(pair, sizing_type)

Get cap for an individual trade for a pair.

get_tvl(timestamp, pair)

Read the TVL from the underlying pricing model.

__init__(pricing_model, per_trade_cap=1.0, per_position_cap=1.0)[source]#
Parameters:
  • per_trade_cap (float) – Maximum US dollar value of a single trade, or unlimited.

  • pricing_model (PricingModel) –

  • per_position_cap (float) –

get_pair_cap(pair, sizing_type)[source]#

Get cap for an individual trade for a pair.

  • Different pool types can have different caps because of CLMM has better capital efficiency

Parameters:
Return type:

float

get_acceptable_size_for_position(timestamp, pair, asked_value)[source]#

What this the maximum position amount.

  • Avoid exceed maximum position size

  • If the position size is exceeded start to reduce the position

Parameters:
  • timestamp (Optional[Union[datetime, Timestamp]]) –

    Historical timestamp.

    Can be set to None for onchain reading backends, and they will use the latest block number.

  • asked_value (float) – How large position we’d like to have in the US Dollar terms.

  • pair (TradingPairIdentifier) –

Returns:

Size-risk adjusted estimation how large the position could be.

Return type:

SizeRisk

abstract get_tvl(timestamp, pair)[source]#

Read the TVL from the underlying pricing model.

Parameters:
Return type:

float