Weighted average (1)
As a finance professional, there are a number of important calculations that you will have to know. One of these is the weighted average. The weighted average allows you to calculate your portfolio return over a time period. Consider the following example:
Assume you have 40% of your cash in Apple stock, and 60% of your cash in IBM stock. If, in January, Apple earned 5% and IBM earned 7%, what was your total portfolio return?
To calculate this, take the return of each stock in your portfolio, and multiply it by the weight of that stock. Then sum up all of the results. For this example, you would do:
6.2 = 5 * .4 + 7 * .6
Or, in variable terms:
portf_ret <- apple_ret * apple_weight + ibm_ret * ibm_weight
Cet exercice fait partie du cours
Introduction to R for Finance
Instructions
- Weights and returns for Microsoft and Sony have been defined for you.
- Calculate the
portf_ret
for this porfolio.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# Weights and returns
micr_ret <- 7
sony_ret <- 9
micr_weight <- .2
sony_weight <- .8
# Portfolio return
portf_ret <-