# Calculating price -> yield and yield -> price for fixed rate bonds using QLNet

I'm trying to implement a simple calculation module to calculate fixed rate bond yield given the price (and then price based on yield to verify the calculation). I've looked at a number of examples (including Bonds example) but in some cases I'm seeing difference from the numbers future users currently retrieve from Bloomberg. Here's my code (BondData class defines bond attributes that I load from a .csv file). In most examples I'm matching yield numbers (in some cases I'm off by 1-2bps) but having hard time matching price. Also, yields don't match when redemption value is different from face value. Is there something obvious that I'm missing?

Thank you,

Jim

int fixingDays = 1;
Date todaysDate = calendar.advance(bond.SettlementDate, -fixingDays, TimeUnit.Days);
Settings.setEvaluationDate(todaysDate);

// Rate
Schedule fixedBondSchedule = new Schedule(
bond.IssueDate,
bond.Maturity,
new Period(bond.Frequency),
new UnitedStates(UnitedStates.Market.GovernmentBond),
DateGeneration.Rule.Backward,
false);

FixedRateBond fixedRateBond = new FixedRateBond(
1,
bond.FaceAmount,
fixedBondSchedule,
new List<double>() { bond.CouponRate }, // { 1, couponRate }
bond.DayCounter,
bond.Redemption,
bond.IssueDate);

bond.YieldCalc = fixedRateBond.yield(
bond.Price,
bond.DayCounter,
Compounding.Compounded,
bond.Frequency,
bond.SettlementDate);

Handle<FlatTermStructure> flatTermStructure = new Handle<FlatTermStructure>(
new FlatForward(
bond.SettlementDate,
bond.Yield,
bond.DayCounter,
Compounding.Compounded,
bond.Frequency));