Get startedGet started for free

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.

This exercise is part of the course

Introduction to Portfolio Analysis in Python

View Course

Exercise instructions

  • 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.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# 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(____)
Edit and Run Code