- java.lang.Object
-
- net.finmath.marketdata.model.curves.AbstractCurve
-
- net.finmath.marketdata.model.curves.CurveInterpolation
-
- All Implemented Interfaces:
Serializable
,Cloneable
,ParameterObject
,Curve
- Direct Known Subclasses:
AbstractForwardCurve
,DiscountCurveInterpolation
public class CurveInterpolation extends AbstractCurve implements Serializable, Cloneable
This class represents a curve build from a set of points in 2D. It provides different interpolation and extrapolation methods applied to a transformation of the input point, examples are- linear interpolation of the input points
- linear interpolation of the log of the input points
- linear interpolation of the log of the input points divided by their respective time
- cubic spline interpolation of the input points (or a function of the input points) (the curve will be C1).
- Akima interpolation of the input points (or a function of the input points).
- etc.
For the interpolation methods provided seeCurveInterpolation.InterpolationMethod
. For the extrapolation methods provided seeCurveInterpolation.ExtrapolationMethod
. For the possible interpolation entities seeCurveInterpolation.InterpolationEntity
. To construct the curve, please use the inner class CurveBuilder (a builder pattern). For a demo on how to construct and/or calibrate a curve see, e.g. net.finmath.tests.marketdata.curves.CurveTest.- Version:
- 1.0
- Author:
- Christian Fries
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CurveInterpolation.Builder
A builder (following the builder pattern) for CurveFromInterpolationPoints objects.static class
CurveInterpolation.ExtrapolationMethod
Possible extrapolation methods.static class
CurveInterpolation.InterpolationEntity
Possible interpolation entities.static class
CurveInterpolation.InterpolationMethod
Possible interpolation methods.static class
CurveInterpolation.Point
Representation of a 2D curve point including the boolean property if the point is fixed or calibrateable.
-
Constructor Summary
Constructors Modifier Constructor Description protected
CurveInterpolation(String name, LocalDate referenceDate, CurveInterpolation.InterpolationMethod interpolationMethod, CurveInterpolation.ExtrapolationMethod extrapolationMethod, CurveInterpolation.InterpolationEntity interpolationEntity)
Create a curve with a given name, reference date and an interpolation method.CurveInterpolation(String name, LocalDate referenceDate, CurveInterpolation.InterpolationMethod interpolationMethod, CurveInterpolation.ExtrapolationMethod extrapolationMethod, CurveInterpolation.InterpolationEntity interpolationEntity, double[] times, double[] values)
Create a curve with a given name, reference date and an interpolation method from given points
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addPoint(double time, double value, boolean isParameter)
Add a point to this curve.CurveInterpolation
clone()
Create a deep copied clone.CurveBuilder
getCloneBuilder()
Returns a curve builder bases on a clone of this curve.Curve
getCloneForParameter(double[] parameter)
Create a clone with a modified parameter.CurveInterpolation.ExtrapolationMethod
getExtrapolationMethod()
Returns the extrapolation method used by this curve.CurveInterpolation.InterpolationEntity
getInterpolationEntity()
Returns the interpolation entity used by this curve.CurveInterpolation.InterpolationMethod
getInterpolationMethod()
Returns the interpolation method used by this curve.double[]
getParameter()
Get the current parameter associated with the state of the objects.protected int
getParameterIndex(double time)
List<CurveInterpolation.Point>
getPoints()
Returns the interpolation points.protected int
getTimeIndex(double time)
double[]
getTimes()
Returns the interpolation times (the x-values).double
getValue(double time)
Returns the value for the time using the interpolation method associated with this curve.double
getValue(AnalyticModel model, double time)
Returns the value for the time using the interpolation method associated with this curve within a given context, i.e., a model.void
setParameter(double[] parameter)
Set the current parameter and change the state of the objects.String
toString()
-
Methods inherited from class net.finmath.marketdata.model.curves.AbstractCurve
getName, getReferenceDate, getValues
-
-
-
-
Constructor Detail
-
CurveInterpolation
public CurveInterpolation(String name, LocalDate referenceDate, CurveInterpolation.InterpolationMethod interpolationMethod, CurveInterpolation.ExtrapolationMethod extrapolationMethod, CurveInterpolation.InterpolationEntity interpolationEntity, double[] times, double[] values)
Create a curve with a given name, reference date and an interpolation method from given points- Parameters:
name
- The name of this curve.referenceDate
- The reference date for this curve, i.e., the date which defined t=0.interpolationMethod
- The interpolation method used for the curve.extrapolationMethod
- The extrapolation method used for the curve.interpolationEntity
- The entity interpolated/extrapolated.times
- A vector of times.values
- A vector of corresponding values.
-
CurveInterpolation
protected CurveInterpolation(String name, LocalDate referenceDate, CurveInterpolation.InterpolationMethod interpolationMethod, CurveInterpolation.ExtrapolationMethod extrapolationMethod, CurveInterpolation.InterpolationEntity interpolationEntity)
Create a curve with a given name, reference date and an interpolation method.- Parameters:
name
- The name of this curve.referenceDate
- The reference date for this curve, i.e., the date which defined t=0.interpolationMethod
- The interpolation method used for the curve.extrapolationMethod
- The extrapolation method used for the curve.interpolationEntity
- The entity interpolated/extrapolated.
-
-
Method Detail
-
getValue
public double getValue(double time)
Description copied from interface:Curve
Returns the value for the time using the interpolation method associated with this curve.- Specified by:
getValue
in interfaceCurve
- Overrides:
getValue
in classAbstractCurve
- Parameters:
time
- Time for which the value should be returned.- Returns:
- The value at the give time.
-
getValue
public double getValue(AnalyticModel model, double time)
Description copied from interface:Curve
Returns the value for the time using the interpolation method associated with this curve within a given context, i.e., a model. The model (context) is needed only if the curve relies on another curve. Examples are a forward curve which relies on a discount curve or a discount curve which is defined via a spread over another curve.
-
addPoint
protected void addPoint(double time, double value, boolean isParameter)
Add a point to this curve. The method will throw an exception if the point is already part of the curve.- Parameters:
time
- The xi in i = f(xi).value
- The yi in i = f(xi).isParameter
- If true, then this point is served viagetParameter()
and changed viagetCloneForParameter(double[])
, i.e., it can be calibrated.
-
getInterpolationMethod
public CurveInterpolation.InterpolationMethod getInterpolationMethod()
Returns the interpolation method used by this curve.- Returns:
- The interpolation method used by this curve.
-
getExtrapolationMethod
public CurveInterpolation.ExtrapolationMethod getExtrapolationMethod()
Returns the extrapolation method used by this curve.- Returns:
- The extrapolation method used by this curve.
-
getInterpolationEntity
public CurveInterpolation.InterpolationEntity getInterpolationEntity()
Returns the interpolation entity used by this curve.- Returns:
- The interpolation entity used by this curve.
-
getPoints
public List<CurveInterpolation.Point> getPoints()
Returns the interpolation points.- Returns:
- An unmodifiable list of points.
-
getTimes
public double[] getTimes()
Returns the interpolation times (the x-values). The method creates a defensive copy.- Returns:
- Array of interpolation times (the x-values).
-
getTimeIndex
protected int getTimeIndex(double time)
-
getParameterIndex
protected int getParameterIndex(double time)
-
getParameter
public double[] getParameter()
Description copied from interface:ParameterObject
Get the current parameter associated with the state of the objects.- Specified by:
getParameter
in interfaceParameterObject
- Returns:
- The parameter.
-
setParameter
public void setParameter(double[] parameter)
Description copied from interface:ParameterObject
Set the current parameter and change the state of the objects.- Specified by:
setParameter
in interfaceParameterObject
- Parameters:
parameter
- The parameter associated with the new state of the objects.
-
clone
public CurveInterpolation clone() throws CloneNotSupportedException
Description copied from interface:Curve
Create a deep copied clone.- Specified by:
clone
in interfaceCurve
- Overrides:
clone
in classAbstractCurve
- Returns:
- A clone (deep copied).
- Throws:
CloneNotSupportedException
- Thrown, when the curve could not be cloned.
-
getCloneForParameter
public Curve getCloneForParameter(double[] parameter) throws CloneNotSupportedException
Description copied from interface:ParameterObject
Create a clone with a modified parameter.- Specified by:
getCloneForParameter
in interfaceCurve
- Specified by:
getCloneForParameter
in interfaceParameterObject
- Overrides:
getCloneForParameter
in classAbstractCurve
- Parameters:
parameter
- The new parameter.- Returns:
- A clone with an otherwise modified parameter.
- Throws:
CloneNotSupportedException
- Thrown, when the curve could not be cloned.
-
getCloneBuilder
public CurveBuilder getCloneBuilder() throws CloneNotSupportedException
Description copied from interface:Curve
Returns a curve builder bases on a clone of this curve. Using that curve builder you may create a new curve from this curve by adding points or changing properties. Note: The clone has the same name than this one.- Specified by:
getCloneBuilder
in interfaceCurve
- Returns:
- An object implementing the CurveBuilderInterface where the underlying curve is a clone of this curve.
- Throws:
CloneNotSupportedException
- Thrown, when this curve could not be cloned.
-
toString
public String toString()
- Overrides:
toString
in classAbstractCurve
-
-