agent0.chainsync.analysis.calc_position_value

Calculates the pnl.

Functions

calc_single_closeout(→ decimal.Decimal | float)

Calculate the closeout value for a single position.

calc_closeout_value(→ pandas.Series)

Calculate closeout value of agent positions.

fill_pnl_values(→ pandas.DataFrame)

Fills in the unrealized and realized pnl for each position.

Module Contents

agent0.chainsync.analysis.calc_position_value.calc_single_closeout(position: pandas.Series, interface: agent0.ethpy.hyperdrive.HyperdriveReadInterface, hyperdrive_state: agent0.ethpy.hyperdrive.state.PoolState, checkpoint_share_prices: pandas.Series, coerce_float: bool) decimal.Decimal | float

Calculate the closeout value for a single position.

Parameters:
  • position (pd.DataFrame) – The position to calculate the closeout value for (one row in current_wallet).

  • interface (HyperdriveReadInterface) – The hyperdrive read interface.

  • hyperdrive_state (PoolState) – The hyperdrive pool state.

  • checkpoint_share_prices (pd.Series) – A series with the index as checkpoint time and the value as the share prices.

  • coerce_float (bool) – If True, will coerce underlying Decimals to floats.

Returns:

The closeout position value. Type depends on the coerce_float argument.

Return type:

Decimal | float

agent0.chainsync.analysis.calc_position_value.calc_closeout_value(current_positions: pandas.DataFrame, checkpoint_info: pandas.DataFrame, interface: agent0.ethpy.hyperdrive.HyperdriveReadInterface, coerce_float: bool) pandas.Series

Calculate closeout value of agent positions.

Parameters:
  • current_positions (pd.DataFrame) – A dataframe resulting from get_current_wallet that describes the current wallet position.

  • checkpoint_info (pd.DataFrame) – A dataframe resulting from get_checkpoint_info that describes all checkpoints.

  • interface (HyperdriveReadInterface) – The hyperdrive read interface.

  • coerce_float (bool) – If True, will coerce underlying Decimals to floats.

Returns:

A series matching the current_wallet input that contains the values of each position.

Return type:

pd.Series

agent0.chainsync.analysis.calc_position_value.fill_pnl_values(in_df: pandas.DataFrame, db_session: sqlalchemy.orm.Session, interface: agent0.ethpy.hyperdrive.HyperdriveReadInterface, coerce_float: bool) pandas.DataFrame

Fills in the unrealized and realized pnl for each position.

Parameters:
  • in_df (pd.DataFrame) – A dataframe of positions from get_current_positions.

  • db_session (Session) – The database session.

  • interface (HyperdriveReadInterface) – The hyperdrive read interface attached to a hyperdrive pool.

  • coerce_float (bool) – If True, will coerce all numeric columns to float.

Returns:

The in_df with unrealized value and pnl columns added.

Return type:

pd.DataFrame