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.
This exercise is part of the course
Introduction to Portfolio Analysis in R
Exercise instructions
- Define the vector
values
as the vector holding the three asset values. - Define the vectors
weights
as the vectorvalues
divided by the total value (obtained by summing over the component values using the functionsum()
. - Print
weights
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Define the vector values
# Define the vector weights
# Print the resulting weights