Ad

Interpolate A Date Between Two Other Dates To Get A Value

I have this pandas dataframe:

     ISIN             MATURITY       PRICE   
 0  AR121489 Corp     29/09/2019    5.300
 1  AR714081 Corp     29/12/2019    7.500
 2  AT452141 Corp     29/06/2020    2.950
 3  QJ100923 Corp     29/09/2020    6.662

My question is if there exists a way to interpolate a date in the column "MATURITY" and get the price value of that date. For example, If I select the date 18/11/2019, the value of the price on that date should be between 5.300 and 7.500. I don't know if what I am asking is possible but thank you so much for taking your time to read it and trying to help me.

Ad

Answer

What you can do if you wanted a daily frequency interpolated is first create a daily frequency range with your start and end-dates.

new_df = pd.DataFrame()
new_df["MATURITY"] = pd.date_range(start='29/09/2019', end='29/09/2020')
new_df = pd.concat([new_df,old_df], join="outer", axis=1)
new_df["PRICE"] = new_df["PRICE"].interpolate(method = "linear")
Ad
source: stackoverflow.com
Ad