Using Java Apache Common Maths, I would like to apply an exponential function to each element of the RealMatrix without having to go through each elements line by line and use a for loops.
In other words, is there an exponential function in ACM taking in entry a RealMatrix and whose output is exp(RealMatrix), written in an optimized way ?
Finally, if I want to create more complex functions than exponential, is there some guidelines ?
Please find below my current highly under-optimized code :
RealMatrix payoffVector = MatrixUtils.createRealMatrix(numberOfSimulation, 1);
for (int i = 0; i <= numberOfSimulation - 1; i++) {
double randNumber = randGenerator.nextVector()[0];
double pathPayoff = mForwardPrice;
pathPayoff *= Math.exp(-0.5 * mVolatility * mVolatility * mTimeToMaturity
+ mVolatility * Math.sqrt(mTimeToMaturity) * distrib.inverseCumulativeProbability(randNumber));
pathPayoff = Math.max(pathPayoff - mStrike, 0);
payoffVector.setEntry(i, 0, pathPayoff);
totalOfTheVector += pathPayoff;
}