Book Image

Learning Pandas

By : Michael Heydt
Book Image

Learning Pandas

By: Michael Heydt

Overview of this book

Table of Contents (19 chapters)
Learning pandas
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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(), 
                          daily_pc.std()):
       plt.annotate(
           label, 
           xy = (x, y), xytext = (30, -30),
           textcoords = 'offset points', ha = 'right', va = 'bottom',
          ...