Book Image

Python for Finance

By : Yuxing Yan
Book Image

Python for Finance

By: Yuxing Yan

Overview of this book

Table of Contents (20 chapters)
Python for Finance
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Test of equivalency of volatility over two periods


We know that the stock market fell dramatically in October, 1987. We could choose a stock to test the volatility before and after October, 1987. For instance, we could use Ford Motor Corp, with a ticker of F, to illustrate how to test the equality of variance before and after the market crash in 1987. In the following Python program, we define a function called ret_f() to retrieve daily price data from Yahoo! Finance and estimate its daily returns:

import scipy as sp
from matplotlib.finance import quotes_historical_yahoo
import numpy as np
# input area 
ticker='F'               # stock
begdate1=(1982,9,1)      # starting date for period  #1
enddate1=(1987,9,1)      # ending   date for period  #1
begdate2=(1987,12,1)     # starting date for period  #2
enddate2=(1992,12,1)     # ending   date for period  #2
# define a function
def ret_f(ticker,begdate,enddate):
    p = quotes_historical_yahoo(ticker, begdate, enddate,asobject=True, adjusted...