Calculating portfolio weights when component values are given
In the video, it was shown that you can easily compute portfolio weights if you have a given amount of money invested in certain assets. If you want to start investing in a portfolio, but you have budget restraints, you can also impose weights yourself. Depending on what these are, you will invest a certain amount of money in each of the assets based on their weight.
When given asset values, calculating the weights is quite simple. Recall from the video that weights are calculated by taking the value of an asset divided by the sum of values from all assets.
In this exercise, you will learn to calculate weights when individual asset values are given! For this example, an investor has 4000 USD invested in equities, 4000 USD invested in bonds, and 2000 USD invested in commodities. Compute the weights as the proportion invested in each of those three assets.
Cet exercice fait partie du cours
Introduction to Portfolio Analysis in R
Instructions
- Define the vector
valuesas the vector holding the three asset values. - Define the vectors
weightsas the vectorvaluesdivided by the total value (obtained by summing over the component values using the functionsum(). - Print
weights.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# Define the vector values
# Define the vector weights
# Print the resulting weights