// Valuation of Interest Rate Derivatives. See the Excel spreadsheet
// for context.
def PV(sigma: Double) : Double = {
var yc=qlw.qlFlatForward(UU("flatfowrard"),
ONull(),
new property_t("NullCalendar"),
new property_t(0.044),
ONull(),
new property_t("Continuous"),
new property_t("Annual"))
var vc=qlw.qlConstantSwaptionVolatility(UU("vol"),
new property_t(0),
"TARGET", "f",
new property_t(sigma),
ONull()
)
var refDate = qlw.qlSettingsEvaluationDate();
var calendar="TARGET"
var pv=new PropertyVector()
pv.push_back(new property_t(refDate))
var adjustedRefDate=qlw.qlCalendarAdjust(calendar, pv, new property_t("f"))
var pv2=new PropertyVector()
pv2.push_back(new property_t("2d"))
var effectiveDate=qlw.qlCalendarAdvance(calendar
, new property_t(adjustedRefDate.get(0))
, pv2
, ONull()
, ONull() ).get(0)
var pv3=new PropertyVector()
pv3.push_back(new property_t("10Y"))
var terminationDate=qlw.qlCalendarAdvance(calendar
, new property_t(effectiveDate)
, pv3
, new property_t("Unadjusted")
, ONull() ).get(0)
var sFixed=qlw.qlSchedule(UU("schedule")
, new property_t(effectiveDate+365)
, new property_t(terminationDate)
, "1Y"
, new property_t(calendar)
, new property_t("Modified Following")
, new property_t("Modified Following")
, new property_t("Backward")
, ONull()
, ONull()
, ONull())
var sFloating=qlw.qlSchedule(UU("schedule")
, new property_t(effectiveDate+365)
, new property_t(terminationDate)
, "6M"
, new property_t(calendar)
, new property_t("Modified Following")
, new property_t("Modified Following")
, new property_t("Backward")
, ONull()
, ONull()
, ONull())
var ibor=qlw.qlEuribor(UU("IBOR"),
"6M",
new property_t(yc))
var vanswap=qlw.qlVanillaSwap(UU(""),
new property_t("Payer"),
new property_t(1e6),
sFixed,
new property_t(0.05),
"30/360 (Bond Basis)",
sFloating,
ibor,
new property_t(0.0),
"Actual/360",
ONull())
var pe= qlw.qlBlackSwaptionEngine(UU("PE"), yc, vc)
var ee=qlw.qlEuropeanExercise(UU(""), new property_t("1Y"))
var ii=qlw.qlSwaption(UU(""),
vanswap,
ee,
"Physical")
qlw.qlInstrumentSetPricingEngine(ii, pe)
var NPV=qlw.qlInstrumentNPV(ii)
// Clean-up all created objects
qlw.ohRepositoryDeleteAllObjects(ONull())
NPV;
}