update_position_valuations#

API documentation for tradeexecutor.strategy.valuation_update.update_position_valuations Python function.

update_position_valuations(timestamp, state, universe, execution_context, valuation_model, routing_state, long_short_metrics_latest=None)[source]#

Revalue positions and update statistics.

  • Revalue all positions

  • Push new valuation update to onchain if needed (Lagoon)

  • Update statistics

A new statistics entry is calculated for portfolio and all of its positions and added to the state.

Example:

logger.info("Sync model is %s", sync_model)
logger.info("Trading university reserve asset is %s", universe.get_reserve_asset())

# Use unit_testing flag so this code path is easier to check
if sync_model.has_async_deposits() or unit_testing:
    logger.info("Vault must be revalued before proceeding, using: %s", sync_model.__class__.__name__)
    update_position_valuations(
        timestamp=ts,
        state=state,
        universe=universe,
        execution_context=execution_context,
        routing_state=routing_state,
        valuation_model=valuation_model,
        long_short_metrics_latest=None,
    )

# Sync any incoming stablecoin transfers
# that have not been synced yet
balance_updates = sync_model.sync_treasury(
    ts,
    state,
    list(universe.reserve_assets),
    post_valuation=True,
)

logger.info("We received balance update events: %s", balance_updates)

# Velvet capital code path
if sync_model.has_position_sync():
    sync_model.sync_positions(
        ts,
        state,
        universe,
        pricing_model
    )
Parameters: