IniziaInizia gratis

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

Questo esercizio fa parte del corso

Introduction to R for Finance

Visualizza il corso

Istruzioni dell'esercizio

  • Weights and returns for Microsoft and Sony have been defined for you.
  • Calculate the portf_ret for this porfolio.

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

# Weights and returns
micr_ret <- 7
sony_ret <- 9
micr_weight <- .2
sony_weight <- .8

# Portfolio return
portf_ret <-
Modifica ed esegui il codice