Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REF: change repr for Schedule and BondFuture #416

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions python/rateslib/instruments/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4166,6 +4166,9 @@ def __init__(
)
self._cfs = NoInput(0)

def __repr__(self):
return f"<rl.BondFuture at {hex(id(self))}>"

@property
def notional(self):
"""
Expand Down
3 changes: 3 additions & 0 deletions python/rateslib/scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,9 @@ def _attribute_schedules(self):
self.stubs[-1] = True

def __repr__(self):
return f"<rl.Schedule at {hex(id(self))}>"

def __str__(self):
str = (
f"freq: {self.frequency}, stub: {self.stub}, roll: {self.roll}"
f", pay lag: {self.payment_lag}, modifier: {self.modifier}\n"
Expand Down
14 changes: 14 additions & 0 deletions python/tests/test_instruments_bonds.py
Original file line number Diff line number Diff line change
Expand Up @@ -2174,6 +2174,20 @@ def test_settle_method_param_combinations(self) -> None:


class TestBondFuture:
def test_repr(self):
kwargs = dict(
effective=dt(2020, 1, 1),
stub="ShortFront",
frequency="A",
calendar="tgt",
currency="eur",
convention="ActActICMA",
)
bond1 = FixedRateBond(termination=dt(2022, 3, 1), fixed_rate=1.5, **kwargs)
fut = BondFuture(delivery=dt(2021, 3, 1), coupon=6.0, basket=[bond1])
expected = f"<rl.BondFuture at {hex(id(fut))}>"
assert expected == fut.__repr__()

@pytest.mark.parametrize(
("delivery", "mat", "coupon", "exp"),
[
Expand Down
14 changes: 12 additions & 2 deletions python/tests/test_scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,17 @@ def test_infer_stub_date_eom(cal_) -> None:
assert result[1]["front_stub"] == dt(2022, 5, 31)


def test_schedule_repr(cal_) -> None:
def test_repr():
schedule = Schedule(
dt(2022, 1, 1),
"2M",
"M",
)
expected = f"<rl.Schedule at {hex(id(schedule))}>"
assert expected == schedule.__repr__()


def test_schedule_str(cal_) -> None:
schedule = Schedule(
dt(2022, 1, 1),
"2M",
Expand All @@ -298,7 +308,7 @@ def test_schedule_repr(cal_) -> None:
defaults.headers["payment"]: [dt(2022, 2, 2), dt(2022, 3, 2)],
},
)
assert schedule.__repr__() == expected + df.__repr__()
assert schedule.__str__() == expected + df.__repr__()


def test_schedule_raises(cal_) -> None:
Expand Down
Loading