Skip to content

Commit d76bf79

Browse files
authored
DOC: updates (#140) (#1060)
Co-authored-by: JHM Darbyshire (M1) <attack68@users.noreply.github.com>
1 parent 1fbba1b commit d76bf79

File tree

3 files changed

+118
-55
lines changed

3 files changed

+118
-55
lines changed

python/rateslib/periods/components/cashflow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class Cashflow(_BasePeriodStatic):
6666
currency="eur",
6767
notional=125000,
6868
)
69-
print(period.cashflows())
69+
period.cashflows()
7070
7171
.. role:: red
7272
@@ -294,7 +294,7 @@ class MtmCashflow(_BasePeriodStatic):
294294
fx_fixings_start=1.10,
295295
fx_fixings_end=1.20,
296296
)
297-
print(period.cashflows())
297+
period.cashflows()
298298
299299
.. role:: red
300300

python/rateslib/periods/components/fixed_period.py

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,28 @@ class FixedPeriod(_BasePeriodStatic):
6060
6161
.. role:: green
6262
63+
.. rubric:: Examples
64+
65+
.. ipython:: python
66+
:suppress:
67+
68+
from rateslib.periods.components import FixedPeriod
69+
from datetime import datetime as dt
70+
71+
.. ipython:: python
72+
73+
period = FixedPeriod(
74+
start=dt(2000, 1, 1),
75+
end=dt(2001, 1, 1),
76+
payment=dt(2001, 1, 1),
77+
fixed_rate=5.0,
78+
notional=1e6,
79+
convention="ActActICMA",
80+
frequency="A",
81+
)
82+
period.cashflows()
83+
84+
6385
Parameters
6486
----------
6587
.
@@ -382,6 +404,24 @@ class ZeroFixedPeriod(_BasePeriodStatic):
382404
383405
For *analytic delta* purposes the :math:`\xi=-R`.
384406
407+
.. rubric:: Examples
408+
409+
.. ipython:: python
410+
:suppress:
411+
412+
from rateslib.periods.components import ZeroFixedPeriod
413+
from rateslib.scheduling import Schedule
414+
from datetime import datetime as dt
415+
416+
.. ipython:: python
417+
418+
period = ZeroFixedPeriod(
419+
schedule=Schedule(dt(2000, 1, 1), "5Y", "A"),
420+
fixed_rate=5.0,
421+
convention="1",
422+
)
423+
period.cashflows()
424+
385425
.. role:: red
386426
387427
.. role:: green
@@ -448,28 +488,6 @@ class ZeroFixedPeriod(_BasePeriodStatic):
448488
index_only: bool, :green:`optional (set as False)`
449489
A flag which determines non-payment of notional on supported *Periods*.
450490
451-
452-
Examples
453-
--------
454-
455-
A typical :class:`~rateslib.periods.components.ZeroFixedPeriod`.
456-
457-
.. ipython:: python
458-
:suppress:
459-
460-
from rateslib.periods.components import ZeroFixedPeriod
461-
from rateslib.scheduling import Schedule
462-
from datetime import datetime as dt
463-
464-
.. ipython:: python
465-
466-
period = ZeroFixedPeriod(
467-
schedule=Schedule(dt(2000, 1, 1), "5Y", "A"),
468-
fixed_rate=5.0,
469-
convention="1",
470-
)
471-
period.cashflows()
472-
473491
""" # noqa: E501
474492

475493
@property

python/rateslib/periods/components/float_period.py

Lines changed: 76 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,37 @@ class FloatPeriod(_BasePeriodStatic):
7979
8080
.. role:: green
8181
82+
.. rubric:: Examples
83+
84+
.. ipython:: python
85+
:suppress:
86+
87+
from rateslib.periods.components import FloatPeriod
88+
from rateslib import fixings
89+
from datetime import datetime as dt
90+
from pandas import Series
91+
92+
.. ipython:: python
93+
94+
fixings.add("MY_RATE_INDEX_6M", Series(index=[dt(2000, 1, 1)], data=[2.66]))
95+
period = FloatPeriod(
96+
start=dt(2000, 1, 1),
97+
end=dt(2000, 7, 1),
98+
payment=dt(2000, 7, 1),
99+
notional=1e6,
100+
convention="Act360",
101+
frequency="S",
102+
fixing_method="ibor",
103+
method_param=0,
104+
rate_fixings="MY_RATE_INDEX"
105+
)
106+
period.cashflows()
107+
108+
.. ipython:: python
109+
:suppress:
110+
111+
fixings.pop("MY_RATE_INDEX_6M")
112+
82113
Parameters
83114
----------
84115
.
@@ -494,6 +525,35 @@ class ZeroFloatPeriod(_BasePeriodStatic):
494525
495526
For *analytic delta* purposes the :math:`\xi=-z`.
496527
528+
.. rubric:: Examples
529+
530+
.. ipython:: python
531+
:suppress:
532+
533+
from rateslib.periods.components import ZeroFloatPeriod
534+
from rateslib.scheduling import Schedule
535+
from datetime import datetime as dt
536+
537+
.. ipython:: python
538+
539+
fixings.add("MY_RATE_INDEX_6M", Series(
540+
index=[dt(2000, 1, 1), dt(2000, 7, 1), dt(2001, 1, 1), dt(2001, 7, 1)],
541+
data=[1.0, 2.0, 3.0, 4.0]
542+
))
543+
period = ZeroFloatPeriod(
544+
schedule=Schedule(dt(2000, 1, 1), "2Y", "S"),
545+
fixing_method="IBOR",
546+
rate_fixings="MY_RATE_INDEX",
547+
convention="Act360",
548+
method_param=0,
549+
)
550+
period.cashflows()
551+
552+
.. ipython:: python
553+
:suppress:
554+
555+
fixings.pop("MY_RATE_INDEX_6M")
556+
497557
.. role:: red
498558
499559
.. role:: green
@@ -581,35 +641,12 @@ class ZeroFloatPeriod(_BasePeriodStatic):
581641
index_only: bool, :green:`optional (set as False)`
582642
A flag which determines non-payment of notional on supported *Periods*.
583643
584-
585-
Examples
586-
--------
587-
588-
A typical :class:`~rateslib.periods.components.ZeroFloatPeriod`.
589-
590-
.. ipython:: python
591-
:suppress:
592-
593-
from rateslib.periods.components import ZeroFloatPeriod
594-
from rateslib.scheduling import Schedule
595-
from datetime import datetime as dt
596-
597-
.. ipython:: python
598-
599-
period = ZeroFloatPeriod(
600-
schedule=Schedule(dt(2000, 1, 1), "2Y", "S"),
601-
fixing_method="IBOR",
602-
rate_fixings=[1.1, 2.1, 3.1, 4.1],
603-
convention="Act360",
604-
)
605-
period.cashflows()
606-
607644
""" # noqa: E501
608645

609646
@property
610647
def rate_params(self) -> _FloatRateParams:
611648
"""The :class:`~rateslib.periods.components.parameters._FixedRateParams` of the *Period*."""
612-
return self._float_periods[0].rate_params
649+
return self.float_periods[0].rate_params
613650

614651
@property
615652
def period_params(self) -> _PeriodParams:
@@ -648,6 +685,14 @@ def float_spread(self, value: DualTypes) -> None:
648685
for period in self._float_periods:
649686
period.rate_params.float_spread = value
650687

688+
@property
689+
def float_periods(self) -> list[FloatPeriod]:
690+
"""
691+
The individual :class:`~rateslib.periods.components.period.FloatPeriod` that are
692+
compounded.
693+
"""
694+
return self._float_periods
695+
651696
def __init__(
652697
self,
653698
*,
@@ -746,8 +791,8 @@ def try_rate(
746791
**kwargs: Any,
747792
) -> Result[DualTypes]:
748793
try:
749-
r_i = [period.rate(rate_curve=rate_curve) for period in self._float_periods]
750-
d_i = [period.period_params.dcf for period in self._float_periods]
794+
r_i = [period.rate(rate_curve=rate_curve) for period in self.float_periods]
795+
d_i = [period.period_params.dcf for period in self.float_periods]
751796
except Exception as e:
752797
return Err(e)
753798

@@ -785,8 +830,8 @@ def unindexed_reference_cashflow(
785830
**kwargs: Any,
786831
) -> DualTypes:
787832
# determine each rate from individual Periods
788-
r_i = [period.rate(rate_curve=rate_curve) for period in self._float_periods]
789-
d_i = [period.period_params.dcf for period in self._float_periods]
833+
r_i = [period.rate(rate_curve=rate_curve) for period in self.float_periods]
834+
d_i = [period.period_params.dcf for period in self.float_periods]
790835
r = np.prod(1.0 + np.array(r_i) * np.array(d_i) / 100.0) - 1.0
791836
return -self.settlement_params.notional * r
792837

@@ -822,8 +867,8 @@ def try_unindexed_reference_cashflow_analytic_rate_fixings(
822867
fx_vol: FXVolOption_ = NoInput(0),
823868
) -> Result[DataFrame]:
824869
try:
825-
r_i = [period.rate(rate_curve=rate_curve) for period in self._float_periods]
826-
d_i = [period.period_params.dcf for period in self._float_periods]
870+
r_i = [period.rate(rate_curve=rate_curve) for period in self.float_periods]
871+
d_i = [period.period_params.dcf for period in self.float_periods]
827872
dfs_i = [
828873
period.try_unindexed_reference_cashflow_analytic_rate_fixings(
829874
rate_curve=rate_curve,
@@ -832,7 +877,7 @@ def try_unindexed_reference_cashflow_analytic_rate_fixings(
832877
fx_vol=fx_vol,
833878
index_curve=index_curve,
834879
).unwrap()
835-
for period in self._float_periods
880+
for period in self.float_periods
836881
]
837882
except Exception as e:
838883
return Err(e)

0 commit comments

Comments
 (0)