Cumulative weights with monthly rebalancing python

129
March 25, 2021, at 06:40 AM

I have real struggle here:

I have a dataframe with columns like this excel file, where PERMNO is each stock and weights are already calculated and sum up to 1 each day:

What i want to achieve is like the left column in this example with just two stocks, but for all stocks.

[]

If we look at the problem with only two stocks, what i want to do is achieved like this:

Wt = Wt-1*(1+rt)/sum(wt all stocks this t)

Stock 1 has weight 0.5 and return 0.01, stock 2 has weight 0.5 and return 0,03 the first day of the month. Hence, the weight of the two stocks this day is:

Day 1: stock 1: 0.51.01/(0.51.01+0.51.03) = 0.4951 stock 2:0.51.03/(0.51.01+0.51.03) = 0,5049

next day like this: Day 2:

stock 1: 0.49511.02/(0.49511.02+0,50491.01) = 0.4975 stock 2: 0,50491.01/(0.49511.02+0,50491.01) = 0,5024

and this shall continue until the end of the month. After that, the first return for each stock is used to start the same process again. The idea is to do this with a dataframe like the first picture.

READ ALSO
Is there a way to find the index of a element randomly grabed from an array?

Is there a way to find the index of a element randomly grabed from an array?

Quick beginner question here, I was just wordering if there is a better way of doing thisIm trying to get a random element from an array and also find out the index of the element at the same time

91
How to use antd icons in CSS pseudo-elements

How to use antd icons in CSS pseudo-elements

I'm currently getting an icon like this:

122
Can you return null here? [closed]

Can you return null here? [closed]

Want to improve this question? Add details and clarify the problem by editing this post

100
Libraries JS with TCP and UDP and WebExtension for Firefox and Chrome

Libraries JS with TCP and UDP and WebExtension for Firefox and Chrome

I have an application game which sends TCP and UDP data

124