calculate_volume_weighted_ohlcv#

API documentation for tradingstrategy.utils.aggregate_ohlcv.calculate_volume_weighted_ohlcv Python function.

calculate_volume_weighted_ohlcv(df)[source]#

Calculate volume weighted average prices (vwap) on OHLCV.

  • Assume input has multiple entries for each timestamp (index) separated by column “pair_id”

  • open, high, low, close columns are weighted by volume column

  • volume is the sum of all volume by timestamp

  • liquidity, if in the columns, is the sum of all liquidity by timestamp

            pair_id  open  high  low  close  volume  liquidity
timestamp
2020-01-01        1   100   100  100    100     500         10
2020-02-02        1   100   100  100    100     500         10
2020-01-01        2   110   110  110    110     250         20
2020-02-02        2   110   110  110    110     250         20
2020-02-02        3   200   200  200    200    1000         30
Parameters:

df (DataFrame) – Must have columns pair_id, timestamp, open, high, low, close, volume and optionally liquidity

Returns:

Aggregated open, high, low, close, volume, liquidity

Return type:

DataFrame