This function allows retrieval of miscellaneous values computed when an instrument is priced. These results are indexed by their string names and different types values of values are available depending on type of instrument and pricing engine.
Usage:
=qlInstrumentResults(<InstrumentId>, <ResultType>)
Instrument to retrieve the result for
Type of result to retrieve (see below)
List of the possible additional results (actual availability depends on instrument type and pricing engine):
“vega”
“dailyPositions”
“optionletsPrice”
“optionletsAtmForward”
“spreadCorrection”
“strike”
“atmForward”
“annuity”
“swapLength”
“stdDev”
“optionletsVega”
“optionletsStdDev”
Here is example usage in QLW – QuantLib-Addin like interface from Java and Python to calculate the vega of a swaption:
// Copyright (C) 2012 Bojan Nikolic <bojan@bnikolic.co.uk>
//
import co.uk.bnikolic.qlw.property_t;
import co.uk.bnikolic.qlw.qlw;
import co.uk.bnikolic.qlw.StringVector;
import co.uk.bnikolic.qlw.LongVector;
import co.uk.bnikolic.qlw.PropertyVector;
import co.uk.bnikolic.qlw.PropertyMatrix;
import co.uk.bnikolic.qlw.DoubleVector;
public class qlInstrumentResults {
public static void main(String[] args) throws Exception {
String engine=mkEngine();
String swaption=mkSwaption();
qlw.qlInstrumentSetPricingEngine(swaption, engine,
qlw.OH_NULL());
System.out.println("NPV: " + qlw.qlInstrumentNPV(swaption,
qlw.OH_NULL()));
System.out.println("Vega: " + qlw.qlInstrumentResults(swaption,
"vega",
qlw.OH_NULL()));
}
public static String mkSwaption() {
String swap=mkSwap();
String exercise=qlw.qlEuropeanExercise("exercise",
new property_t("41265"),
qlw.OH_NULL(),
qlw.OH_NULL(),
false);
String swaption=qlw.qlSwaption("swaption",
swap,
exercise,
"Cash",
qlw.OH_NULL(),
qlw.OH_NULL(),
false);
return swaption;
}
// See
// http://www.bnikolic.co.uk/ql/addindoc/f/qlMakeVanillaSwap.html
// for explanation of this function
public static String mkSwap() {
PropertyVector datesList= new PropertyVector();
datesList.add(new property_t("0D"));
datesList.add(new property_t("10Y"));
DoubleVector ratesList=new DoubleVector();
ratesList.add(0.01);
ratesList.add(0.01);
property_t dcc=new property_t("Actual/365 (Fixed)");
String curve=qlw.qlInterpolatedYieldCurve("swapcurve",
datesList,
ratesList,
"TARGET", dcc,
new PropertyVector(),
new PropertyVector(),
new property_t("ZeroYield"),
new property_t("LogLinear"),
qlw.OH_NULL(),
qlw.OH_NULL(),
false);
String engine=qlw.qlDiscountingSwapEngine("discounting-engine",
curve,
qlw.OH_NULL(),
qlw.OH_NULL(),
qlw.OH_NULL(),
qlw.OH_NULL(),
qlw.OH_NULL(),
false);
String index=qlw.qlEuribor("index","6M",
new property_t(curve),
qlw.OH_NULL(),
qlw.OH_NULL(),
false);
String swap=qlw.qlMakeVanillaSwap("swap",
"5Y",
index,
new property_t(0.01),
"0D",
new property_t("Actual/360"),
new property_t(0.0),
engine,
qlw.OH_NULL(),
qlw.OH_NULL(),
false);
return swap;
}
public static String mkEngine() {
PropertyVector datesList= new PropertyVector();
datesList.add(new property_t("0D"));
datesList.add(new property_t("10Y"));
DoubleVector ratesList=new DoubleVector();
ratesList.add(0.01);
ratesList.add(0.01);
property_t dcc=new property_t("Actual/365 (Fixed)");
String curve=qlw.qlInterpolatedYieldCurve("curve",
datesList,
ratesList,
"TARGET", dcc,
new PropertyVector(),
new PropertyVector(),
new property_t("ZeroYield"),
new property_t("LogLinear"),
qlw.OH_NULL(),
qlw.OH_NULL(),
false);
String vol=qlw.qlConstantSwaptionVolatility("vol",
new property_t(0),
"TARGET",
"Following",
new property_t(0.20),
new property_t("Actual/365 (Fixed)"),
qlw.OH_NULL(),
qlw.OH_NULL(),
false);
String engine=qlw.qlBlackSwaptionEngine("engine",
curve, vol,
qlw.OH_NULL(),
qlw.OH_NULL(),
false);
return engine;
}
}