FDRM ASSIGNMENT¶
Question: Determination / Computation of Hedge ratio and Hedging Effectiveness of 10 stocks with 10 different futures.¶
Solution:¶
SETTLEMENT DATA¶
Equity Price Data¶
In [64]:
df_s.head(10)
Out[64]:
| ticker | Bharat Electronics Ltd. | Infosys Ltd. | Tata Steel Ltd. | Larsen & Toubro Ltd. | Nestle India Ltd. | Power Grid Corporation of India Ltd. | Mahindra & Mahindra Ltd. | Sun Pharmaceutical Industries Ltd. | UltraTech Cement Ltd. | Axis Bank Ltd. |
|---|---|---|---|---|---|---|---|---|---|---|
| date | ||||||||||
| 2025-07-14 | 407.30 | 1570.3 | 160.44 | 3495.9 | 1196.45 | 298.20 | 3092.1 | 1682.6 | 12516.0 | 1172.7 |
| 2025-07-15 | 408.95 | 1585.6 | 159.00 | 3494.0 | 1208.15 | 298.05 | 3128.6 | 1727.5 | 12502.0 | 1165.9 |
| 2025-07-16 | 406.15 | 1607.9 | 157.33 | 3503.8 | 1230.00 | 297.05 | 3196.5 | 1701.0 | 12453.0 | 1168.4 |
| 2025-07-17 | 404.20 | 1583.5 | 159.90 | 3474.0 | 1224.55 | 296.60 | 3195.0 | 1703.4 | 12495.0 | 1159.8 |
| 2025-07-18 | 394.75 | 1586.1 | 162.37 | 3464.8 | 1236.10 | 294.15 | 3192.4 | 1693.6 | 12498.0 | 1099.3 |
| 2025-07-21 | 399.95 | 1584.3 | 163.02 | 3502.8 | 1236.30 | 297.00 | 3246.7 | 1692.3 | 12577.0 | 1099.6 |
| 2025-07-22 | 403.10 | 1570.9 | 163.04 | 3464.6 | 1221.75 | 297.80 | 3257.2 | 1678.0 | 12452.0 | 1098.0 |
| 2025-07-23 | 400.20 | 1574.5 | 162.77 | 3484.9 | 1226.25 | 299.25 | 3268.8 | 1682.5 | 12372.0 | 1104.8 |
| 2025-07-24 | 398.25 | 1552.5 | 163.48 | 3477.5 | 1161.05 | 299.35 | 3260.9 | 1692.0 | 12304.0 | 1095.1 |
| 2025-07-25 | 395.20 | 1515.7 | 161.43 | 3442.9 | 1137.30 | 292.10 | 3246.4 | 1699.0 | 12250.0 | 1086.1 |
Futures Price Data¶
In [65]:
df_f.head(10)
Out[65]:
| ticker | Bharat Electronics Ltd Futures. | Infosys Ltd Futures. | Tata Steel Ltd Futures. | Larsen & Toubro Ltd Futures. | Nestle India Ltd Futures. | Power Grid Corporation of India Ltd Futures. | Mahindra & Mahindra Ltd Futures. | Sun Pharmaceutical Industries Ltd Futures. | UltraTech Cement Ltd Futures. | Axis Bank Ltd Futures. |
|---|---|---|---|---|---|---|---|---|---|---|
| date | ||||||||||
| 2025-07-14 | 412.95 | 1589.6 | 162.85 | 3548.5 | 1212.50 | 301.55 | 3139.0 | 1706.3 | 12582.0 | 1188.7 |
| 2025-07-15 | 414.35 | 1608.1 | 161.42 | 3546.1 | 1225.20 | 301.15 | 3174.2 | 1749.5 | 12574.0 | 1181.4 |
| 2025-07-16 | 411.20 | 1630.5 | 159.30 | 3551.8 | 1246.00 | 299.80 | 3238.0 | 1725.3 | 12612.0 | 1181.8 |
| 2025-07-17 | 409.40 | 1607.5 | 161.92 | 3526.0 | 1242.20 | 300.35 | 3249.7 | 1729.0 | 12581.0 | 1176.7 |
| 2025-07-18 | 399.55 | 1608.8 | 164.48 | 3516.7 | 1251.20 | 296.75 | 3237.9 | 1718.5 | 12576.0 | 1115.4 |
| 2025-07-21 | 404.20 | 1605.3 | 165.23 | 3546.6 | 1251.05 | 300.55 | 3279.7 | 1714.8 | 12652.0 | 1115.0 |
| 2025-07-22 | 406.95 | 1594.7 | 165.21 | 3511.5 | 1234.45 | 301.30 | 3298.7 | 1698.0 | 12529.0 | 1113.3 |
| 2025-07-23 | 404.00 | 1588.0 | 165.03 | 3533.2 | 1241.35 | 301.10 | 3306.7 | 1705.6 | 12461.0 | 1120.2 |
| 2025-07-24 | 402.40 | 1573.2 | 165.35 | 3526.0 | 1173.35 | 301.30 | 3295.6 | 1712.0 | 12363.0 | 1110.4 |
| 2025-07-25 | 398.60 | 1533.6 | 163.35 | 3487.6 | 1150.30 | 293.45 | 3278.6 | 1716.9 | 12388.0 | 1099.3 |
DELTA DATA¶
Stock Price
In [66]:
df_s_diff.head(10)
Out[66]:
| ticker | Bharat Electronics Ltd. | Infosys Ltd. | Tata Steel Ltd. | Larsen & Toubro Ltd. | Nestle India Ltd. | Power Grid Corporation of India Ltd. | Mahindra & Mahindra Ltd. | Sun Pharmaceutical Industries Ltd. | UltraTech Cement Ltd. | Axis Bank Ltd. |
|---|---|---|---|---|---|---|---|---|---|---|
| date | ||||||||||
| 2025-07-15 | 1.65 | 15.3 | -1.44 | -1.9 | 11.70 | -0.15 | 36.5 | 44.9 | -14.0 | -6.8 |
| 2025-07-16 | -2.80 | 22.3 | -1.67 | 9.8 | 21.85 | -1.00 | 67.9 | -26.5 | -49.0 | 2.5 |
| 2025-07-17 | -1.95 | -24.4 | 2.57 | -29.8 | -5.45 | -0.45 | -1.5 | 2.4 | 42.0 | -8.6 |
| 2025-07-18 | -9.45 | 2.6 | 2.47 | -9.2 | 11.55 | -2.45 | -2.6 | -9.8 | 3.0 | -60.5 |
| 2025-07-21 | 5.20 | -1.8 | 0.65 | 38.0 | 0.20 | 2.85 | 54.3 | -1.3 | 79.0 | 0.3 |
| 2025-07-22 | 3.15 | -13.4 | 0.02 | -38.2 | -14.55 | 0.80 | 10.5 | -14.3 | -125.0 | -1.6 |
| 2025-07-23 | -2.90 | 3.6 | -0.27 | 20.3 | 4.50 | 1.45 | 11.6 | 4.5 | -80.0 | 6.8 |
| 2025-07-24 | -1.95 | -22.0 | 0.71 | -7.4 | -65.20 | 0.10 | -7.9 | 9.5 | -68.0 | -9.7 |
| 2025-07-25 | -3.05 | -36.8 | -2.05 | -34.6 | -23.75 | -7.25 | -14.5 | 7.0 | -54.0 | -9.0 |
| 2025-07-28 | -5.95 | 0.3 | -1.75 | -20.7 | -22.65 | -0.20 | -36.6 | 3.2 | -10.0 | -12.5 |
Future Price
In [69]:
df_f_diff.head(10)
Out[69]:
| ticker | Bharat Electronics Ltd Futures. | Infosys Ltd Futures. | Tata Steel Ltd Futures. | Larsen & Toubro Ltd Futures. | Nestle India Ltd Futures. | Power Grid Corporation of India Ltd Futures. | Mahindra & Mahindra Ltd Futures. | Sun Pharmaceutical Industries Ltd Futures. | UltraTech Cement Ltd Futures. | Axis Bank Ltd Futures. |
|---|---|---|---|---|---|---|---|---|---|---|
| date | ||||||||||
| 2025-07-15 | 1.40 | 18.5 | -1.43 | -2.4 | 12.70 | -0.40 | 35.2 | 43.2 | -8.0 | -7.3 |
| 2025-07-16 | -3.15 | 22.4 | -2.12 | 5.7 | 20.80 | -1.35 | 63.8 | -24.2 | 38.0 | 0.4 |
| 2025-07-17 | -1.80 | -23.0 | 2.62 | -25.8 | -3.80 | 0.55 | 11.7 | 3.7 | -31.0 | -5.1 |
| 2025-07-18 | -9.85 | 1.3 | 2.56 | -9.3 | 9.00 | -3.60 | -11.8 | -10.5 | -5.0 | -61.3 |
| 2025-07-21 | 4.65 | -3.5 | 0.75 | 29.9 | -0.15 | 3.80 | 41.8 | -3.7 | 76.0 | -0.4 |
| 2025-07-22 | 2.75 | -10.6 | -0.02 | -35.1 | -16.60 | 0.75 | 19.0 | -16.8 | -123.0 | -1.7 |
| 2025-07-23 | -2.95 | -6.7 | -0.18 | 21.7 | 6.90 | -0.20 | 8.0 | 7.6 | -68.0 | 6.9 |
| 2025-07-24 | -1.60 | -14.8 | 0.32 | -7.2 | -68.00 | 0.20 | -11.1 | 6.4 | -98.0 | -9.8 |
| 2025-07-25 | -3.80 | -39.6 | -2.00 | -38.4 | -23.05 | -7.85 | -17.0 | 4.9 | 25.0 | -11.1 |
| 2025-07-28 | -4.95 | -0.3 | -1.82 | -25.3 | -21.35 | 0.40 | -29.9 | 7.2 | -36.0 | -12.6 |
FINAL ANALYSIS¶
CORR COEFF (r)¶
In [70]:
cross_correlation_matrix.head(10)
Out[70]:
| ticker | Bharat Electronics Ltd Futures. | Infosys Ltd Futures. | Tata Steel Ltd Futures. | Larsen & Toubro Ltd Futures. | Nestle India Ltd Futures. | Power Grid Corporation of India Ltd Futures. | Mahindra & Mahindra Ltd Futures. | Sun Pharmaceutical Industries Ltd Futures. | UltraTech Cement Ltd Futures. | Axis Bank Ltd Futures. |
|---|---|---|---|---|---|---|---|---|---|---|
| ticker | ||||||||||
| Bharat Electronics Ltd. | 0.986785 | 0.249701 | 0.505220 | 0.225658 | -0.005924 | 0.149871 | 0.583512 | 0.258634 | 0.399662 | 0.551980 |
| Infosys Ltd. | 0.262463 | 0.976238 | 0.331776 | 0.517450 | 0.487080 | 0.148953 | 0.573552 | 0.534089 | 0.536314 | 0.109932 |
| Tata Steel Ltd. | 0.552945 | 0.365612 | 0.997336 | 0.386667 | -0.032904 | -0.006160 | 0.407206 | 0.500335 | 0.494317 | -0.001099 |
| Larsen & Toubro Ltd. | 0.257266 | 0.464798 | 0.356819 | 0.997781 | 0.238791 | -0.111741 | 0.395264 | 0.509369 | 0.565838 | 0.365949 |
| Nestle India Ltd. | -0.042971 | 0.363072 | -0.050974 | 0.243894 | 0.994819 | 0.031938 | 0.347258 | -0.130333 | 0.341507 | 0.065604 |
| Power Grid Corporation of India Ltd. | 0.080218 | 0.165959 | -0.110377 | -0.115040 | 0.117942 | 0.965511 | 0.006743 | -0.164662 | -0.218182 | 0.163207 |
| Mahindra & Mahindra Ltd. | 0.564256 | 0.540321 | 0.318724 | 0.373640 | 0.407139 | 0.063973 | 0.979641 | 0.292210 | 0.611682 | 0.386311 |
| Sun Pharmaceutical Industries Ltd. | 0.327838 | 0.531385 | 0.484527 | 0.517836 | -0.107803 | -0.101490 | 0.348414 | 0.995550 | 0.509032 | 0.142312 |
| UltraTech Cement Ltd. | 0.431419 | 0.387358 | 0.553294 | 0.558458 | 0.280896 | 0.032594 | 0.500310 | 0.511584 | 0.923255 | 0.298574 |
| Axis Bank Ltd. | 0.568495 | 0.072589 | -0.063410 | 0.385587 | 0.109949 | 0.170823 | 0.439102 | 0.134345 | 0.336769 | 0.994870 |
STDEV RATIO¶
In [71]:
cross_division_matrix.head(10)
Out[71]:
| ticker | Bharat Electronics Ltd Futures. | Infosys Ltd Futures. | Tata Steel Ltd Futures. | Larsen & Toubro Ltd Futures. | Nestle India Ltd Futures. | Power Grid Corporation of India Ltd Futures. | Mahindra & Mahindra Ltd Futures. | Sun Pharmaceutical Industries Ltd Futures. | UltraTech Cement Ltd Futures. | Axis Bank Ltd Futures. |
|---|---|---|---|---|---|---|---|---|---|---|
| ticker | ||||||||||
| Bharat Electronics Ltd. | 1.027083 | 0.271611 | 1.845485 | 0.092423 | 0.239103 | 1.814600 | 0.142782 | 0.172691 | 0.051199 | 0.301467 |
| Infosys Ltd. | 3.730644 | 0.986566 | 6.703300 | 0.335704 | 0.868486 | 6.591120 | 0.518624 | 0.627260 | 0.185968 | 1.095010 |
| Tata Steel Ltd. | 0.544716 | 0.144050 | 0.978756 | 0.049017 | 0.126809 | 0.962377 | 0.075725 | 0.091587 | 0.027153 | 0.159884 |
| Larsen & Toubro Ltd. | 11.403298 | 3.015592 | 20.489687 | 1.026133 | 2.654664 | 20.146789 | 1.585255 | 1.917318 | 0.568440 | 3.347069 |
| Nestle India Ltd. | 4.280506 | 1.131976 | 7.691304 | 0.385184 | 0.996493 | 7.562590 | 0.595064 | 0.719712 | 0.213378 | 1.256404 |
| Power Grid Corporation of India Ltd. | 0.515170 | 0.136236 | 0.925669 | 0.046358 | 0.119931 | 0.910178 | 0.071618 | 0.086619 | 0.025681 | 0.151212 |
| Mahindra & Mahindra Ltd. | 7.399666 | 1.956835 | 13.295876 | 0.665864 | 1.722627 | 13.073368 | 1.028681 | 1.244159 | 0.368864 | 2.171933 |
| Sun Pharmaceutical Industries Ltd. | 5.681430 | 1.502449 | 10.208514 | 0.511247 | 1.322625 | 10.037673 | 0.789817 | 0.955259 | 0.283212 | 1.667600 |
| UltraTech Cement Ltd. | 20.783422 | 5.496158 | 37.344092 | 1.870210 | 4.838338 | 36.719134 | 2.889255 | 3.494465 | 1.036028 | 6.100301 |
| Axis Bank Ltd. | 3.435959 | 0.908636 | 6.173804 | 0.309187 | 0.799884 | 6.070484 | 0.477658 | 0.577712 | 0.171278 | 1.008515 |
HEDGE RATIO¶
In [76]:
Hedge_Ratio.head(10)
Out[76]:
| ticker | Bharat Electronics Ltd Futures. | Infosys Ltd Futures. | Tata Steel Ltd Futures. | Larsen & Toubro Ltd Futures. | Nestle India Ltd Futures. | Power Grid Corporation of India Ltd Futures. | Mahindra & Mahindra Ltd Futures. | Sun Pharmaceutical Industries Ltd Futures. | UltraTech Cement Ltd Futures. | Axis Bank Ltd Futures. |
|---|---|---|---|---|---|---|---|---|---|---|
| ticker | ||||||||||
| Bharat Electronics Ltd. | 1.013510 | 0.067822 | 0.932375 | 0.020856 | -0.001416 | 0.271956 | 0.083315 | 0.044664 | 0.020462 | 0.166404 |
| Infosys Ltd. | 0.979155 | 0.963123 | 2.223995 | 0.173710 | 0.423022 | 0.981769 | 0.297458 | 0.335013 | 0.099737 | 0.120376 |
| Tata Steel Ltd. | 0.301198 | 0.052666 | 0.976149 | 0.018953 | -0.004173 | -0.005929 | 0.030836 | 0.045824 | 0.013422 | -0.000176 |
| Larsen & Toubro Ltd. | 2.933677 | 1.401640 | 7.311102 | 1.023856 | 0.633911 | -2.251227 | 0.626594 | 0.976623 | 0.321645 | 1.224857 |
| Nestle India Ltd. | -0.183937 | 0.410989 | -0.392057 | 0.093944 | 0.991330 | 0.241532 | 0.206641 | -0.093802 | 0.072870 | 0.082425 |
| Power Grid Corporation of India Ltd. | 0.041326 | 0.022610 | -0.102173 | -0.005333 | 0.014145 | 0.878787 | 0.000483 | -0.014263 | -0.005603 | 0.024679 |
| Mahindra & Mahindra Ltd. | 4.175310 | 1.057319 | 4.237712 | 0.248793 | 0.701349 | 0.836341 | 1.007738 | 0.363555 | 0.225628 | 0.839041 |
| Sun Pharmaceutical Industries Ltd. | 1.862586 | 0.798379 | 4.946301 | 0.264742 | -0.142582 | -1.018723 | 0.275183 | 0.951008 | 0.144164 | 0.237320 |
| UltraTech Cement Ltd. | 8.966357 | 2.128983 | 20.662249 | 1.044434 | 1.359068 | 1.196810 | 1.445524 | 1.787712 | 0.956518 | 1.821392 |
| Axis Bank Ltd. | 1.953325 | 0.065957 | -0.391480 | 0.119219 | 0.087946 | 1.036981 | 0.209741 | 0.077613 | 0.057681 | 1.003341 |
HEDGING EFFECTIVENESS¶
In [77]:
squared_matrix.head(10)
Out[77]:
| ticker | Bharat Electronics Ltd Futures. | Infosys Ltd Futures. | Tata Steel Ltd Futures. | Larsen & Toubro Ltd Futures. | Nestle India Ltd Futures. | Power Grid Corporation of India Ltd Futures. | Mahindra & Mahindra Ltd Futures. | Sun Pharmaceutical Industries Ltd Futures. | UltraTech Cement Ltd Futures. | Axis Bank Ltd Futures. |
|---|---|---|---|---|---|---|---|---|---|---|
| ticker | ||||||||||
| Bharat Electronics Ltd. | 0.973744 | 0.062351 | 0.255247 | 0.050921 | 0.000035 | 0.022461 | 0.340486 | 0.066891 | 0.159730 | 0.304682 |
| Infosys Ltd. | 0.068887 | 0.953041 | 0.110075 | 0.267754 | 0.237247 | 0.022187 | 0.328962 | 0.285251 | 0.287633 | 0.012085 |
| Tata Steel Ltd. | 0.305749 | 0.133672 | 0.994679 | 0.149511 | 0.001083 | 0.000038 | 0.165817 | 0.250336 | 0.244349 | 0.000001 |
| Larsen & Toubro Ltd. | 0.066186 | 0.216037 | 0.127320 | 0.995567 | 0.057021 | 0.012486 | 0.156233 | 0.259457 | 0.320173 | 0.133919 |
| Nestle India Ltd. | 0.001846 | 0.131821 | 0.002598 | 0.059484 | 0.989665 | 0.001020 | 0.120588 | 0.016987 | 0.116627 | 0.004304 |
| Power Grid Corporation of India Ltd. | 0.006435 | 0.027543 | 0.012183 | 0.013234 | 0.013910 | 0.932211 | 0.000045 | 0.027114 | 0.047603 | 0.026637 |
| Mahindra & Mahindra Ltd. | 0.318385 | 0.291947 | 0.101585 | 0.139607 | 0.165762 | 0.004093 | 0.959696 | 0.085387 | 0.374155 | 0.149236 |
| Sun Pharmaceutical Industries Ltd. | 0.107477 | 0.282370 | 0.234766 | 0.268154 | 0.011621 | 0.010300 | 0.121392 | 0.991119 | 0.259114 | 0.020253 |
| UltraTech Cement Ltd. | 0.186122 | 0.150047 | 0.306134 | 0.311876 | 0.078902 | 0.001062 | 0.250311 | 0.261718 | 0.852401 | 0.089147 |
| Axis Bank Ltd. | 0.323186 | 0.005269 | 0.004021 | 0.148678 | 0.012089 | 0.029181 | 0.192811 | 0.018049 | 0.113413 | 0.989766 |
METHODOLOGY¶
In [1]:
import pandas as pd
import yfinance as yf
import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import make_interp_spline
import pdblp
from datetime import datetime
import io
In [2]:
con = pdblp.BCon()
con.start()
Out[2]:
<pdblp.pdblp.BCon at 0x233b9b70ad0>
In [3]:
con.timeout = 30000
In [4]:
Stock_tickers= [
'TATA IS Equity', # Tata Steel Ltd.
'LT IS Equity', # Larsen & Toubro Ltd.
'NEST IS Equity', # Nestle India Ltd.
'PWGR IS Equity', # Power Grid Corporation of India Ltd.
'MM IS Equity', # Mahindra & Mahindra Ltd.
'SUNP IS Equity', # Sun Pharmaceutical Industries Ltd.
'UTCEM IS Equity', # UltraTech Cement Ltd.
'AXSB IS Equity', # Axis Bank Ltd.
'BHE IS Equity', # Bharat Electronics Ltd.
'INFO IS Equity' # Infosys Ltd.
]
In [5]:
futures_tickers= [
'TATA=U5 IS Equity', # Tata Steel Ltd.
'LT=U5 IS Equity', # Larsen & Toubro Ltd.
'NEST=U5 IS Equity', # Nestle India Ltd.
'PWGR=U5 IS Equity', # Power Grid Corporation of India Ltd.
'MM=U5 IS Equity', # Mahindra & Mahindra Ltd.
'SUNP=U5 IS Equity', # Sun Pharmaceutical Industries Ltd.
'UTCEM=U5 IS Equity', # UltraTech Cement Ltd.
'AXSB=U5 IS Equity', # Axis Bank Ltd.
'BHE=U5 IS Equity', # Bharat Electronics Ltd.
'INFO=U5 IS Equity' # Infosys Ltd.
]
In [6]:
price_field = ['PX_LAST']
In [7]:
thirty_days_ago = (datetime.now() - pd.DateOffset(days=30)).strftime('%Y%m%d')
In [8]:
data_stocks = con.bdh(
tickers=Stock_tickers,
flds=price_field,
start_date=thirty_days_ago,
end_date=datetime.now().strftime('%Y%m%d')
)
In [9]:
data_futures = con.bdh(
tickers=futures_tickers,
flds=price_field,
start_date=thirty_days_ago,
end_date=datetime.now().strftime('%Y%m%d')
)
In [10]:
df_s = pd.DataFrame(data_stocks)
In [11]:
df_f = pd.DataFrame(data_futures)
In [12]:
df_s.columns = df_s.columns.droplevel('field')
df_f.columns = df_f.columns.droplevel('field')
In [13]:
df_s.rename(columns={
'TATA IS Equity': 'Tata Steel Ltd.',
'LT IS Equity': 'Larsen & Toubro Ltd.',
'NEST IS Equity': 'Nestle India Ltd.',
'PWGR IS Equity': 'Power Grid Corporation of India Ltd.',
'MM IS Equity': 'Mahindra & Mahindra Ltd.',
'SUNP IS Equity': 'Sun Pharmaceutical Industries Ltd.',
'UTCEM IS Equity': 'UltraTech Cement Ltd.',
'AXSB IS Equity': 'Axis Bank Ltd.',
'BHE IS Equity': 'Bharat Electronics Ltd.',
'INFO IS Equity': 'Infosys Ltd.'
}, inplace=True)
In [14]:
df_f.rename(columns={
'TATA=U5 IS Equity': 'Tata Steel Ltd Futures.',
'LT=U5 IS Equity': 'Larsen & Toubro Ltd Futures.',
'NEST=U5 IS Equity': 'Nestle India Ltd Futures.',
'PWGR=U5 IS Equity': 'Power Grid Corporation of India Ltd Futures.',
'MM=U5 IS Equity': 'Mahindra & Mahindra Ltd Futures.',
'SUNP=U5 IS Equity': 'Sun Pharmaceutical Industries Ltd Futures.',
'UTCEM=U5 IS Equity': 'UltraTech Cement Ltd Futures.',
'AXSB=U5 IS Equity': 'Axis Bank Ltd Futures.',
'BHE=U5 IS Equity': 'Bharat Electronics Ltd Futures.',
'INFO=U5 IS Equity': 'Infosys Ltd Futures.'
}, inplace=True)
In [15]:
common_dates = df_s.index.intersection(df_f.index)
In [16]:
df_s = df_s.reindex(common_dates)
df_f = df_f.reindex(common_dates)
In [17]:
df_s.head()
Out[17]:
| ticker | Bharat Electronics Ltd. | Infosys Ltd. | Tata Steel Ltd. | Larsen & Toubro Ltd. | Nestle India Ltd. | Power Grid Corporation of India Ltd. | Mahindra & Mahindra Ltd. | Sun Pharmaceutical Industries Ltd. | UltraTech Cement Ltd. | Axis Bank Ltd. |
|---|---|---|---|---|---|---|---|---|---|---|
| date | ||||||||||
| 2025-07-14 | 407.30 | 1570.3 | 160.44 | 3495.9 | 1196.45 | 298.20 | 3092.1 | 1682.6 | 12516.0 | 1172.7 |
| 2025-07-15 | 408.95 | 1585.6 | 159.00 | 3494.0 | 1208.15 | 298.05 | 3128.6 | 1727.5 | 12502.0 | 1165.9 |
| 2025-07-16 | 406.15 | 1607.9 | 157.33 | 3503.8 | 1230.00 | 297.05 | 3196.5 | 1701.0 | 12453.0 | 1168.4 |
| 2025-07-17 | 404.20 | 1583.5 | 159.90 | 3474.0 | 1224.55 | 296.60 | 3195.0 | 1703.4 | 12495.0 | 1159.8 |
| 2025-07-18 | 394.75 | 1586.1 | 162.37 | 3464.8 | 1236.10 | 294.15 | 3192.4 | 1693.6 | 12498.0 | 1099.3 |
In [18]:
df_s_diff = df_s.diff().dropna()
In [19]:
df_s_diff.head()
Out[19]:
| ticker | Bharat Electronics Ltd. | Infosys Ltd. | Tata Steel Ltd. | Larsen & Toubro Ltd. | Nestle India Ltd. | Power Grid Corporation of India Ltd. | Mahindra & Mahindra Ltd. | Sun Pharmaceutical Industries Ltd. | UltraTech Cement Ltd. | Axis Bank Ltd. |
|---|---|---|---|---|---|---|---|---|---|---|
| date | ||||||||||
| 2025-07-15 | 1.65 | 15.3 | -1.44 | -1.9 | 11.70 | -0.15 | 36.5 | 44.9 | -14.0 | -6.8 |
| 2025-07-16 | -2.80 | 22.3 | -1.67 | 9.8 | 21.85 | -1.00 | 67.9 | -26.5 | -49.0 | 2.5 |
| 2025-07-17 | -1.95 | -24.4 | 2.57 | -29.8 | -5.45 | -0.45 | -1.5 | 2.4 | 42.0 | -8.6 |
| 2025-07-18 | -9.45 | 2.6 | 2.47 | -9.2 | 11.55 | -2.45 | -2.6 | -9.8 | 3.0 | -60.5 |
| 2025-07-21 | 5.20 | -1.8 | 0.65 | 38.0 | 0.20 | 2.85 | 54.3 | -1.3 | 79.0 | 0.3 |
In [20]:
df_f.head()
Out[20]:
| ticker | Bharat Electronics Ltd Futures. | Infosys Ltd Futures. | Tata Steel Ltd Futures. | Larsen & Toubro Ltd Futures. | Nestle India Ltd Futures. | Power Grid Corporation of India Ltd Futures. | Mahindra & Mahindra Ltd Futures. | Sun Pharmaceutical Industries Ltd Futures. | UltraTech Cement Ltd Futures. | Axis Bank Ltd Futures. |
|---|---|---|---|---|---|---|---|---|---|---|
| date | ||||||||||
| 2025-07-14 | 412.95 | 1589.6 | 162.85 | 3548.5 | 1212.5 | 301.55 | 3139.0 | 1706.3 | 12582.0 | 1188.7 |
| 2025-07-15 | 414.35 | 1608.1 | 161.42 | 3546.1 | 1225.2 | 301.15 | 3174.2 | 1749.5 | 12574.0 | 1181.4 |
| 2025-07-16 | 411.20 | 1630.5 | 159.30 | 3551.8 | 1246.0 | 299.80 | 3238.0 | 1725.3 | 12612.0 | 1181.8 |
| 2025-07-17 | 409.40 | 1607.5 | 161.92 | 3526.0 | 1242.2 | 300.35 | 3249.7 | 1729.0 | 12581.0 | 1176.7 |
| 2025-07-18 | 399.55 | 1608.8 | 164.48 | 3516.7 | 1251.2 | 296.75 | 3237.9 | 1718.5 | 12576.0 | 1115.4 |
In [21]:
df_f_diff = df_f.diff().dropna()
In [22]:
df_f_diff.head()
Out[22]:
| ticker | Bharat Electronics Ltd Futures. | Infosys Ltd Futures. | Tata Steel Ltd Futures. | Larsen & Toubro Ltd Futures. | Nestle India Ltd Futures. | Power Grid Corporation of India Ltd Futures. | Mahindra & Mahindra Ltd Futures. | Sun Pharmaceutical Industries Ltd Futures. | UltraTech Cement Ltd Futures. | Axis Bank Ltd Futures. |
|---|---|---|---|---|---|---|---|---|---|---|
| date | ||||||||||
| 2025-07-15 | 1.40 | 18.5 | -1.43 | -2.4 | 12.70 | -0.40 | 35.2 | 43.2 | -8.0 | -7.3 |
| 2025-07-16 | -3.15 | 22.4 | -2.12 | 5.7 | 20.80 | -1.35 | 63.8 | -24.2 | 38.0 | 0.4 |
| 2025-07-17 | -1.80 | -23.0 | 2.62 | -25.8 | -3.80 | 0.55 | 11.7 | 3.7 | -31.0 | -5.1 |
| 2025-07-18 | -9.85 | 1.3 | 2.56 | -9.3 | 9.00 | -3.60 | -11.8 | -10.5 | -5.0 | -61.3 |
| 2025-07-21 | 4.65 | -3.5 | 0.75 | 29.9 | -0.15 | 3.80 | 41.8 | -3.7 | 76.0 | -0.4 |
In [23]:
stock_sd = df_s_diff.std()
In [24]:
df_stock_sd = pd.DataFrame(stock_sd)
In [25]:
future_sd = df_f_diff.std()
In [26]:
df_future_sd = pd.DataFrame(future_sd)
In [27]:
combined_diff_df = pd.concat([df_s_diff, df_f_diff], axis=1)
full_correlation_matrix = combined_diff_df.corr()
stocks_list = df_s_diff.columns.tolist()
futures_list = df_f_diff.columns.tolist()
cross_correlation_matrix = full_correlation_matrix.loc[stocks_list, futures_list]
cross_correlation_matrix.head(10)
Out[27]:
| ticker | Bharat Electronics Ltd Futures. | Infosys Ltd Futures. | Tata Steel Ltd Futures. | Larsen & Toubro Ltd Futures. | Nestle India Ltd Futures. | Power Grid Corporation of India Ltd Futures. | Mahindra & Mahindra Ltd Futures. | Sun Pharmaceutical Industries Ltd Futures. | UltraTech Cement Ltd Futures. | Axis Bank Ltd Futures. |
|---|---|---|---|---|---|---|---|---|---|---|
| ticker | ||||||||||
| Bharat Electronics Ltd. | 0.986785 | 0.249701 | 0.505220 | 0.225658 | -0.005924 | 0.149871 | 0.583512 | 0.258634 | 0.399662 | 0.551980 |
| Infosys Ltd. | 0.262463 | 0.976238 | 0.331776 | 0.517450 | 0.487080 | 0.148953 | 0.573552 | 0.534089 | 0.536314 | 0.109932 |
| Tata Steel Ltd. | 0.552945 | 0.365612 | 0.997336 | 0.386667 | -0.032904 | -0.006160 | 0.407206 | 0.500335 | 0.494317 | -0.001099 |
| Larsen & Toubro Ltd. | 0.257266 | 0.464798 | 0.356819 | 0.997781 | 0.238791 | -0.111741 | 0.395264 | 0.509369 | 0.565838 | 0.365949 |
| Nestle India Ltd. | -0.042971 | 0.363072 | -0.050974 | 0.243894 | 0.994819 | 0.031938 | 0.347258 | -0.130333 | 0.341507 | 0.065604 |
| Power Grid Corporation of India Ltd. | 0.080218 | 0.165959 | -0.110377 | -0.115040 | 0.117942 | 0.965511 | 0.006743 | -0.164662 | -0.218182 | 0.163207 |
| Mahindra & Mahindra Ltd. | 0.564256 | 0.540321 | 0.318724 | 0.373640 | 0.407139 | 0.063973 | 0.979641 | 0.292210 | 0.611682 | 0.386311 |
| Sun Pharmaceutical Industries Ltd. | 0.327838 | 0.531385 | 0.484527 | 0.517836 | -0.107803 | -0.101490 | 0.348414 | 0.995550 | 0.509032 | 0.142312 |
| UltraTech Cement Ltd. | 0.431419 | 0.387358 | 0.553294 | 0.558458 | 0.280896 | 0.032594 | 0.500310 | 0.511584 | 0.923255 | 0.298574 |
| Axis Bank Ltd. | 0.568495 | 0.072589 | -0.063410 | 0.385587 | 0.109949 | 0.170823 | 0.439102 | 0.134345 | 0.336769 | 0.994870 |
In [28]:
squared_matrix = cross_correlation_matrix.pow(2)
In [29]:
squared_matrix.head(10)
Out[29]:
| ticker | Bharat Electronics Ltd Futures. | Infosys Ltd Futures. | Tata Steel Ltd Futures. | Larsen & Toubro Ltd Futures. | Nestle India Ltd Futures. | Power Grid Corporation of India Ltd Futures. | Mahindra & Mahindra Ltd Futures. | Sun Pharmaceutical Industries Ltd Futures. | UltraTech Cement Ltd Futures. | Axis Bank Ltd Futures. |
|---|---|---|---|---|---|---|---|---|---|---|
| ticker | ||||||||||
| Bharat Electronics Ltd. | 0.973744 | 0.062351 | 0.255247 | 0.050921 | 0.000035 | 0.022461 | 0.340486 | 0.066891 | 0.159730 | 0.304682 |
| Infosys Ltd. | 0.068887 | 0.953041 | 0.110075 | 0.267754 | 0.237247 | 0.022187 | 0.328962 | 0.285251 | 0.287633 | 0.012085 |
| Tata Steel Ltd. | 0.305749 | 0.133672 | 0.994679 | 0.149511 | 0.001083 | 0.000038 | 0.165817 | 0.250336 | 0.244349 | 0.000001 |
| Larsen & Toubro Ltd. | 0.066186 | 0.216037 | 0.127320 | 0.995567 | 0.057021 | 0.012486 | 0.156233 | 0.259457 | 0.320173 | 0.133919 |
| Nestle India Ltd. | 0.001846 | 0.131821 | 0.002598 | 0.059484 | 0.989665 | 0.001020 | 0.120588 | 0.016987 | 0.116627 | 0.004304 |
| Power Grid Corporation of India Ltd. | 0.006435 | 0.027543 | 0.012183 | 0.013234 | 0.013910 | 0.932211 | 0.000045 | 0.027114 | 0.047603 | 0.026637 |
| Mahindra & Mahindra Ltd. | 0.318385 | 0.291947 | 0.101585 | 0.139607 | 0.165762 | 0.004093 | 0.959696 | 0.085387 | 0.374155 | 0.149236 |
| Sun Pharmaceutical Industries Ltd. | 0.107477 | 0.282370 | 0.234766 | 0.268154 | 0.011621 | 0.010300 | 0.121392 | 0.991119 | 0.259114 | 0.020253 |
| UltraTech Cement Ltd. | 0.186122 | 0.150047 | 0.306134 | 0.311876 | 0.078902 | 0.001062 | 0.250311 | 0.261718 | 0.852401 | 0.089147 |
| Axis Bank Ltd. | 0.323186 | 0.005269 | 0.004021 | 0.148678 | 0.012089 | 0.029181 | 0.192811 | 0.018049 | 0.113413 | 0.989766 |
In [30]:
combined_sd_df = pd.concat([df_stock_sd, df_future_sd], axis=0)
In [31]:
combined_series = combined_sd_df.iloc[:, 0]
In [32]:
column_vector = combined_series.values.reshape(-1, 1)
In [33]:
row_vector = column_vector.T
division_matrix = column_vector / row_vector
In [34]:
division_df = pd.DataFrame(division_matrix, index=combined_series.index, columns=combined_series.index)
In [35]:
cross_division_matrix = division_df.loc[stocks_list, futures_list]
In [36]:
cross_division_matrix.head(10)
Out[36]:
| ticker | Bharat Electronics Ltd Futures. | Infosys Ltd Futures. | Tata Steel Ltd Futures. | Larsen & Toubro Ltd Futures. | Nestle India Ltd Futures. | Power Grid Corporation of India Ltd Futures. | Mahindra & Mahindra Ltd Futures. | Sun Pharmaceutical Industries Ltd Futures. | UltraTech Cement Ltd Futures. | Axis Bank Ltd Futures. |
|---|---|---|---|---|---|---|---|---|---|---|
| ticker | ||||||||||
| Bharat Electronics Ltd. | 1.027083 | 0.271611 | 1.845485 | 0.092423 | 0.239103 | 1.814600 | 0.142782 | 0.172691 | 0.051199 | 0.301467 |
| Infosys Ltd. | 3.730644 | 0.986566 | 6.703300 | 0.335704 | 0.868486 | 6.591120 | 0.518624 | 0.627260 | 0.185968 | 1.095010 |
| Tata Steel Ltd. | 0.544716 | 0.144050 | 0.978756 | 0.049017 | 0.126809 | 0.962377 | 0.075725 | 0.091587 | 0.027153 | 0.159884 |
| Larsen & Toubro Ltd. | 11.403298 | 3.015592 | 20.489687 | 1.026133 | 2.654664 | 20.146789 | 1.585255 | 1.917318 | 0.568440 | 3.347069 |
| Nestle India Ltd. | 4.280506 | 1.131976 | 7.691304 | 0.385184 | 0.996493 | 7.562590 | 0.595064 | 0.719712 | 0.213378 | 1.256404 |
| Power Grid Corporation of India Ltd. | 0.515170 | 0.136236 | 0.925669 | 0.046358 | 0.119931 | 0.910178 | 0.071618 | 0.086619 | 0.025681 | 0.151212 |
| Mahindra & Mahindra Ltd. | 7.399666 | 1.956835 | 13.295876 | 0.665864 | 1.722627 | 13.073368 | 1.028681 | 1.244159 | 0.368864 | 2.171933 |
| Sun Pharmaceutical Industries Ltd. | 5.681430 | 1.502449 | 10.208514 | 0.511247 | 1.322625 | 10.037673 | 0.789817 | 0.955259 | 0.283212 | 1.667600 |
| UltraTech Cement Ltd. | 20.783422 | 5.496158 | 37.344092 | 1.870210 | 4.838338 | 36.719134 | 2.889255 | 3.494465 | 1.036028 | 6.100301 |
| Axis Bank Ltd. | 3.435959 | 0.908636 | 6.173804 | 0.309187 | 0.799884 | 6.070484 | 0.477658 | 0.577712 | 0.171278 | 1.008515 |
In [74]:
Hedge_Ratio = cross_correlation_matrix * cross_division_matrix
In [75]:
Hedge_Ratio.head(10)
Out[75]:
| ticker | Bharat Electronics Ltd Futures. | Infosys Ltd Futures. | Tata Steel Ltd Futures. | Larsen & Toubro Ltd Futures. | Nestle India Ltd Futures. | Power Grid Corporation of India Ltd Futures. | Mahindra & Mahindra Ltd Futures. | Sun Pharmaceutical Industries Ltd Futures. | UltraTech Cement Ltd Futures. | Axis Bank Ltd Futures. |
|---|---|---|---|---|---|---|---|---|---|---|
| ticker | ||||||||||
| Bharat Electronics Ltd. | 1.013510 | 0.067822 | 0.932375 | 0.020856 | -0.001416 | 0.271956 | 0.083315 | 0.044664 | 0.020462 | 0.166404 |
| Infosys Ltd. | 0.979155 | 0.963123 | 2.223995 | 0.173710 | 0.423022 | 0.981769 | 0.297458 | 0.335013 | 0.099737 | 0.120376 |
| Tata Steel Ltd. | 0.301198 | 0.052666 | 0.976149 | 0.018953 | -0.004173 | -0.005929 | 0.030836 | 0.045824 | 0.013422 | -0.000176 |
| Larsen & Toubro Ltd. | 2.933677 | 1.401640 | 7.311102 | 1.023856 | 0.633911 | -2.251227 | 0.626594 | 0.976623 | 0.321645 | 1.224857 |
| Nestle India Ltd. | -0.183937 | 0.410989 | -0.392057 | 0.093944 | 0.991330 | 0.241532 | 0.206641 | -0.093802 | 0.072870 | 0.082425 |
| Power Grid Corporation of India Ltd. | 0.041326 | 0.022610 | -0.102173 | -0.005333 | 0.014145 | 0.878787 | 0.000483 | -0.014263 | -0.005603 | 0.024679 |
| Mahindra & Mahindra Ltd. | 4.175310 | 1.057319 | 4.237712 | 0.248793 | 0.701349 | 0.836341 | 1.007738 | 0.363555 | 0.225628 | 0.839041 |
| Sun Pharmaceutical Industries Ltd. | 1.862586 | 0.798379 | 4.946301 | 0.264742 | -0.142582 | -1.018723 | 0.275183 | 0.951008 | 0.144164 | 0.237320 |
| UltraTech Cement Ltd. | 8.966357 | 2.128983 | 20.662249 | 1.044434 | 1.359068 | 1.196810 | 1.445524 | 1.787712 | 0.956518 | 1.821392 |
| Axis Bank Ltd. | 1.953325 | 0.065957 | -0.391480 | 0.119219 | 0.087946 | 1.036981 | 0.209741 | 0.077613 | 0.057681 | 1.003341 |
In [ ]:
In [ ]: