19#include <boost/make_shared.hpp>
20#include <ql/math/solvers1d/brent.hpp>
21#include <ql/termstructures/yieldtermstructure.hpp>
32 PriceError(
const Bond& engine, SimpleQuote& spread, Real targetValue,
bool isCleanPrice);
33 Real operator()(Real spread)
const;
42PriceError::PriceError(
const Bond& bond, SimpleQuote& spread, Real targetValue,
bool isCleanPrice)
45Real PriceError::operator()(Real spread)
const {
55Real ImpliedBondSpreadHelper::calculate(
const QuantLib::ext::shared_ptr<Bond>& bond,
56 const QuantLib::ext::shared_ptr<PricingEngine>& engine,
57 const QuantLib::ext::shared_ptr<SimpleQuote>& spreadQuote, Real targetValue,
58 bool isCleanPrice, Real accuracy, Natural maxEvaluations, Real minSpread,
61 Bond clonedBond = *bond;
62 clonedBond.setPricingEngine(engine);
63 clonedBond.recalculate();
64 spreadQuote->setValue(0.005);
66 PriceError f(clonedBond, *spreadQuote, targetValue, isCleanPrice);
68 solver.setMaxEvaluations(maxEvaluations);
69 Real guess = (minSpread + maxSpread) / 2.0;
70 Real result = solver.solve(f, accuracy, guess, minSpread, maxSpread);
utilities for implied bond credit spread calculation