0

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;
        }
Nielsou Akbrg
  • 201
  • 3
  • 13
  • Maybe it's worth to find some more suitable library for your needs? Take a look on this answer: http://stackoverflow.com/a/16388508/1430055 – Maxim Kolesnikov Sep 10 '16 at 20:09
  • Hi, thanks for the answer. I had a look at the implementation of the add function in Apache Common Math and I was strongly disapointed as it is really not optimized. https://github.com/apache/commons-math/blob/050dfa6f0850174fdf958ce6751d2f06900201f8/src/main/java/org/apache/commons/math4/linear/AbstractRealMatrix.java – Nielsou Akbrg Sep 11 '16 at 13:46

0 Answers0