I have a set of panel data that contains different bonds and the bond yields yields across multiple days.
I would like to create a function which, for a given day, takes two bonds and calculates the spread, and then does this for every bond pair, for every day.
The resulting dataframe will have the date, a column indicating which two bonds and then the yield spread.
Original dataframe:
data1 = {'Date':['26/10/2019', '26/10/2019', '26/10/2019', '26/10/2019', '25/10/2019', '25/10/2019', '25/10/2019',
'25/10/2019'],
'Bond':['A', 'B', 'C', 'D', 'A', 'B', 'C', 'D'],
'Yield':[1.1, 1.11, 1.2, 1.3, 1, 1.1, 1.25, 1.29]}
df1 = pd.DataFrame(data=data1)
Resulting dataframe:
data2 = {'Date':['26/10/2019', '26/10/2019', '26/10/2019', '26/10/2019','26/10/2019','26/10/2019', '25/10/2019',
'25/10/2019', '25/10/2019', '25/10/2019','25/10/2019','25/10/2019'],
'Bond':['BA', 'CB', 'CA', 'DC', 'DB', 'DA', 'BA', 'CB', 'CA', 'DC', 'DB', 'DA'],
'Yield':[0.01, 0.09, 0.1, 0.1, 0.19, 0.2, 0.1, 0.15, 0.25, 0.04, 0.19, 0.29]}
df2 = pd.DataFrame(data=data2)
Thank you in advance!