Algorithmic Trading & Indicators
Beginner
Classify Futures & Options OI Buildup (Long Buildup, Short Buildup, Short Covering, Long Unwinding) in Python
Automatically classify intraday price and Open Interest (OI) changes into Long Buildup, Short Buildup, Short Covering, and Long Unwinding in Python Pandas.
#pandas#numpy
Problem Statement
Looking at price movement without Open Interest (OI) change hides whether a rally is driven by fresh institutional buying (Long Buildup) or hollow short covering.
Formula / Core Logic
Price_Chg > 0 & OI_Chg > 0 -> Long Buildup
Price_Chg < 0 & OI_Chg > 0 -> Short Buildup
Price_Chg > 0 & OI_Chg < 0 -> Short Covering
Price_Chg < 0 & OI_Chg < 0 -> Long Unwinding
Installation
pip install pandas numpy
option-chain-oi-buildup-long-short-covering-unwinding-python.py
import pandas as pd
import numpy as np
def classify_oi_buildup(df):
# Expected cols: Close, Open_Interest
df = df.copy()
p_chg = df['Close'].diff()
oi_chg = df['Open_Interest'].diff()
conds = [
(p_chg > 0) & (oi_chg > 0),
(p_chg < 0) & (oi_chg > 0),
(p_chg > 0) & (oi_chg < 0),
(p_chg < 0) & (oi_chg < 0)
]
labels = ['LONG_BUILDUP', 'SHORT_BUILDUP', 'SHORT_COVERING', 'LONG_UNWINDING']
df['OI_Interpretation'] = np.select(conds, labels, default='NEUTRAL')
return df
Get the Complete 100+ Python Quant & Automation Bundle
Instant lifetime access to all production-ready scripts, valuation models, and trading bots ($19).
Buy Full Bundle on Gumroad ($19) →Frequently Asked Questions
Q: How do option buyers interpret Short Buildup on an ATM Call strike?
Rising Call OI accompanied by falling Call premium indicates aggressive Call writing (resistance formation at that strike).