Book Image

Python for Finance

By : Yuxing Yan
Book Image

Python for Finance

By: Yuxing Yan

Overview of this book

A hands-on guide with easy-to-follow examples to help you learn about option theory, quantitative finance, financial modeling, and time series using Python. Python for Finance is perfect for graduate students, practitioners, and application developers who wish to learn how to utilize Python to handle their financial needs. Basic knowledge of Python will be helpful but knowledge of programming is necessary.
Table of Contents (14 chapters)
13
Index

Adding texts to our graph

In the following example, we simply insert a text. Remember that the x and y scale is from 0 to 1:

>>>from pylab import *
>>>x = [0,1,2]
>>>y = [2,4,6]
>>>plot(x,y)
>>>figtext(0.2, 0.7, 'North & West')
>>>figtext(0.7, 0.2, 'East & South')
>>>show()

The corresponding output graph is given as follows:

Adding texts to our graph

Let's make it more complex. From the National Bureau of Economic Research web page at http://www.nber.org/cycles.html, we can find the following table showing the business cycle in the past two decades:

Turning Point Date

Peak or Trough

Announcement Date

June 1, 2009

Trough

September 20, 2010

December 1, 2007

Peak

December 1, 2008

November 1, 2001

Trough

July 17, 2003

March 1, 2001

Peak

November 26, 2001

March 1, 1991

Trough

December 22, 1992

July 1, 1990

Peak

April 25, 1991

November 1, 1982

Trough

July 8, 1983

July 1, 1981

Peak

June 1, 1982

July...