0
$\begingroup$

firstly I would like to say sorry for the title - its not the best. In fact its crap.

Here is my problem (I am new to coding btw - still learning)

I am using Python on my MacBook - using Terminal.

  1. I have a portfolio of stocks with their weightings but at random periods. E.g. 2/Jan/2018 - Company X - 3%, Company Y - 4% etc. On 15/Feb/2018, I readjusted the weights to: Company X - 4% , Company Y - 5% etc. But for the period between 2/Jan to 15/Feb - I have no weightings for the stocks.

I want to fill in the gap - so between 2 Jan and 15 Feb 2018. I know we can easily do this by using the daily stock prices. What code can I use to to build daily weightings between 2 Jan 2018 to 15 Feb? So, if Company X price jump between 2nd of Jan to 3rd of Jan by some %, I would see the weighting get adjusted on 3rd Jan for Company X?

Much appreciated. PS I'm a novice at this.. so go easy on me!

$\endgroup$
1
  • $\begingroup$ many thanks. I am sorry I should have been more specific in terms of what I was asking. I want to know what kind of code would I need to use to answer my question? I have installed numpy, panda into my MacBook Book - using the Terminal. I googled it and found something about apply a loop? I am a novice coder but will to do the leg work if someone can help me out on what code, syntax I would need to build a code that will solve my answer $\endgroup$ Commented Sep 11, 2020 at 10:37

1 Answer 1

1
$\begingroup$

Assume a portfolio value (i.g. 100.000), find the value invested in each specific stock (if weight company X is 20% then we invest 20.000 in that stock), based on the price at that day you find the number of stocks invested (assume price 5, then we invested 20.000/5=4000 stocks). Once you have the exact number of stocks you invested in the portfolio for each company, every day find the new value for each stock (number stock times new price), find the portfolio value (sum of the new values) and divide the the values you have found by the portfolio value.

Assume the day after the price of the stock of campany X is 6. Then, the value of the investent in that stock is 6*4000=24.000. Assuming all the other stock prices constant the new portfolio value is 104.000 and the new weight is 24.000/104.000=23.08%.

$\endgroup$
1
  • $\begingroup$ many thanks. I am sorry I should have been more specific in terms of what I was asking. I want to know what kind of code would I need to use to answer my question? I have installed numpy, panda into my MacBook Book - using the Terminal? I googled it and found something about apply a loop? I am a novice coder but will to do the leg work if someone can help me out on what code, syntax I would need to build a code that will solve my answer $\endgroup$ Commented Sep 11, 2020 at 10:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.