Market data interpolation APIs

The market data API provides an interpolation API separated from the market data retrieval. The API is mostly contained in the market-data-api module, with Spring configuration classes available in the market-data-api-spring-boot-starter module.

Supported interpolation types

This API supports linear, cubic and spline interpolation, with the InterpolationMode class in the com.activeviam.mr.common.services.marketdata.interpolation.intf package providing valid options.

Value Details
InterpolationMode.LINEAR Linear interpolation is required for missing data points.
InterpolationMode.CUBIC Cubic interpolation is required for missing data points.
InterpolationMode.SPLINE Spline interpolation is required for missing data points.

Handling market data

The interpolation API expects the known data points to be expressed as an array of doubles with corresponding double arrays of coordinates (tenors/moneyness/maturities). The retrieval interfaces packaged with the market data API allow you retrieve curves, surfaces, or cubes as values and associated coordinates. Market data values are always expressed as doubles whereas coordinates will likely be expressed as other data types, based on the structure of the underlying market data store. The ICubeMarketData, ICurveMarketData, and ISurfaceMarketData interfaces allow you to extract coordinates as doubles by providing a mapping function.

Interpolator Interfaces

Interpolators are objects that will provide an interpolated point when provided with correctly configured known data points and the required coordinates. All interpolators must implement the IInterpolator interface:

Method Return type Details
value(double... coordinates) double Returns the interpolated value given the coordinates. A helper default validateCoordinates(double... coordinates) method is provided on the IInterpolatorSettings interface (see below) to check the validity of the requested coordinates against the supported axes.

Each interpolator is constructed with a factory that formats the input data correctly for that specific interpolator. These factories implement the IInterpolatorFactory interface:

Method Return type Details
from(double[] values, double[]... coordinates) IInterpolator Sets up the interpolator with known data points. The implementation has to check that the number of coordinate arrays matches the result of getAxis().

Both IInterpolator and IInterpolatorFactory interfaces extend the IInterpolatorSettings interface which contains methods that describe the type of interpolation handled by that interpolator.

Method Return type Details
getMode() InterpolationMode The type of interpolation performed by the interpolator object.
getAxis() int The number of axes of the known data points.

A number of convenience interfaces have also been provided which extend the IInterpolationSettings interface and provide common settings as default methods.

Interface Details
IUnivariate Returns 1 on getAxis().
IBivariate Returns 2 on getAxis().
ITrivariate Returns 3 on getAxis().
ILinear Returns InterpolationMode.LINEAR on getMode().
ICubic Returns InterpolationMode.CUBIC on getMode().
ISpline Returns InterpolationMode.SPLINE on getMode().
ILinearUnivariateInterpolatorFactory Extends IInterpolatorFactory, ILinear, and IUnivariate.
IBilinearInterpolatorFactory Extends IInterpolatorFactory, ILinear, and IBivariate.
ITrilinearInterpolatorFactory Extends IInterpolatorFactory, ILinear, and ITrivariate.
IBicubicInterpolatorFactory Extends IInterpolatorFactory, ICubic, and IBivariate.
ITricubicInterpolatorFactory Extends IInterpolatorFactory, ICubic, and ITrivariate.
ISplineUnivariateInterpolatorFactory Extends IInterpolatorFactory, ISpline, and IUnivariate.
ISplineBicubicInterpolatorFactory Extends IInterpolatorFactory, ISpline, and IBivariate.

Interpolator Implementations

The majority of interpolators provided in Atoti Market Risk use the Apache Commons Math library. As the Apache library expects unflattened matrices, conversion and sorting is handled through data classes in the com.activeviam.marketdata.api.interpolation.interpolators.commonsmath.data package:

Class Input Details
CurveInterpolationData Tenors and values Sorts the tenors as double[] and stores the associated values as double[].
SurfaceInterpolationData Tenors, moneyness, and values Sorts the tenors and moneyness as double[], and stores the associated values as double[][].
CubeInterpolationData Tenors, moneyness, maturities, and values Sorts the tenors, moneyness and maturities as double[], and stores the associated values as double[][][].

Several interpolators are provided in the com.activeviam.marketdata.api.interpolation.interpolators.commonsmath.impl package. We do not provide a three-axis interpolator for SPLINE interpolation, as the Commons Math implementation is deprecated and considered invalid.

Interpolator Interpolation type Axes Interface Details
BicubicInterpolator CUBIC 2 IInterpolator, ICubic, IBivariate Extends the Commons Math BicubicIntepolator.
TricubicInterpolator CUBIC 3 IInterpolator, ICubic, ITrivariate Extends the Commons Math TricubicInterpolator.
SplineUnivariateInterpolator SPLINE 1 IInterpolator, ISpline, IUnivariate Extends the Commons Math SplineInterpolator.
SplineBicubicInterpolator SPLINE 2 IInterpolator, ISpline, IBivariate Extends the Commons Math PiecewiseBicubicSplineInterpolator.

A further, custom interpolator (LinearInterpolator) is provided to carry out linear interpolation on any number axes. This interpolator can be found in the com.activeviam.marketdata.api.interpolation.interpolators.impl package.

Interpolator Interpolation type Axes Interface Details
LinearInterpolator LINEAR any IInterpolator, Ilinear Custom implementation of a linear interpolator.

Interpolator factories

The following interpolator factory classes are available. Implementations of IInterpolatorFactory are available in the same package and these construct interpolators that work along one, two, or three axes, as follows:

InterpolatorFactory Interpolation type Axes Interface Details
LinearUnivariateInterpolatorFactory LINEAR 1 ILinearUnivariateInterpolatorFactory (IInterpolatorFactory, Ilinear, IUnivariate) Constructs linear interpolators that operate on a single axis.
BilinearInterpolatorFactory LINEAR 2 IBilinearInterpolatorFactory (IInterpolatorFactory, Ilinear, IBivariate) Constructs linear interpolators that operate on two axes.
TrlinearInterpolatorFactory LINEAR 3 ITrilinearInterpolatorFactory (IInterpolatorFactory, Ilinear, ITrivariate) Constructs linear interpolators that operate on three axes.
BicubicInterpolatorFactory CUBIC 1 IBicubicInterpolatorFactory (IInterpolatorFactory, ICubic, IUnivariate) Constructs cubic interpolators that operate on a single axis.
TricubicInterpolatorFactory CUBIC 2 ITricubicInterpolatorFactory (IInterpolatorFactory, ICubic, IBivariate) Constructs cubic interpolators that operate on two axes.
SplineBicubicInterpolatorFactory SPLINE 2 ISplineBicubicInterpolatorFactory (IInterpolatorFactory, ISpline, IBivariate) Constructs spline interpolators that operate on two axes.
SplineTricubicInterpolatorFactory SPLINE 3 ISplineTricubicInterpolatorFactory (IInterpolatorFactory, ISpline, ITrivariate) Constructs spline interpolators that operate on three axes.

Interpolation service

Two interpolation services are available:

  • The IInterpolationService interface, with corresponding InterpolationService implementation, collects the interpolator factories and allows the retrieval of an interpolator for the given mode, values, and number of coordinate axes. The retrieved interpolator is constructed with the correct known data points.
  • The ICachingInterpolationService interface, with corresponding CachingInterpolationService implementation, is constructed with an underlying IInterpolationService which it uses to retrieve interpolators, caching those interpolators within an IQueryCache for faster retrieval.

The interfaces can be found in the com.activeviam.marketdata.api.interpolation.services.intf package with the implementations in the com.activeviam.marketdata.api.interpolation.services.impl package.

Class Details
IInterpolationService Provides a single getInterpolator(InterpolationMode mode, double[] values, double[]... coordinates) method returning an IInterpolator.
InterpolationService Implementation of IInterpolationService that stores a set of interpolators and returns the correct interpolator for the given mode, values, and number of coordinate axes.
ICachingInterpolationService Provides a single getInterpolator(IQueryCache cache, InterpolationMode mode, double[] values, double[]... coordinates) method returning an IInterpolator.
CachingInterpolationService Implementation of ICachingInterpolationService caches interpolator instances for fast retrieval.

Spring configuration classes

Several Spring configuration classes are provided in the com.activeviam.marketdata.api.configuration.interpolation package of the market-data-api-spring-boot-starter module, providing interpolation services and interpolator factory Spring beans. When you add the starter as a dependency in your project, the AllInterpolatorsConfig class will be auto-configured.

Class Details
AllInterpolatorsConfig Imports all other *InterpolatorConfig classes.
InterpolationServiceConfig Collects all IInterpolatorFactory beans and publishes an IInterpolationService bean that can be overridden by creating a custom bean of the same type. A further ICachingInterpolationService bean is also provided.
LinearUnivariateInterpolatorConfig Publishes a LinearUnivariateInterpolatorFactory as an ILinearUnivariateInterpolatorFactory bean that can be overridden by creating a custom bean of the same type.
BilinearInterpolatorConfig Publishes a BilinearInterpolatorFactory as an IBilinearInterpolatorFactory bean that can be overridden by creating a custom bean of the same type.
TrilinearInterpolatorConfig Publishes a TrilinearInterpolatorFactory as an ITrilinearInterpolatorFactory bean that can be overridden by creating a custom bean of the same type.
BicubicInterpolatorConfig Publishes a BicubicInterpolatorFactory as an IBicubicInterpolatorFactoryFactory bean that can be overridden by creating a custom bean of the same type.
TricubicInterpolatorConfig Publishes a LinearTricubicInterpolatorFactory as an ITricubicInterpolatorFactory bean that can be overridden by creating a custom bean of the same type.
SplineUnivariateInterpolatorConfig Publishes a SplineUnivariateInterpolatorFactory as an ISplineUnivariateInterpolatorFactory bean that can be overridden by creating a custom bean of the same type.
SplineBicubicInterpolatorConfig Publishes a SplineBicubicInterpolatorFactory as an ISplineBicubicInterpolatorFactory bean that can be overridden by creating a custom bean of the same type.