I want to compute the volume weighted average price in time intervals (not for the entire day). For that I need either - 1) precise average_price, or 2) value traded for the day in each tick
@vineet_dhandhania You can calculate volume traded for each tick from WebSocket Feed, by subtracting current tick volume to last tick volume data. {'volume': 35901,last_price': 4762.0, 'timestamp': datetime.datetime(2018, 7, 23, 16, 13, 19)} {'volume': 35903,last_price': 4763.0,'timestamp': datetime.datetime(2018, 7, 23, 16, 13, 20)} Here, volume traded for 1 tick is 2 (35903-35901).
@rakeshr Thanks for replying. I already know what you mentioned. That is only 1 of the 2 needed inputs. Hence that doesn't solve my requirement.
I want to compute the volume weighted average price for an interval. For that I would need either 1) precise average price (before and after the interval), or 2) Traded value (before and after the interval), in addition to the volume (before and after the interval). I hope I was able to make myself clearer this time.
@vineet_dhandhania You can do summation multiplication of volume difference and last_price(use last_price,only if volume_difference > 0) and keep adding total volume with current tick volume(it will be divisor).Something like if volume_difference > 0: weighted_price=(volume_difference*last_price)+weighted_price total_volume=total_volume+volume_difference vwap=weighted_price/total volume
You can calculate volume traded for each tick from WebSocket Feed, by subtracting current tick volume to last tick volume data.
{
'volume': 35901
,last_price': 4762.0, 'timestamp': datetime.datetime(2018, 7, 23, 16, 13, 19)}{
'volume': 35903
,last_price': 4763.0,'timestamp': datetime.datetime(2018, 7, 23, 16, 13, 20)}Here, volume traded for 1 tick is 2 (35903-35901).
I want to compute the volume weighted average price for an interval. For that I would need either 1) precise average price (before and after the interval), or 2) Traded value (before and after the interval), in addition to the volume (before and after the interval). I hope I was able to make myself clearer this time.
You can do summation multiplication of volume difference and last_price(use last_price,only if volume_difference > 0) and keep adding total volume with current tick volume(it will be divisor).Something like if volume_difference > 0:
weighted_price=(volume_difference*last_price)+weighted_price
total_volume=total_volume+volume_difference
vwap=weighted_price/total volume