O'Reilly logo

Learning pandas by Michael Heydt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Determining risk relative to expected returns

A useful analysis is to relate the volatility of a stock's daily percentage change to its expected return. This gives a feel for the risk/return ratio of the investment. This can be performed by mapping the mean of the daily percentage change relative to the standard deviation of the same values.

To demonstrate, the following code will create a scatter plot that relates the risk and return of our sample set of stocks:

In [34]:
   # generate a scatter of the mean versus std of daily % change
   plt.scatter(daily_pc.mean(), daily_pc.std())
   plt.xlabel('Expected returns')
   plt.ylabel('Risk')

   # this adds fancy labels to each dot, with an arrow too
   for label, x, y in zip(daily_pc.columns, 
 daily_pc.mean(), ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required