/** * Method for calculating the returns on a given rate path, via the definition for the * instantaneous compounded return. u_i = \ln{\frac{S_i}{S_{i-1}}} * * @return the return, as defined. * @exception DemoException thrown if there is a problem with the calculation. */ public ReturnPath getReturnCompounded() throws DemoException { if (pathValue == null || nAcceptedPathValue == 0) { throw new DemoException("The Rate Path has not been defined!"); } double[] returnPathValue = new double[nAcceptedPathValue]; returnPathValue[0] = 0.0; try { for (int i = 1; i < nAcceptedPathValue; i++) { returnPathValue[i] = Math.log(pathValue[i] / pathValue[i - 1]); } } catch (ArithmeticException aex) { throw new DemoException("Error in getReturnLogarithm:" + aex.toString()); } ReturnPath rPath = new ReturnPath(returnPathValue, nAcceptedPathValue, ReturnPath.COMPOUNDED); // // Copy the PathId information to the ReturnPath object. rPath.copyInstanceVariables(this); rPath.estimatePath(); return (rPath); }