I have a pandas dataframe with stock transactions which do not happen every day and not for each stock:
Goal is to get the (daily) weights of each stock for each day.
Starting table and expected result
This means - creating a full calendar of dates - repeating the cumulative shares for each stock on each date - and finally calculate the weight for this date
Would somone be able to help me on this? I was already searching through several threads but I am not able to find any working solution.
Awesome! This inspired me finding a way to solve the issue! The issue in your solution was that if a stock D appears (added in below set) in the initial dataset it won't work anymore.
I was able to solve this with the following: