Re: Question about a formula of calculation of Yield of Bond in Quantlib
In the most general cases there isn't an explicit formula. Through a solver, you look for the rate r such that the sum of discounted cashflows (discount factors being function of r) is equal to the dirty price of the bond.
It's not a formula, it's the application of an iterative solver. The functions use one of the root solvers available in the library to find the zero of the CashFlows::IrrFinder::operator()(Rate y) method. In short: given a guess for the yield, the IrrFinder class calculates the corresponding price of the bond (see the call to CashFlows::npv in the IrrFinder::operator() method) and returns the difference between the calculation and the target price. The used solver iteratively changes the guess and tries to find the value for which difference is zero, that is, the yield for which the calculated price equals the target price.