void VolatiltiySurfaceRateSource::setInputs(Date anchorDateInput, vector<Date> observationDatesInput, vector<double> strikeDimensionInput, QuantLib::Matrix volatilityInput, SurfaceInterpolatorType interpolatorTypeInput, bool extrapolateInput) { if (observationDatesInput.size() == 0 || strikeDimensionInput.size() == 0 || volatilityInput.rows() * volatilityInput.columns() == 0) { observationDates = vector<Date>(); strikeDimension = vector<double>(); volatility = Matrix(0,0); return; } anchorDate = anchorDateInput; dayCounter = boost::shared_ptr<DayCounter>(new Actual365Fixed()); allowExtrapolation = extrapolateInput; strikeDimension = strikeDimensionInput; observationDates = observationDatesInput; if (observationDates[0] > anchorDate) { observationDates.insert(observationDates.begin(), anchorDate); volatility = QuantLib::Matrix(volatilityInput.rows(), volatilityInput.columns()+1); for (size_t i = 0; i < volatilityInput.rows(); ++i) { volatility[i][0] = volatilityInput[i][0]; for (size_t j = 0; j < volatilityInput.columns(); ++j) { volatility[i][j+1] = volatilityInput[i][j]; } } } else { volatility = volatilityInput; } time.clear(); for (size_t i = 0; i < observationDates.size(); ++i) { double yf = dayCounter->yearFraction(anchorDate, observationDates[i]); time.push_back(yf); } if (observationDates.size() > 0) { finalDate = observationDates.back(); } else { finalDate = Date(01,Jan,1901); } setInterpolatorType(interpolatorTypeInput); }
void matrixToOper(const QuantLib::Matrix &m, OPER &xMatrix) { if (m.empty()) { xMatrix.xltype = xltypeErr; xMatrix.val.err = xlerrNA; return; } xMatrix.val.array.rows = m.rows(); xMatrix.val.array.columns = m.columns(); xMatrix.val.array.lparray = new OPER[xMatrix.val.array.rows * xMatrix.val.array.columns]; xMatrix.xltype = xltypeMulti | xlbitDLLFree; for (unsigned int i=0; i<m.rows(); ++i) for (unsigned int j=0; j<m.columns(); ++j) scalarToOper(m[i][j], xMatrix.val.array.lparray[i * m.columns() + j]); }
std::vector<std::vector<double> > qlMatrixToVv(const QuantLib::Matrix &m) { std::vector<std::vector<double> > vv; for(unsigned int r=0; r<m.rows(); ++r) { std::vector<double> v; for(unsigned int c=0; c<m.columns(); ++c) { v.push_back(m[r][c]); } vv.push_back(v); } return vv; }
boost::shared_ptr<VolatilityRateSource> VolatilitySurfaceMoneyness::parallelBump(double spread) { vector<Date> newDates; QuantLib::Matrix volatilitySubset; getRolledVariables(anchorDate, newDates, volatilitySubset); Matrix spreadMatrix = Matrix(volatilitySubset.rows(), volatilitySubset.columns(), spread); Matrix bumpedVolMatrix = volatilitySubset + spreadMatrix; return boost::shared_ptr<VolatilityRateSource>(new VolatilitySurfaceMoneyness(anchorDate, newDates, strikeDimension, bumpedVolMatrix, interpolatorType, allowExtrapolation)); }