erc_4626.profit_and_loss

Documentation for eth_defi.erc_4626.profit_and_loss Python module.

Calculate ERC-4626 vault APY, or profitability.

Functions

estimate_4626_profitability(vault, ...[, ...])

Uses archive node and share price to calculate.

estimate_4626_recent_profitability(vault, ...)

Get the real-time vault profitability.

Classes

ERC4626Profitability

Capture the data needed for the vault profitability calculation.

class ERC4626Profitability

Bases: object

Capture the data needed for the vault profitability calculation.

calculate_profitability(annualise=True, year_in_seconds=31536000)

Get profitability for the whole duration of the sampling period.

This is the same as APY <https://tradingstrategy.ai/glossary/annual-percentage-yield-apy>__. But it’s incorrect to use term APY was some vaults may incur losses as well.

Parameters
  • annualise – If True, calculate profit % if we can maintain this profitability for a year.

  • year_in_seconds – Allow custom year durations.

Returns

Profitability as a percentage, either annualised or not.

0.07 means 7% APY.

Return type

float

get_time_range()

Get the time range of the profitability data.

Returns

Tuple of start and end timestamps.

Return type

tuple[datetime.datetime, datetime.datetime]

get_block_range()

Get the block range of the profitability data.

Returns

Tuple of start and end block numbers.

Return type

tuple[int, int]

get_share_price_range()

Get the share price range of the profitability data.

Returns

Tuple of start and end share prices.

Return type

tuple[decimal.Decimal, decimal.Decimal]

__init__(vault, start_block, end_block, share_prices, timestamps)
Parameters
Return type

None

estimate_4626_profitability(vault, start_block, end_block, sample_count=2)

Uses archive node and share price to calculate.

Get N samples of share price data.

  • Uses archive node to read historiocal share price for profitability calculation.

Parameters
Return type

eth_defi.erc_4626.profit_and_loss.ERC4626Profitability

estimate_4626_recent_profitability(vault, lookback_window)

Get the real-time vault profitability.

  • Uses block time to estimate the number of blocks in the sample duration for the profitability calculation.

See estimate_4626_profitability() for more details.

Parameters
Returns

Profitability data instance.

Return type

eth_defi.erc_4626.profit_and_loss.ERC4626Profitability