19#include <ql/math/interpolations/linearinterpolation.hpp>
25static void fillMatrixImpl(Matrix& mat, Real blank) {
29 for (
unsigned int i = 0; i < mat.columns(); i++) {
34 for (Size i = 0; i < mat.rows(); i++) {
37 vector<Real> yDesired(xAxis.size());
40 if (mat[i][0] == blank) {
41 Size pos1 = mat.columns();
42 for (Size j = 1; j < mat.columns(); j++) {
43 if (mat[i][j] != blank) {
48 QL_REQUIRE(pos1 < mat.columns(),
"Matrix has empty line.");
49 for (Size j = 0; j < pos1; j++) {
50 mat[i][j] = mat[i][pos1];
55 if (mat[i][mat.columns() - 1] == blank) {
57 for (Size j = mat.columns() - 2; j >= 0; j--) {
58 if (mat[i][j] != blank) {
63 for (Size j = pos1 + 1; j < mat.columns(); j++) {
64 mat[i][j] = mat[i][pos1];
69 for (
unsigned int j = 0; j < mat.columns(); j++) {
70 if (mat[i][j] != blank) {
72 y.push_back(mat[i][j]);
77 Interpolation f = LinearInterpolation(x.begin(), x.end(), y.begin());
78 std::transform(xAxis.begin(), xAxis.end(), yDesired.begin(), f);
81 for (Size j = 0; j < mat.columns(); j++) {
82 mat[i][j] = yDesired[j];
88 QL_REQUIRE(mat.columns() > 0 && mat.rows() > 0,
"Matrix has no elements.");
92 for (Size i = 0; i < mat.rows(); i++) {
93 for (Size j = 0; j < mat.columns(); j++) {
94 if (mat[i][j] == blank) {
107 if (mat.columns() == 1 && mat.rows() == 1) {
108 QL_FAIL(
"1 X 1 empty matrix given to fill.");
111 QL_REQUIRE(mat.columns() > 1,
"Too few columns in matrix to interpolate within rows.");
112 fillMatrixImpl(mat, blank);
114 QL_REQUIRE(mat.rows() > 1,
"Too few rows in matrix to interpolate within columns.");
115 Matrix m2 = transpose(mat);
116 fillMatrixImpl(m2, blank);
117 Matrix m3 = transpose(m2);
functions to compute delta or delta-gamma VaR numbers
void fillIncompleteMatrix(Matrix &mat, bool interpRows=true, Real blank=QL_NULL_REAL)
function that fills a matrix