-
Notifications
You must be signed in to change notification settings - Fork 192
/
ibor_index.pyx
100 lines (84 loc) · 4.09 KB
/
ibor_index.pyx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
include '../types.pxi'
from cython.operator cimport dereference as deref
from libcpp.string cimport string
from libcpp cimport bool
from quantlib.handle cimport shared_ptr, Handle
from quantlib.time.date cimport Period
from quantlib.time.daycounter cimport DayCounter
from quantlib.currency.currency cimport Currency
from quantlib.time.calendar cimport Calendar
from quantlib.time.businessdayconvention cimport ModifiedFollowing, BusinessDayConvention
from quantlib.termstructures.yield_term_structure cimport YieldTermStructure
cimport quantlib.termstructures._yield_term_structure as _yts
cimport quantlib._index as _in
cimport quantlib.indexes._ibor_index as _ib
from quantlib.time.api import calendar_from_name
from quantlib.market.conventions.swap import params as swap_params
from quantlib.indexes.interest_rate_index cimport InterestRateIndex
cdef class IborIndex(InterestRateIndex):
def __init__(self, str family_name, Period tenor not None, Natural settlement_days,
Currency currency, Calendar fixing_calendar, int convention,
bool end_of_month, DayCounter day_counter not None,
YieldTermStructure yts=YieldTermStructure()):
self._thisptr = shared_ptr[_in.Index](
new _ib.IborIndex(family_name.encode('utf-8'),
deref(tenor._thisptr),
settlement_days,
deref(currency._thisptr),
fixing_calendar._thisptr,
<BusinessDayConvention> convention,
end_of_month,
deref(day_counter._thisptr),
yts._thisptr)
)
property business_day_convention:
def __get__(self):
cdef _ib.IborIndex* ref = <_ib.IborIndex*>self._thisptr.get()
return ref.businessDayConvention()
property end_of_month:
def __get__(self):
cdef _ib.IborIndex* ref = <_ib.IborIndex*>self._thisptr.get()
return ref.endOfMonth()
@property
def forwarding_term_structure(self):
cdef:
_ib.IborIndex* ref = <_ib.IborIndex*>self._thisptr.get()
YieldTermStructure yts = YieldTermStructure.__new__(YieldTermStructure)
Handle[_yts.YieldTermStructure] _yts = ref.forwardingTermStructure()
if not _yts.empty():
yts._thisptr.linkTo(_yts.currentLink())
return yts
@staticmethod
def from_name(market, term_structure=YieldTermStructure(), **kwargs):
"""
Create default IBOR for the market, modify attributes if provided
"""
row = swap_params(market)
row = row._replace(**kwargs)
if row.currency == 'EUR':
from quantlib.indexes.ibor.euribor import Euribor
ibor_index = Euribor(Period(row.floating_leg_period), term_structure)
else:
label = row.currency + ' ' + row.floating_leg_reference
from quantlib.indexes.ibor.libor import Libor
ibor_index = Libor(label,
Period(row.floating_leg_period),
row.settlement_days,
Currency.from_name(row.currency),
calendar_from_name(row.calendar),
DayCounter.from_name(row.floating_leg_daycount),
term_structure)
return ibor_index
cdef class OvernightIndex(IborIndex):
def __init__(self, str family_name, Natural settlement_days,
Currency currency, Calendar fixing_calendar,
DayCounter day_counter not None,
YieldTermStructure yts=YieldTermStructure()):
self._thisptr = shared_ptr[_in.Index](
new _ib.OvernightIndex(family_name.encode('utf-8'),
settlement_days,
deref(currency._thisptr),
fixing_calendar._thisptr,
deref(day_counter._thisptr),
yts._thisptr)
)