Skip to content

Instantly share code, notes, and snippets.

@lucasastorian
Last active June 20, 2021 17:52
Show Gist options
  • Select an option

  • Save lucasastorian/25d67a510aca85e9c619b3311d52246d to your computer and use it in GitHub Desktop.

Select an option

Save lucasastorian/25d67a510aca85e9c619b3311d52246d to your computer and use it in GitHub Desktop.
def calculate_vpin(buy_volume: pd.Series, sell_volume: pd.Series, window_size: int) -> pd.Series:
"""Calculates VPIN over a historical window
Args:
buy_volume (pd.Series): A Series of containing the classified Buy-Volume in each Volume-Bar
sell_volume (pd.Series): A Series containing the classified Sell-Volume in each Volume-Bar
window_size (int): The historical window over which to estimate VPIN
Returns:
VPIN (pd.Series): A Series containing the calculated VPIN values
"""
vpin = buy_volume.sub(sell_volume).abs().rolling(window_size).mean()
vpin /= buy_volume + sell_volume
return vpin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment