Last active
June 20, 2021 17:52
-
-
Save lucasastorian/25d67a510aca85e9c619b3311d52246d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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