Python Forum
another alternative to np.interp
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
another alternative to np.interp
#1
I am doing finance programming and i need another solution instead of using numpy's np.interp. I have a yield curve table which shows interest rates for bonds, for the respective tenure.

i am new to python

the tenures are 1 month, 2 months, 3 months.... up to 30 years, i converted to fraction and whole numbers for calculation purpose. there are 12 tenure and 12 interest rate respectively.

tenure = [1/12, 2/12, 3/12, 6/12, 1, 2, 3, 5, 7, 10, 20, 30]
interest_rates = [2.40, 2.40, 2.42, 2.51, 2.60, 2.50, 2.47, 2.49, 2.56, 2.66, 2.83, 2.97]

i understand that one way i can do is to use np.interp

calculate_interest_rate = np.interp (year, tenure, interest_rates)
year = x (my input depending which year i am interested in)

i need to make a user defined function to automate the calculation of the interest rate for the respective tenure. for example, a 1.5 (input) year bond will return 2.55% of interest rate.

is there another another way i can get the same outcome but not using np.interp? something like a for loop or something? i really have no idea.

also, i am given a mathematical formula for calculation of the interest rate, the required inputs in for formula are the tenure and interest rate before and after the tenure i want to calculate. is there a way i can get the numbers with python function, and then use the numbers i obtain to sub into my mathematical formula?

for example, if i want to calculate the interest rate at 1.5 years
the inputs i need in the mathematical function are:
1 year (tenure) - 2.60% (interest rates)
2 year (tenure) - 2.50% (interest rates)
Reply
#2
home cook your own, see: https://en.wikipedia.org/wiki/Linear_interpolation
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Twilio alternative jmair 3 3,892 Feb-08-2024, 01:55 PM
Last Post: Sharmi
  Pillow alternative? kucingkembar 4 865 Jul-27-2023, 10:50 AM
Last Post: Larz60+
  Alternative for Cairosvg? Maryan 0 2,450 Oct-26-2020, 01:27 PM
Last Post: Maryan
  Multithreading alternative MartinV279 1 2,777 Aug-01-2019, 11:41 PM
Last Post: scidam
  Array alternative oldcity 3 3,470 Oct-01-2018, 10:03 PM
Last Post: ichabod801
  If elif else alternative brocq_18 13 12,207 Apr-12-2017, 06:53 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020