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

Price bond with yield #18

Open
Skumin opened this issue Nov 12, 2020 · 0 comments
Open

Price bond with yield #18

Skumin opened this issue Nov 12, 2020 · 0 comments

Comments

@Skumin
Copy link

Skumin commented Nov 12, 2020

I'm trying to price a fixed-rate coupon bond using the bond's yield. The code I'm using is the following:

using QuantLib, Dates

# Params
settlement_date = Date(2015, 1, 5)
maturity_date = Date(2025, 1, 1)
issue_date = Date(2010, 1, 1)
coupon_rate = 5 / 100
yild = 5 / 100
face = 100.0

# Run
set_eval_date!(settings, settlement_date)

fixed_schedule = QuantLib.Time.Schedule(issue_date, maturity_date, QuantLib.Time.TenorPeriod(QuantLib.Time.Semiannual()), QuantLib.Time.Unadjusted(), QuantLib.Time.Unadjusted(), QuantLib.Time.DateGenerationBackwards(), false, QuantLib.Time.USGovernmentBondCalendar());
ts = FlatForwardTermStructure(0, QuantLib.Time.USGovernmentBondCalendar(), Quote(yild), QuantLib.Time.ISMAActualActual(), CompoundedCompounding() , QuantLib.Time.Semiannual());

bond = FixedRateBond(0, face, fixed_schedule, coupon_rate, QuantLib.Time.ISMAActualActual(), QuantLib.Time.ModifiedFollowing(), face, issue_date, fixed_schedule.cal, DiscountingBondEngine(ts));
npv(bond)

This returns the following error: ERROR: negative time not allowed! Time fraction is -4.5. If I re-run the last two lines, the code works, however, and I get a price of 100. Am I doing something wrong in the first run of the code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant