10.12.2019 Views

Python for Finance

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 8

The covariance between them is negative. When its value is positive, Roll's model

would fail. In a real world, it could occur for many cases. Usually, practitioners

adopt two approaches: when the spread is negative, we just ignore those cases or use

other methods to estimate spread. The second approach is to add a negative sign in

front of a positive covariance.

Estimating Amihud's illiquidity

According to Amihud (2002), liquidity reflects the impact of order flow on price. His

illiquidity measure is defined as follows:

Here, illiq(t) is the Amihud's illiquidity measure for month t, Ri is the daily return at

day i, Pi is the closing price at i, and Vi is the daily dollar trading volume at i. Since

the illiquidity is the reciprocal of liquidity, the lower the illiquidity value, the higher

the liquidity of the underlying security. First, let's look at an item-by-item division:

>>>x=np.array([1,2,3],dtype='float')

>>>y=np.array([2,2,4],dtype='float')

>>>np.divide(x,y)

array([ 0.5 , 1. , 0.75])

>>>

In the following code, we estimate Amihud's illiquidity for IBM based on trading

data in October 2013. The value is 1.21*10-11. It seems that this value is quite small.

Actually, the absolute value is not important; the relative value matters. If we

estimate the illiquidity for WMT over the same period, we would find a value of

1.52*10-11. Since 1.21 is less than 1.52, we conclude that IBM is more liquid than

WMT. This correlation is represented in the following code:

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:]))

[ 267 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!