erc_4626.profit_and_loss
Documentation for eth_defi.erc_4626.profit_and_loss Python module.
Calculate ERC-4626 vault APY, or profitability.
Read tutorial ERC-4626: historical APY of a vault
Read tutorial ERC-4626: current APY of a vault
See about APY.
Functions
|
Uses archive node and share price to calculate. |
|
Get the real-time vault profitability. |
Classes
Capture the data needed for the vault profitability calculation. |
- class ERC4626Profitability
Bases:
objectCapture 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
- get_time_range()
Get the time range of the profitability data.
- Returns
Tuple of start and end timestamps.
- Return type
- get_block_range()
Get the block range of the profitability data.
Get the share price range of the profitability data.
- Returns
Tuple of start and end share prices.
- Return type
- __init__(vault, start_block, end_block, share_prices, timestamps)
- Parameters
vault (eth_defi.erc_4626.vault.ERC4626Vault) –
start_block (int) –
end_block (int) –
share_prices (dict[int, decimal.Decimal]) –
timestamps (dict[int, datetime.datetime]) –
- 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
vault (eth_defi.erc_4626.vault.ERC4626Vault) –
start_block (int) –
end_block (int) –
- Return type
- 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
vault (eth_defi.erc_4626.vault.ERC4626Vault) – ERC-4626 vault to estimate profitability for.
lookback_window (datetime.timedelta) – How far back we do we look for profitability calculation.
- Returns
Profitability data instance.
- Return type