How to calculate volume profile in algo

I wanted to I wanted to calculate volume profile with poc etc , how to calculate it

Hi @Shailesh_Sharma ,

Refer the below sample code to calculate volume profile with poc:

import pandas as pd
import numpy as np

def volume_profile_with_poc(df, price_col='Close', volume_col='Volume', bin_size=1.0):

    # Bin price range
    bins = np.arange(df[price_col].min(), df[price_col].max() + bin_size, bin_size)
    df['Bin'] = pd.cut(df[price_col], bins=bins)

    # Volume sum per bin
    profile = df.groupby('Bin')[volume_col].sum().reset_index()
    profile['Price'] = profile['Bin'].apply(lambda x: (x.left + x.right) / 2)

    # Find POC
    poc_price = profile.loc[profile[volume_col].idxmax(), 'Price']

    return profile[['Price', volume_col]], poc_price

Example usage:

vp, poc = volume_profile_with_poc(df, price_col='Close', volume_col='Volume', bin_size=1)
print("POC:", poc)
print(vp.head())