2

I have df with the endDate column, which I want to use as my x array and discountFactor column as y array. The goal is to interpolate discountFactor at some date within the range of x array, let's say 2020-12-31 using cubic spline method.

The source df below:

lst = [['6M', '2020-10-26', '2021-04-26', '-0.521684','1.002611'], ['1Y', '2020-10-26', '2021-10-26', '-0.534855','1.005377'], 
       ['5Y', '2020-10-26', '2025-10-27','-0.495927','1.025184']] 
    
df = pd.DataFrame(lst, columns =['tenor', 'startDate', 'endDate','ratePercent','discountFactor'], dtype = float)

Please see the following steps, which unfortunately lead to df with all NaN columns, even there where I had known discountFacor values

# Converting date column strings to date objects
df['endDate'] = pd.to_datetime(df['endDate'], format='%Y-%m-%d')
df['startDate'] = pd.to_datetime(df['startDate'], format='%Y-%m-%d')
# Setting endDate column as my index
df.set_index("endDate", inplace= True)
# Creating daily dates range between start and end dates from the df
dates_range = pd.date_range(start='2020-10-26', end='2025-10-27')
idx = pd.DatetimeIndex(dates_range)
df = df.reindex(idx)
Mr. T
  • 11,960
  • 10
  • 32
  • 54
John
  • 17
  • 4
  • I tried to create tge daily range and combine known discountFactor and dates with those which are unknown with dates schedule, however I am getting NaN for the whole table df.set_index("endDate", inplace= True) dates_range = pd.date_range(start='2021-04-26', end='2025-10-27') index= pd.DatetimeIndex(dates_range) df.reindex(index) – John Oct 26 '20 at 08:36
  • Much better. I understand that we have not reached the interpolation part but are at the resampling stage. What is the expected output of your sample `df`? – Mr. T Oct 27 '20 at 10:37
  • Try looking at https://stackoverflow.com/questions/27926669/how-do-you-interpolate-from-an-array-containing-datetime-objects –  Oct 27 '20 at 11:30

0 Answers0