I have found the following code in the book Python for Finance by Yuxing Yan, in page 267 for estimating Amihud's illiquidity
import numpy as np
import statsmodels.api as sm
from matplotlib.finance import quotes_historical_yahoo_ochl as getData
begdate=(2013,10,1)
enddate=(2013,10,30)
ticker='IBM' # or WMT
data= getData(ticker, begdate, enddate,asobject=True, adjusted=True)
p=np.array(data.aclose)
dollar_vol=np.array(data.volume*p)
ret=np.array((p[1:] - p[:-1])/p[1:])
illiq=np.mean(np.divide(abs(ret),dollar_vol[1:]))
print("Aminud illiq for =",ticker,illiq)
The matplotlib.finance has been deprecated.The new module does not support collection of financial data, so I found an other way to collect them:
import pandas as pd
import pandas_datareader.data as web
end = '2013-10-30'
start = '2013-10-1'
get_px = lambda x: web.DataReader(x, 'yahoo', start=start, end=end)['Adj Close']
symbols = ['IBM']
data = pd.DataFrame({sym:get_px(sym) for sym in symbols})
data = data.rename({'IBM': 'Adj Close'}, axis=1)
p1 = data
p = p1['Adj Close'].ravel()
So far so good.But I don't know from the original code what the data.volume
does and how I can translate dollar_vol=np.array(data.volume*p)
with the existing functions of any module in Python.