CellMatrix::CellMatrix(const MyMatrix& data): Cells(data.rows()), Rows(data.rows()), Columns(data.columns()) { for (unsigned long i=0; i < data.rows(); ++i) for (unsigned long j=0; j < data.columns(); ++j) Cells[i].push_back(CellValue(Element(data,i,j))); }
double BSDeltaWithParamsFD(const MyMatrix& parametersMatrix, double epsilon) { if (parametersMatrix.columns() != 6 && parametersMatrix.rows() != 1 ) { throw("Input matrix should be 1 x 5");} double Spot = parametersMatrix(0,0); double Strike = parametersMatrix(0,1); double r = parametersMatrix(0,2); double d = parametersMatrix(0,3); double vol = parametersMatrix(0,4); double expiry = parametersMatrix(0,5); return BlackScholesDeltaFD(Spot, Strike,r,d,vol,expiry, epsilon); }
double BSZeroCouponBondWithParams(const MyMatrix& parametersMatrix){ if (parametersMatrix.columns() != 6 && parametersMatrix.rows() != 1 ) { throw("Input matrix should be 1 x 5");} double Spot = parametersMatrix(0,0); double Strike = parametersMatrix(0,1); double r = parametersMatrix(0,2); double d = parametersMatrix(0,3); double vol = parametersMatrix(0,4); double expiry = parametersMatrix(0,5); return BlackScholesZeroCouponBond(Spot, Strike,r,d,vol,expiry); }
CellMatrix::CellMatrix(const MyMatrix& data):pimpl(new defaultCellMatrixImpl(data.rows(),data.columns())) { for(size_t i(0); i < data.rows(); ++i) { for(size_t j(0); j < data.columns(); ++j) { (*pimpl)(i,j) = data(i,j); } } }
CellMatrix // BSGreeksFD(const MyMatrix& parametersMatrix,double epsilon) { if (parametersMatrix.columns() != 6 && parametersMatrix.rows() != 1 ) { throw("Input matrix should be 1 x 5");} double Spot = parametersMatrix(0,0); double Strike = parametersMatrix(0,1); double r = parametersMatrix(0,2); double d = parametersMatrix(0,3); double vol = parametersMatrix(0,4); double expiry = parametersMatrix(0,5); CellMatrix resultMatrix(1,5); resultMatrix(0,0) = BlackScholesDeltaFD(Spot,Strike,r,d,vol,expiry,epsilon); resultMatrix(0,1) = BlackScholesGammaFD(Spot,Strike,r,d,vol,expiry,epsilon); resultMatrix(0,2) = BlackScholesVegaFD(Spot,Strike,r,d,vol,expiry,epsilon); resultMatrix(0,3) = BlackScholesRhoFD(Spot,Strike,r,d,vol,expiry,epsilon); resultMatrix(0,4) = BlackScholesThetaFD(Spot,Strike,r,d,vol,expiry,epsilon); return resultMatrix; }
CellMatrix // returns delta, gamma, vega, rho, theta BSGreeks(const MyMatrix& parametersMatrix) { if (parametersMatrix.columns() != 6 && parametersMatrix.rows() != 1 ) { throw("Input matrix should be 1 x 5");} double Spot = parametersMatrix(0,0); double Strike = parametersMatrix(0,1); double r = parametersMatrix(0,2); double d = parametersMatrix(0,3); double vol = parametersMatrix(0,4); double expiry = parametersMatrix(0,5); CellMatrix resultMatrix(1,5); resultMatrix(0,0) = BlackScholesDelta(Spot,Strike,r,d,vol,expiry); resultMatrix(0,1) = BlackScholesGamma(Spot,Strike,r,d,vol,expiry); resultMatrix(0,2) = BlackScholesVega(Spot,Strike,r,d,vol,expiry); resultMatrix(0,3) = BlackScholesRho(Spot,Strike,r,d,vol,expiry); resultMatrix(0,4) = BlackScholesTheta(Spot,Strike,r,d,vol,expiry); return resultMatrix; }
bool MyMatrix::operator==(const MyMatrix& a) const { if (this->rows() != a.rows()) return false; if (this->columns() != a.columns()) return false; return(((EigenMatrix)(*this)-(EigenMatrix)a).isApproxToConstant(0.0)); }