public RandomVariable getValues ( double evaluationTime , LIBORMarketModel model ) { if ( evaluationTime > 0 ) { throw new RuntimeException ( "Forward start evaluation currently not supported." ) ; } // Fetch the covariance model of the model LIBORCovarianceModel covarianceModel = model . getCovarianceModel ( ) ; // We sum over all forward rates int numberOfComponents = covarianceModel . getLiborPeriodDiscretization ( ) . getNumberOfTimeSteps ( ) ; // Accumulator RandomVariable integratedLIBORCurvature = new RandomVariableFromDoubleArray ( 0.0 ) ; for ( int componentIndex = 0 ; componentIndex < numberOfComponents ; componentIndex ++ ) { // Integrate from 0 up to the fixing of the rate double timeEnd = covarianceModel . getLiborPeriodDiscretization ( ) . getTime ( componentIndex ) ; int timeEndIndex = covarianceModel . getTimeDiscretization ( ) . getTimeIndex ( timeEnd ) ; // If timeEnd is not in the time discretization we get timeEndIndex = -insertionPoint-1. In that case, we use the index prior to the insertionPoint if ( timeEndIndex < 0 ) { timeEndIndex = - timeEndIndex - 2 ; } // Sum squared second derivative of the variance for all components at this time step RandomVariable integratedLIBORCurvatureCurrentRate = new RandomVariableFromDoubleArray ( 0.0 ) ; for ( int timeIndex = 0 ; timeIndex < timeEndIndex - 2 ; timeIndex ++ ) { double timeStep1 = covarianceModel . getTimeDiscretization ( ) . getTimeStep ( timeIndex ) ; double timeStep2 = covarianceModel . getTimeDiscretization ( ) . getTimeStep ( timeIndex + 1 ) ; RandomVariable covarianceLeft = covarianceModel . getCovariance ( timeIndex + 0 , componentIndex , componentIndex , null ) ; RandomVariable covarianceCenter = covarianceModel . getCovariance ( timeIndex + 1 , componentIndex , componentIndex , null ) ; RandomVariable covarianceRight = covarianceModel . getCovariance ( timeIndex + 2 , componentIndex , componentIndex , null ) ; // Calculate second derivative RandomVariable curvatureSquared = covarianceRight . sub ( covarianceCenter . mult ( 2.0 ) ) . add ( covarianceLeft ) ; curvatureSquared = curvatureSquared . div ( timeStep1 * timeStep2 ) ; // Take square curvatureSquared = curvatureSquared . squared ( ) ; // Integrate over time integratedLIBORCurvatureCurrentRate = integratedLIBORCurvatureCurrentRate . add ( curvatureSquared . mult ( timeStep1 ) ) ; } // Empty intervall - skip if ( timeEnd == 0 ) { continue ; } // Average over time integratedLIBORCurvatureCurrentRate = integratedLIBORCurvatureCurrentRate . div ( timeEnd ) ; // Take square root integratedLIBORCurvatureCurrentRate = integratedLIBORCurvatureCurrentRate . sqrt ( ) ; // Take max over all forward rates integratedLIBORCurvature = integratedLIBORCurvature . add ( integratedLIBORCurvatureCurrentRate ) ; } integratedLIBORCurvature = integratedLIBORCurvature . div ( numberOfComponents ) ; return integratedLIBORCurvature . sub ( tolerance ) . floor ( 0.0 ) ; }
Calculates the squared curvature of the LIBOR instantaneous variance .