ComeçarComece de graça

Calculate mean returns

In this exercise, you're going to calculate performance for a four stock portfolio over the period January 2015 through March 2019. The portfolio consists of Proctor & Gamble, Microsoft, JP Morgan and General Electric stocks. You'll discover that multiplying the mean return of each stock with its portfolio weight, is a very quick and straightforward way to calculate portfolio performance over a given period of time.

The four columns in the DataFrame data contain the prices of these four stocks mentioned above. Have a look at data by inspecting it in the console.

Este exercício faz parte do curso

Introduction to Portfolio Analysis in Python

Ver curso

Instruções do exercício

  • Calculate the percentage returns of the stocks in the DataFrame data by comparing today's price with yesterday's price.
  • Calculate the mean returns of each stock in the new returns DataFrame.
  • Assign the weights of the stocks to the weights array. The weights are 0.5, 0.2, 0.2 and 0.1.
  • Multiply the percentage returns with the weights, and take the total sum, to calculate the total portfolio performance and print the results.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# Calculate percentage returns
returns = data.____()

# Calculate individual mean returns 
meanDailyReturns = ____.____()

# Define weights for the portfolio
weights = np.array([____, ____, ____, ____])

# Calculate expected portfolio performance
portReturn = np.____(____*____)

# Print the portfolio return
print(____)
Editar e executar o código