Estimating Amihud Illiquidity with Adjusted Prices and Trading Volume
Summary
The document explains how to calculate dollar trading volume for an Amihud illiquidity estimate when migrating an older data workflow to a newer Python data source. The key data-handling point is that volume should be multiplied by the adjusted closing price to estimate dollars traded. The source discussion says the historical volume series is already adjusted for stock splits, while the price adjustment accounts for corporate actions; volume itself should not receive the same price adjustment.
The example therefore combines the provider’s volume and adjusted-close fields to form dollar volume, which serves as the denominator in the average absolute return-over-dollar-volume measure. This clarifies the meaning of a field in the original code and how to reproduce it with an alternative data reader. The excerpt does not evaluate the estimator’s statistical properties or discuss choices such as sampling frequency, missing data, or data-provider consistency, so it is chiefly a practical data-definition note rather than a broader liquidity analysis.
Key ideas
- Amihud illiquidity uses absolute returns scaled by dollar trading volume.
- Dollar volume can be estimated by multiplying split-adjusted volume by adjusted closing price.
- The cited data documentation says volume is already backward split-adjusted.
- Data-provider field definitions matter when reproducing historical liquidity calculations.
- The example does not assess estimator behavior or broader data-quality issues.
Tags
Full text
# Estimating Amihud's illiquidity in Python
# Estimating Amihud's illiquidity in Python
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.
## Answer by Pleb (score 1, accepted)
https://quant.stackexchange.com/a/69539
From the documentation of matplotlib.finance (under `parse_yahoo_historical_ochl(...)`) it is specified that the dollars traded/dollar-volume is the unadjusted volume multiplied by the adjusted closing prices of the given ticker (At `quotes_yahoo_historical_ochl(...)` they refer to the above function in order to understand the output format):
> adjusted : bool If True (default) replace open, close, high, low prices with their adjusted values. The adjustment is by a scale factor, S = adjusted_close/close. Adjusted prices are actual prices multiplied by S. Volume is not adjusted as it is already backward split adjusted by Yahoo. If you want to compute dollars traded, multiply volume by the adjusted close, regardless of whether you choose adjusted = True|False.
Here, `data.volume` gets the corresponding "unadjusted" volume array from the `getData` output. If you want to replicate `dollar_vol` you need to get the backwards split-adjusted volume (eg. from Yahoo finance) for your corresponding ticker as it seems you already have the adjusted close prices.
If you do something a lá:
```
from pandas_datareader import data
IBM = data.DataReader("IBM",
start='2013-10-1',
end='2013-10-30',
data_source='yahoo')
dollar_vol = IBM['Volume'] * IBM['Adj Close']
```
You should get the dollar_volume/dollars_traded as described in the documentation and in your first code snippet.Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.