Skip to content
All library documents

Calculating the Lakonishok Herding Measure and Its Adjustment Factor

Article Quant Q&A · Author: finstats

Summary

The document explains how to calculate the Lakonishok et al. herding measure from the fraction of active institutions buying a stock, the market-wide buy proportion, and an adjustment factor. The question asks how to derive that factor and how to aggregate results across stocks, quarters, and data subsets; the answer focuses on the adjustment-factor calculation.

The example assumes two active institutions and a buy probability of one half. It enumerates the possible buy counts, weights each count’s deviation from the expected buy share by its binomial probability, and sums the weighted deviations to obtain the adjustment factor. This shows how the correction represents the expected absolute deviation under no herding. The post does not provide Python implementation details or resolve the questions about averaging and subgroup construction. Its example is limited to the stated assumptions; other cases require using the relevant buy probability and number of active institutions.

Key ideas

  • The herding measure subtracts an adjustment factor from the observed deviation in the buy share.
  • The adjustment factor is the expected absolute deviation under a binomial no-herding model.
  • Compute it by weighting each possible buy count’s deviation by its probability and summing.
  • The example assumes two active institutions and an equal probability of buying or selling.
  • The document leaves implementation and aggregation choices across periods and subgroups unanswered.

Tags

Full text
# How to implement the herding measure proposed by Lakonishok et. al (1992) in python


# How to implement the herding measure proposed by Lakonishok et. al (1992) in python












I would like to test for herding behaviour using the herding measure developed by Lakonishok et. al (1992) on a dataset containing trader transactions during 2013, however, i am having some trouble implementing it in Python and I am not sure I quite understand how to compute each of the components of the equation (especially the Adjustment Factor).

The herding measure is given by `H(i) = |B(i)/(B(i) + S(i)) - p(t)| - AF(i)`

where AF(1) = |$\hat(B)$(1)/(B(1) + S(1)) - p(t)| ..... and ..... $\hat(B)$(i) $\sim$(p(t), B(i) + S(i))

A sample of my dataset looks as follows:

```
PositionID  TraderID    AssetID OrderID   Leverage  Equity  TotalAmount InitialRate PnL    Long=1   EndRate OpenDate            CloseDate
103764400   39          8       4565523   50        20      1000        0.8349       7.03   0       0.8306  24/11/2013 22:05    29/11/2013 21:31
103764489   39          3       4565521   50        20      1000        0.8175       3.9    0       0.8136  24/11/2013 22:06    29/11/2013 21:31
103764661   39          10      4565524   50        20      1000        137.3        19.73  1       139.32  24/11/2013 22:07    29/11/2013 00:53
103764698   39          1       4565518   50        20      1000        1.3553       2.8    1       1.3581  24/11/2013 22:07    29/11/2013 21:31
43611297    57          1       4565519   10        23.02   230.2       1.3         -9.74   0       1.3423  12/12/2012 00:15    08/02/2013 10:56
79572882    57          1       4565520   50        20      1000        1.3101      -0.2    1       1.3099  23/06/2013 21:13    23/06/2013 21:13
79572945    57          1       4565521   50        20      1000        1.3098      -1.5    0       1.3113  23/06/2013 21:13    24/06/2013 10:20
79683082    57          5       4565522   50        20      1000        97.96       -0.2    1       97.94   24/06/2013 10:20    24/06/2013 10:20
83630718    57          16      4565523   100       10      1000        106.41      -0.7    0       106.48  19/07/2013 08:49    19/07/2013 08:49
41039724    59          11      4565524   25        24.23   69.5        129.31      -19.89  0       157.54  20/11/2012 09:26    15/10/2013 15:42
41054904    59          11      4565525   25        24.01   69.5        129.63      -19.67  0       157.54  20/11/2012 11:47    15/10/2013 15:42
41244158    59          11      4565526   25        22.66   68          130.84      -18.41  0       157.54  21/11/2012 09:19    15/10/2013 15:42
```

Let's say I wanted to calculate the herding measure for AssetID=1, then:

`H(1) = |2/4 - (4/12)| - AF(1)` but i'm not sure how to calculate AF(1).

UPDATE: Frey et. al 2012 discuss the AF, but I still don't know how to calculate it.

Then, once I calculate the heading measure for all stocks, should I average them across all stocks and across all quarters?

Also, in the study, the authors apply this measure on subsets of the data (by size, past quarter performance, etc...). I am not sure how to do this exactly. Should I first filter the data (by size lets say) and take the largest quintile and calculate the average herding measure?

I am trying to implement this in python so I would really appreciate as much detail as possible and the best way to implement it in python.

Thank you!

## Answer by Tanel (score 1)

https://quant.stackexchange.com/a/29912

## Formula:

$H(i) = \mid\frac{B(i)}{B(i)+S(i)}-p(t)\mid-AF(i) $ (Lakonishok et al. 1992)

## How to calculate $AF(i)$ ?

This answer is based on Herding and Feedback Trading by Different Types of Institutions and the Effects on Stock Prices (Jones, Lee, Weis 1999)

- Given that Institutions in a company are neither net-buying nor net-selling, $p=0,5$, and there are two institutions active in the given quarter, $n=2$.

- Then the probabilities will be...

For 0 buys: $\frac{2!\times0.5\times(1-0.5)}{(2-0)\times0!}=0.25$

For 1 buys: $\frac{2!\times0.5\times(1-0.5)}{(2-1)\times1!}=0.5$

For 2 buys: $\frac{2!\times0.5\times(1-0.5)}{(2-2)\times2!}=0.25$

- And the absolute values will be...

For 0 buys: $\mid \frac{0}{2}-0.5 \mid = 0.5$

For 1 buys: $\mid \frac{1}{2}-0.5 \mid = 0$

For 2 buys: $\mid \frac{2}{2}-0.5 \mid = 0.5$

- Then the products will be...

For 0 buys: $0.25\times0.5=0.125$

For 1 buys: $0.5\times0=0$

For 2 buys: $0.25\times0.5=0.125$

- So the answer will be $AF=0.125+0+0.125=0.25$

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.