index_left#
- rateslib.curves.index_left(list_input, list_length, value, left_count=0)#
Return the interval index of a value from an ordered input list on the left side.
- Parameters:
input (list) – Ordered list (lowest to highest) containing datatypes the same as value.
length (int) – The length of
input
.value (Any) – The value for which to determine the list index of.
left_count (int) – The counter to pass recursively to determine the output. Users should not directly specify, it is used in internal calculation only.
- Returns:
int – from)
- Return type:
The left index of the interval within which value is found (or extrapolated
Notes
Uses a binary search method which operates with time \(O(log_2 n)\).
Examples
In [1]: from rateslib.curves import index_left
Out of domain values return the left-side index of the closest matching interval. 100 is attributed to the interval (1, 2].
In [2]: list = [0, 1, 2] In [3]: index_left(list, 3, 100) Out[3]: 1
-100 is attributed to the interval (0, 1].
In [4]: index_left(list, 3, -100) Out[4]: 0
Interior values return the left-side index of the interval. 1.45 is attributed to the interval (1, 2].
In [5]: index_left(list, 3, 1.45) Out[5]: 1
1 is attributed to the interval (0, 1].
In [6]: index_left(list, 3, 1) Out[6]: 0