eguidotti / bidask

Efficient Estimation of Bid-Ask Spreads from Open, High, Low, and Close Prices
https://doi.org/10.1016/j.jfineco.2024.103916
GNU General Public License v3.0
99 stars 26 forks source link

Changed edge.py to calculate rolling spread on pandas objects #8

Closed jerseyjosh closed 3 months ago

jerseyjosh commented 7 months ago

I've been using this for a while for online spread calculations from exchange data. Very useful!

I've left the functionality to return a single float based on a single input if 'window' is left as None (default). The pytest has a slightly different result because in the original code, there is a missing value from the np.logical_or(c[:-1], c[1:]) that is filled by NaN when transitioning to pd.Series.shift(), but especially on longer windows this difference would be negligible.

There's also functionality for using exponentially weighted averages instead of simple moving averages, parsing strings like 'ohl', 'oc', for different ways of calculating mid-price, or can pass a raw series to use your own definition of mid-price from orderbook data etc.

Feel free to ignore if not useful.

eguidotti commented 6 months ago

Thank you for your feedback and suggestions!

I see some theoretical issues in using open or closing prices in the calculation of the midprice (high-low average) because this may create a bias in the estimation. On the other hand, calculating rolling averages can be definitely useful. Also https://github.com/eguidotti/bidask/issues/9 seems to be a similar request in this direction

eguidotti commented 3 months ago

For the same reasons of #9 this PR will not be merged. In any case, thank you very much for your time and effort in putting this together.