Exercise

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.

Instructions

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