Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Python for Finance
  • Toc
  • feedback
Python for Finance

Python for Finance

By : Yuxing Yan
3.9 (22)
close
Python for Finance

Python for Finance

3.9 (22)
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)
close
13
Index

Retrieving historical price data from Yahoo! Finance

The function called quotes_historical_yahoo() in the matplotlib module could be used to download historical price data from Yahoo! Finance. For example, we want to download daily price data for IBM over the period from January 1, 2012 to December 31, 2012, we have the following four-line Python code:

>>>from matplotlib.finance import quotes_historical_yahoo
>>>date1=(2012, 1, 1)
>>>date2=(2012, 12,31)
>>>price=quotes_historical_yahoo('IBM', date1, date2)

To download IBM's historical price data up to today, we could use the datetime.date.today() function as follows:

>>>import datetime
>>>import matplotlib.finance as finance
>>>import matplotlib.mlab as mlab
>>>ticker = 'IBM'
>>>begdate = datetime.date(2013,1,1)
>>>enddate = datetime.date.today()
>>>price = finance.fetch_historical_yahoo(ticker, begdate, enddate)
&gt...
bookmark search playlist font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete