public virtual void differentIntervalsTest() { DoubleArray xValues = DoubleArray.of(1.0328724558967068, 1.2692381049172323, 2.8611430465380905, 4.296118458251132, 7.011992052151352, 7.293354144919639, 8.557971037612713, 8.77306861567384, 10.572470371584489, 12.96945799507056); DoubleArray[] yValues = new DoubleArray[] { DoubleArray.of(1.1593075755231343, 2.794957672828094, 4.674733634811079, 5.517689918508841, 6.138447304104604, 6.264375977142906, 6.581666492568779, 8.378685055774037, 10.005246918325483, 10.468304334744241), DoubleArray.of(9.95780079114617, 8.733013195721913, 8.192165283188197, 6.539369493529048, 6.3868683960757515, 4.700471352238411, 4.555354921077598, 3.780781869340659, 2.299369456202763, 0.9182441378327986) }; int nKeys = 100; double[] keys = new double[nKeys]; double interval = 0.061; for (int i = 0; i < nKeys; ++i) { keys[i] = xValues.get(0) + interval * i; } CurveExtrapolator extrap = InterpolatorCurveExtrapolator.INSTANCE; int yDim = yValues.Length; for (int k = 0; k < yDim; ++k) { BoundCurveInterpolator boundInterp = CurveInterpolators.SQUARE_LINEAR.bind(xValues, yValues[k], extrap, extrap); AbstractBoundCurveInterpolator baseInterp = (AbstractBoundCurveInterpolator)boundInterp; for (int j = 0; j < nKeys; ++j) { // value assertEquals(boundInterp.interpolate(keys[j]), baseInterp.doInterpolate(keys[j]), TOL); // derivative assertEquals(boundInterp.firstDerivative(keys[j]), baseInterp.doFirstDerivative(keys[j]), TOL); // sensitivity assertTrue(boundInterp.parameterSensitivity(keys[j]).equalWithTolerance(baseInterp.doParameterSensitivity(keys[j]), TOL)); } } }
public override Builder set(string propertyName, object newValue) { switch (propertyName.GetHashCode()) { case -450004177: // metadata this.metadata_Renamed = (CurveMetadata)newValue; break; case 1681280954: // xValues this.xValues_Renamed = (DoubleArray)newValue; break; case -1726182661: // yValues this.yValues_Renamed = (DoubleArray)newValue; break; case 2096253127: // interpolator this.interpolator_Renamed = (CurveInterpolator)newValue; break; case 1271703994: // extrapolatorLeft this.extrapolatorLeft_Renamed = (CurveExtrapolator)newValue; break; case 773779145: // extrapolatorRight this.extrapolatorRight_Renamed = (CurveExtrapolator)newValue; break; default: throw new NoSuchElementException("Unknown property: " + propertyName); } return(this); }
public virtual void sameIntervalsTest() { DoubleArray xValues = DoubleArray.of(-1.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0); DoubleArray[] yValues = new DoubleArray[] { DoubleArray.of(1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001), DoubleArray.of(11.0, 11.0, 8.0, 5.0, 1.001, 1.001, 5.0, 8.0, 11.0, 11.0), DoubleArray.of(1.001, 1.001, 5.0, 8.0, 9.0, 9.0, 11.0, 12.0, 18.0, 18.0) }; int nKeys = 100; double[] keys = new double[nKeys]; double interval = 0.061; for (int i = 0; i < nKeys; ++i) { keys[i] = xValues.get(0) + interval * i; } CurveExtrapolator extrap = InterpolatorCurveExtrapolator.INSTANCE; int yDim = yValues.Length; for (int k = 0; k < yDim; ++k) { BoundCurveInterpolator boundInterp = CurveInterpolators.SQUARE_LINEAR.bind(xValues, yValues[k], extrap, extrap); AbstractBoundCurveInterpolator baseInterp = (AbstractBoundCurveInterpolator)boundInterp; for (int j = 0; j < nKeys; ++j) { // value assertEquals(boundInterp.interpolate(keys[j]), baseInterp.doInterpolate(keys[j]), TOL); // derivative assertEquals(boundInterp.firstDerivative(keys[j]), baseInterp.doFirstDerivative(keys[j]), TOL); // sensitivity assertTrue(boundInterp.parameterSensitivity(keys[j]).equalWithTolerance(baseInterp.doParameterSensitivity(keys[j]), TOL)); } } }
private static IDictionary <CurveName, LoadedCurveSettings> parseCurveSettings(CharSource settingsResource) { ImmutableMap.Builder <CurveName, LoadedCurveSettings> builder = ImmutableMap.builder(); CsvFile csv = CsvFile.of(settingsResource, true); foreach (CsvRow row in csv.rows()) { string curveNameStr = row.getField(SETTINGS_CURVE_NAME); string valueTypeStr = row.getField(SETTINGS_VALUE_TYPE); string dayCountStr = row.getField(SETTINGS_DAY_COUNT); string interpolatorStr = row.getField(SETTINGS_INTERPOLATOR); string leftExtrapolatorStr = row.getField(SETTINGS_LEFT_EXTRAPOLATOR); string rightExtrapolatorStr = row.getField(SETTINGS_RIGHT_EXTRAPOLATOR); if (!VALUE_TYPE_MAP.containsKey(valueTypeStr.ToLower(Locale.ENGLISH))) { throw new System.ArgumentException(Messages.format("Unsupported {} in curve settings: {}", SETTINGS_VALUE_TYPE, valueTypeStr)); } CurveName curveName = CurveName.of(curveNameStr); ValueType valueType = VALUE_TYPE_MAP.get(valueTypeStr.ToLower(Locale.ENGLISH)); CurveInterpolator interpolator = CurveInterpolator.of(interpolatorStr); CurveExtrapolator leftExtrap = CurveExtrapolator.of(leftExtrapolatorStr); CurveExtrapolator rightExtrap = CurveExtrapolator.of(rightExtrapolatorStr); // ONE_ONE day count is not used DayCount dayCount = LoaderUtils.parseDayCount(dayCountStr); LoadedCurveSettings settings = LoadedCurveSettings.of(curveName, ValueType.YEAR_FRACTION, valueType, dayCount, interpolator, leftExtrap, rightExtrap); builder.put(curveName, settings); } return(builder.build()); }
public override Builder set(string propertyName, object newValue) { switch (propertyName.GetHashCode()) { case 1411950943: // xInterpolator this.xInterpolator = (CurveInterpolator)newValue; break; case -382665134: // xExtrapolatorLeft this.xExtrapolatorLeft = (CurveExtrapolator)newValue; break; case 1027943729: // xExtrapolatorRight this.xExtrapolatorRight = (CurveExtrapolator)newValue; break; case 1118547936: // yInterpolator this.yInterpolator = (CurveInterpolator)newValue; break; case 970644563: // yExtrapolatorLeft this.yExtrapolatorLeft = (CurveExtrapolator)newValue; break; case 30871376: // yExtrapolatorRight this.yExtrapolatorRight = (CurveExtrapolator)newValue; break; default: throw new NoSuchElementException("Unknown property: " + propertyName); } return(this); }
private GridSurfaceInterpolator(CurveInterpolator xInterpolator, CurveExtrapolator xExtrapolatorLeft, CurveExtrapolator xExtrapolatorRight, CurveInterpolator yInterpolator, CurveExtrapolator yExtrapolatorLeft, CurveExtrapolator yExtrapolatorRight) { this.xInterpolator = xInterpolator; this.xExtrapolatorLeft = xExtrapolatorLeft; this.xExtrapolatorRight = xExtrapolatorRight; this.yInterpolator = yInterpolator; this.yExtrapolatorLeft = yExtrapolatorLeft; this.yExtrapolatorRight = yExtrapolatorRight; }
internal Bound(CurveInterpolator xInterpolator, CurveExtrapolator xExtrapolatorLeft, CurveExtrapolator xExtrapolatorRight, int paramSize, DoubleArray xValuesUnique, BoundCurveInterpolator[] yInterpolators) { this.xInterpolator = xInterpolator; this.xExtrapolatorLeft = xExtrapolatorLeft; this.xExtrapolatorRight = xExtrapolatorRight; this.xValuesUnique = xValuesUnique; this.paramSize = paramSize; this.yInterpolators = yInterpolators; }
/// <summary> /// Restricted copy constructor. </summary> /// <param name="beanToCopy"> the bean to copy from, not null </param> internal Builder(InterpolatedNodalCurve beanToCopy) { this.metadata_Renamed = beanToCopy.Metadata; this.xValues_Renamed = beanToCopy.XValues; this.yValues_Renamed = beanToCopy.YValues; this.interpolator_Renamed = beanToCopy.Interpolator; this.extrapolatorLeft_Renamed = beanToCopy.ExtrapolatorLeft; this.extrapolatorRight_Renamed = beanToCopy.ExtrapolatorRight; }
public virtual void differentIntervalsTest() { DoubleArray xValues = DoubleArray.of(1.0328724558967068, 1.2692381049172323, 2.8611430465380905, 4.296118458251132, 7.011992052151352, 7.293354144919639, 8.557971037612713, 8.77306861567384, 10.572470371584489, 12.96945799507056); DoubleArray[] yValues = new DoubleArray[] { DoubleArray.of(1.1593075755231343, 2.794957672828094, 4.674733634811079, 5.517689918508841, 6.138447304104604, 6.264375977142906, 6.581666492568779, 8.378685055774037, 10.005246918325483, 10.468304334744241), DoubleArray.of(9.95780079114617, 8.733013195721913, 8.192165283188197, 6.539369493529048, 6.3868683960757515, 4.700471352238411, 4.555354921077598, 3.780781869340659, 2.299369456202763, 0.9182441378327986) }; int nData = xValues.size(); int nKeys = 100 * nData; double[] xKeys = new double[nKeys]; double xMin = 0.0; double xMax = xValues.get(nData - 1) + 2.0; double step = (xMax - xMin) / nKeys; for (int i = 0; i < nKeys; ++i) { xKeys[i] = xMin + step * i; } CurveExtrapolator extrap = QuadraticLeftCurveExtrapolator.INSTANCE; int yDim = yValues.Length; for (int k = 0; k < yDim; ++k) { BoundCurveInterpolator bci = CurveInterpolators.LOG_NATURAL_SPLINE_MONOTONE_CUBIC.bind(xValues, yValues[k], extrap, CurveExtrapolators.LOG_LINEAR); // Check C0 continuity assertEquals(bci.interpolate(xValues.get(0) - 1.e-14), bci.interpolate(xValues.get(0)), TOL); // Check C1 continuity assertEquals(bci.firstDerivative(xValues.get(0) - TOL), bci.firstDerivative(xValues.get(0)), TOL * 1.e2); // Test sensitivity double[] yValues1Up = yValues[k].toArray(); double[] yValues1Dw = yValues[k].toArray(); for (int j = 0; j < nData; ++j) { yValues1Up[j] = yValues[k].get(j) * (1.0 + EPS); yValues1Dw[j] = yValues[k].get(j) * (1.0 - EPS); BoundCurveInterpolator bciUp = CurveInterpolators.LOG_NATURAL_SPLINE_MONOTONE_CUBIC.bind(xValues, DoubleArray.ofUnsafe(yValues1Up), extrap, CurveExtrapolators.LOG_LINEAR); BoundCurveInterpolator bciDw = CurveInterpolators.LOG_NATURAL_SPLINE_MONOTONE_CUBIC.bind(xValues, DoubleArray.ofUnsafe(yValues1Dw), extrap, CurveExtrapolators.LOG_LINEAR); for (int i = 0; i < nKeys; ++i) { double res1 = 0.5 * (bciUp.interpolate(xKeys[i]) - bciDw.interpolate(xKeys[i])) / EPS / yValues[k].get(j); assertEquals(res1, bci.parameterSensitivity(xKeys[i]).get(j), Math.Max(Math.Abs(yValues[k].get(j)) * EPS, EPS) * 1.e2); //because gradient is NOT exact } yValues1Up[j] = yValues[k].get(j); yValues1Dw[j] = yValues[k].get(j); } } }
public virtual void sameIntervalsTest() { DoubleArray xValues = DoubleArray.of(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0); DoubleArray[] yValues = new DoubleArray[] { DoubleArray.of(1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001, 1.001), DoubleArray.of(11.0, 8.0, 5.0, 1.001, 1.001, 5.0, 8.0, 11.0), DoubleArray.of(1.001, 1.001, 5.0, 9.0, 9.0, 12.0, 18.0, 18.0) }; int nData = xValues.size(); int nKeys = 100 * nData; double[] xKeys = new double[nKeys]; double xMin = 0.0; double xMax = xValues.get(nData - 1) + 2.0; double step = (xMax - xMin) / nKeys; for (int i = 0; i < nKeys; ++i) { xKeys[i] = xMin + step * i; } CurveExtrapolator extrap = QuadraticLeftCurveExtrapolator.INSTANCE; int yDim = yValues.Length; for (int k = 0; k < yDim; ++k) { BoundCurveInterpolator bci = CurveInterpolators.LOG_NATURAL_SPLINE_MONOTONE_CUBIC.bind(xValues, yValues[k], extrap, CurveExtrapolators.LOG_LINEAR); // Check C0 continuity assertEquals(bci.interpolate(xValues.get(0) - 1.e-14), bci.interpolate(xValues.get(0)), TOL); // Check C1 continuity assertEquals(bci.firstDerivative(xValues.get(0) - TOL), bci.firstDerivative(xValues.get(0)), TOL * 1.e2); // Test sensitivity double[] yValues1Up = yValues[k].toArray(); double[] yValues1Dw = yValues[k].toArray(); for (int j = 0; j < nData; ++j) { yValues1Up[j] = yValues[k].get(j) * (1.0 + EPS); yValues1Dw[j] = yValues[k].get(j) * (1.0 - EPS); BoundCurveInterpolator bciUp = CurveInterpolators.LOG_NATURAL_SPLINE_MONOTONE_CUBIC.bind(xValues, DoubleArray.ofUnsafe(yValues1Up), extrap, CurveExtrapolators.LOG_LINEAR); BoundCurveInterpolator bciDw = CurveInterpolators.LOG_NATURAL_SPLINE_MONOTONE_CUBIC.bind(xValues, DoubleArray.ofUnsafe(yValues1Dw), extrap, CurveExtrapolators.LOG_LINEAR); for (int i = 0; i < nKeys; ++i) { double res1 = 0.5 * (bciUp.interpolate(xKeys[i]) - bciDw.interpolate(xKeys[i])) / EPS / yValues[k].get(j); assertEquals(res1, bci.parameterSensitivity(xKeys[i]).get(j), Math.Max(Math.Abs(yValues[k].get(j)) * EPS, EPS) * 1.e2); //because gradient is NOT exact } yValues1Up[j] = yValues[k].get(j); yValues1Dw[j] = yValues[k].get(j); } } }
public virtual void test_interpolatorExtrapolator() { DoubleArray xValues = DoubleArray.of(1, 2, 3); DoubleArray yValues = DoubleArray.of(2, 3, 5); CurveExtrapolator extrap = InterpolatorCurveExtrapolator.INSTANCE; BoundCurveInterpolator boundInterp = LINEAR_INTERPOLATOR.bind(xValues, yValues, extrap, extrap); assertEquals(boundInterp.interpolate(0.5), 1.5, TOL); assertEquals(boundInterp.interpolate(1), 2, TOL); assertEquals(boundInterp.interpolate(1.5), 2.5, TOL); assertEquals(boundInterp.interpolate(2), 3, TOL); assertEquals(boundInterp.interpolate(2.5), 4, TOL); assertEquals(boundInterp.interpolate(3), 5, TOL); assertEquals(boundInterp.interpolate(3.5), 6, TOL); }
// regression to ISDA curve public virtual void curveNegativeRateRegressionTest() { double[] xValues = new double[] { 0.09589041095890412, 0.1726027397260274, 0.2547945205479452, 0.5041095890410959, 0.7561643835616438, 1.0082191780821919, 2.0136986301369864, 3.0109589041095894, 4.008219178082192, 5.010958904109589, 6.010958904109589, 7.010958904109589, 8.016438356164384, 9.013698630136986, 10.013698630136986, 12.013698630136986, 15.016438356164384, 20.021917808219175, 30.032876712328765 }; double[] yValues = new double[] { -0.0020786675364765166, -0.0016860241245632032, -0.0013445488774423426, -4.237821212705129E-4, 2.5198253623336676E-5, 5.935456094577134E-4, -3.2426565772714425E-4, 6.147334333200949E-4, 0.0019060366773708986, 0.0033107384678633615, 0.004774430364382846, 0.006237401212672876, 0.007639615209817064, 0.00896830709117619, 0.010164859928720184, 0.012196812821300893, 0.014410766977011871, 0.01623618497051232, 0.016522578536714926 }; CurveExtrapolator left = CurveExtrapolators.FLAT; CurveExtrapolator right = CurveExtrapolators.PRODUCT_LINEAR; BoundCurveInterpolator interp = INTERP.bind(DoubleArray.ofUnsafe(xValues), DoubleArray.ofUnsafe(yValues), left, right); double[] keys = new double[] { 1d / 365d, 17d / 365d, 30d / 365d, 98d / 365d, 1d, 2.35, 6d, 10d, 12.6, 28d, 32d, 39d }; // interpolate double[] expected = new double[] { -0.0020786675364765166, -0.0020786675364765166, -0.0020786675364765166, -0.0012495606047715551, 5.795315650672766E-4, 8.145045403416393E-5, 0.004761034017457297, 0.010150085453826136, 0.01271200378309255, 0.016480992621622493, 0.016557789252559695, 0.016654277327326956 }; for (int i = 0; i < keys.Length; ++i) { double computed = interp.interpolate(keys[i]); assertEquals(computed, expected[i], EPS); } // sensitivity double[][] sensiExp = new double[][] { new double[] { 1d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0.0 }, new double[] { 1d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0.0 }, new double[] { 1d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0.0 }, new double[] { 0d, 0d, 0.8968378560215295, 0.1031621439784705, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0.0 }, new double[] { 0d, 0d, 0d, 0d, 0.024657534246575567, 0.9753424657534244, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0.0 }, new double[] { 0d, 0d, 0d, 0d, 0d, 0d, 0.5679270452660136, 0.43207295473398644, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0.0 }, new double[] { 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0.009152436354538397, 0.9908475636454616, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0.0 }, new double[] { 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0.012347532370050315, 0.9876524676299496, 0d, 0d, 0d, 0.0 }, new double[] { 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0.7672982701729827, 0.23270172982701726, 0d, 0.0 }, new double[] { 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0.1452054794520546, 0.8547945205479454 }, new double[] { 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, -0.12294520547945219, 1.1229452054794522 }, new double[] { 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, -0.4598524762908325, 1.4598524762908325 } }; for (int i = 0; i < keys.Length; ++i) { DoubleArray computed = interp.parameterSensitivity(keys[i]); assertTrue(DoubleArrayMath.fuzzyEquals(computed.toArray(), sensiExp[i], EPS)); } // fwd rate double[] fwdExp = new double[] { -0.0020786675364765166, -0.0020786675364765166, -0.0020786675364765166, 5.172212669050933E-4, 0.0022985876769608432, 0.0025107892902424037, 0.012108930306120206, 0.02095022660137702, 0.023268603631019753, 0.017095365669120136, 0.017095365669120136, 0.017095365669120136 }; for (int i = 0; i < keys.Length; ++i) { double value = interp.interpolate(keys[i]); double deriv = interp.firstDerivative(keys[i]); double computed = deriv * keys[i] + value; assertEquals(computed, fwdExp[i], EPS); } }
// regression to ISDA curve public virtual void curveRegressionTest() { double[] xValues = new double[] { 0.08767123287671233, 0.1726027397260274, 0.2602739726027397, 0.5095890410958904, 1.010958904109589, 2.010958904109589, 3.0136986301369864, 4.0191780821917815, 5.016438356164384, 6.013698630136987, 7.016438356164384, 8.016438356164384, 9.016438356164384, 10.021917808219179, 12.01917808219178, 15.027397260273974, 20.024657534246575, 25.027397260273972, 30.030136986301372 }; double[] yValues = new double[] { 0.0015967771993938666, 0.002000101499768777, 0.002363431670279865, 0.003338175293899776, 0.005634608399714134, 0.00440326902435394, 0.007809961130263494, 0.011941089607974827, 0.015908558015433557, 0.019426790989545677, 0.022365655212981644, 0.02480329609280203, 0.02681632723967965, 0.028566047406753222, 0.031343018999443514, 0.03409375145707815, 0.036451406286344155, 0.0374228389649933, 0.037841116301420584 }; CurveExtrapolator left = CurveExtrapolators.FLAT; CurveExtrapolator right = CurveExtrapolators.PRODUCT_LINEAR; BoundCurveInterpolator interp = INTERP.bind(DoubleArray.ofUnsafe(xValues), DoubleArray.ofUnsafe(yValues), left, right); double[] keys = new double[] { 1d / 365d, 17d / 365d, 30d / 365d, 98d / 365d, 1d, 2.35, 6d, 10d, 12.6, 28d, 32d, 39d }; // interpolate double[] expected = new double[] { 0.0015967771993938666, 0.0015967771993938666, 0.0015967771993938666, 0.0024244214596922794, 0.005609029445739646, 0.005880433874305883, 0.01938638577242741, 0.02853165777399691, 0.031976443846372445, 0.03768939749254428, 0.037969928846136244, 0.038322391316033835 }; for (int i = 0; i < keys.Length; ++i) { double computed = interp.interpolate(keys[i]); assertEquals(computed, expected[i], EPS); } // sensitivity double[][] sensiExp = new double[][] { new double[] { 1d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0.0 }, new double[] { 1d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0.0 }, new double[] { 1.0, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0.0 }, new double[] { 0d, 0d, 0.9374299170217537, 0.0625700829782464, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0.0 }, new double[] { 0d, 0d, 0d, 0.011138558275319966, 0.98886144172468, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0.0 }, new double[] { 0d, 0d, 0d, 0d, 0d, 0.5663932037211347, 0.43360679627886545, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0.0 }, new double[] { 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0.011484520046164301, 0.9885154799538357, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0.0 }, new double[] { 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0.01965436153932362, 0.9803456384606765, 0d, 0d, 0d, 0d, 0.0 }, new double[] { 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0.7697250253579322, 0.23027497464206784, 0d, 0d, 0.0 }, new double[] { 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0.3627229965940976, 0.6372770034059024 }, new double[] { 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, -0.3079596561838882, 1.3079596561838882 }, new double[] { 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, 0d, -1.1506122199305884, 2.1506122199305886 } }; for (int i = 0; i < keys.Length; ++i) { DoubleArray computed = interp.parameterSensitivity(keys[i]); assertTrue(DoubleArrayMath.fuzzyEquals(computed.toArray(), sensiExp[i], EPS)); } // fwd rate double[] fwdExp = new double[] { 0.0015967771993938666, 0.0015967771993938666, 0.0015967771993938666, 0.004355764791085397, 0.007968687949886104, 0.01464196114594003, 0.037124276087345934, 0.04425631735181895, 0.04508415518352911, 0.03993364832127998, 0.03993364832127998, 0.03993364832127998 }; for (int i = 0; i < keys.Length; ++i) { double value = interp.interpolate(keys[i]); double deriv = interp.firstDerivative(keys[i]); double computed = deriv * keys[i] + value; assertEquals(computed, fwdExp[i], EPS); } }
private LoadedCurveSettings(CurveName curveName, ValueType xValueType, ValueType yValueType, DayCount dayCount, CurveInterpolator interpolator, CurveExtrapolator extrapolatorLeft, CurveExtrapolator extrapolatorRight) { JodaBeanUtils.notNull(curveName, "curveName"); JodaBeanUtils.notNull(xValueType, "xValueType"); JodaBeanUtils.notNull(yValueType, "yValueType"); JodaBeanUtils.notNull(dayCount, "dayCount"); JodaBeanUtils.notNull(interpolator, "interpolator"); JodaBeanUtils.notNull(extrapolatorLeft, "extrapolatorLeft"); JodaBeanUtils.notNull(extrapolatorRight, "extrapolatorRight"); this.curveName = curveName; this.xValueType = xValueType; this.yValueType = yValueType; this.dayCount = dayCount; this.interpolator = interpolator; this.extrapolatorLeft = extrapolatorLeft; this.extrapolatorRight = extrapolatorRight; }
public virtual void calibration_present_value_discountCurve_clamped() { CurveInterpolator interp = CurveInterpolators.LOG_NATURAL_SPLINE_DISCOUNT_FACTOR; CurveExtrapolator extrapRight = CurveExtrapolators.LOG_LINEAR; CurveExtrapolator extrapLeft = CurveExtrapolators.INTERPOLATOR; InterpolatedNodalCurveDefinition dsc = InterpolatedNodalCurveDefinition.builder().name(DSCON_CURVE_NAME).xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.DISCOUNT_FACTOR).dayCount(CURVE_DC).interpolator(interp).extrapolatorLeft(extrapLeft).extrapolatorRight(extrapRight).nodes(DSC_NODES).build(); InterpolatedNodalCurveDefinition fwd = InterpolatedNodalCurveDefinition.builder().name(FWD3_CURVE_NAME).xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.DISCOUNT_FACTOR).dayCount(CURVE_DC).interpolator(interp).extrapolatorLeft(extrapLeft).extrapolatorRight(extrapRight).nodes(FWD3_NODES).build(); RatesCurveGroupDefinition config = RatesCurveGroupDefinition.builder().name(CURVE_GROUP_NAME).addCurve(dsc, USD, USD_FED_FUND).addForwardCurve(fwd, USD_LIBOR_3M).build(); RatesProvider result = CALIBRATOR.calibrate(config, ALL_QUOTES_BD, REF_DATA); assertResult(result, ALL_QUOTES_BD); double shift = 1.0E-6; System.Func <MarketData, RatesProvider> f = marketData => CALIBRATOR.calibrate(config, marketData, REF_DATA); calibration_market_quote_sensitivity_check(f, config, shift, TS_EMPTY); }
public virtual void test_interpolatorExtrapolator() { DoubleArray xValues = DoubleArray.of(1, 2, 3); DoubleArray yValues = DoubleArray.of(2, 3, 5); DoubleArray yValuesLog = DoubleArray.of(Math.Log(2), Math.Log(3), Math.Log(5)); CurveExtrapolator extrap = InterpolatorCurveExtrapolator.INSTANCE; // log-linear same as linear where y-values have had log applied BoundCurveInterpolator bciLinear = CurveInterpolators.LINEAR.bind(xValues, yValuesLog, extrap, extrap); BoundCurveInterpolator bci = LL_INTERPOLATOR.bind(xValues, yValues, extrap, extrap); assertEquals(Math.Log(bci.interpolate(0.5)), bciLinear.interpolate(0.5), EPS); assertEquals(Math.Log(bci.interpolate(1)), bciLinear.interpolate(1), EPS); assertEquals(Math.Log(bci.interpolate(1.5)), bciLinear.interpolate(1.5), EPS); assertEquals(Math.Log(bci.interpolate(2)), bciLinear.interpolate(2), EPS); assertEquals(Math.Log(bci.interpolate(2.5)), bciLinear.interpolate(2.5), EPS); assertEquals(Math.Log(bci.interpolate(3)), bciLinear.interpolate(3), EPS); assertEquals(Math.Log(bci.interpolate(3.5)), bciLinear.interpolate(3.5), EPS); }
//------------------------------------------------------------------------- // restricted constructor //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @ImmutableConstructor private InterpolatedNodalCurve(CurveMetadata metadata, com.opengamma.strata.collect.array.DoubleArray xValues, com.opengamma.strata.collect.array.DoubleArray yValues, com.opengamma.strata.market.curve.interpolator.CurveInterpolator interpolator, com.opengamma.strata.market.curve.interpolator.CurveExtrapolator extrapolatorLeft, com.opengamma.strata.market.curve.interpolator.CurveExtrapolator extrapolatorRight) private InterpolatedNodalCurve(CurveMetadata metadata, DoubleArray xValues, DoubleArray yValues, CurveInterpolator interpolator, CurveExtrapolator extrapolatorLeft, CurveExtrapolator extrapolatorRight) { JodaBeanUtils.notNull(metadata, "metadata"); JodaBeanUtils.notNull(xValues, "times"); JodaBeanUtils.notNull(yValues, "values"); JodaBeanUtils.notNull(interpolator, "interpolator"); JodaBeanUtils.notNull(extrapolatorLeft, "extrapolatorLeft"); JodaBeanUtils.notNull(extrapolatorRight, "extrapolatorRight"); if (xValues.size() < 2) { throw new System.ArgumentException("Length of x-values must be at least 2"); } if (xValues.size() != yValues.size()) { throw new System.ArgumentException("Length of x-values and y-values must match"); } metadata.ParameterMetadata.ifPresent(@params => { if (xValues.size() != @params.size()) { throw new System.ArgumentException("Length of x-values and parameter metadata must match when metadata present"); } }); for (int i = 1; i < xValues.size(); i++) { if (xValues.get(i) <= xValues.get(i - 1)) { throw new System.ArgumentException("Array of x-values must be sorted and unique"); } } this.metadata = metadata; this.xValues = xValues; this.yValues = yValues; this.extrapolatorLeft = extrapolatorLeft; this.interpolator = interpolator; this.extrapolatorRight = extrapolatorRight; this.boundInterpolator = interpolator.bind(xValues, yValues, extrapolatorLeft, extrapolatorRight); this.parameterMetadata = IntStream.range(0, ParameterCount).mapToObj(i => getParameterMetadata(i)).collect(toImmutableList()); }
/// <summary> /// Creates an interpolated curve with metadata. /// </summary> /// <param name="metadata"> the curve metadata </param> /// <param name="xValues"> the x-values </param> /// <param name="yValues"> the y-values </param> /// <param name="interpolator"> the interpolator </param> /// <param name="extrapolatorLeft"> the extrapolator for extrapolating off the left-hand end of the curve </param> /// <param name="extrapolatorRight"> the extrapolator for extrapolating off the right-hand end of the curve </param> /// <returns> the curve </returns> public static InterpolatedNodalCurve of(CurveMetadata metadata, DoubleArray xValues, DoubleArray yValues, CurveInterpolator interpolator, CurveExtrapolator extrapolatorLeft, CurveExtrapolator extrapolatorRight) { return(InterpolatedNodalCurve.builder().metadata(metadata).xValues(xValues).yValues(yValues).interpolator(interpolator).extrapolatorLeft(extrapolatorLeft).extrapolatorRight(extrapolatorRight).build()); }
//------------------------------------------------------------------------- /// <summary> /// Obtains an instance. /// </summary> /// <param name="curveName"> the curve name </param> /// <param name="yValueType"> the value type </param> /// <param name="dayCount"> the day count </param> /// <param name="interpolator"> the interpolator </param> /// <param name="extrapolatorLeft"> the left extrapolator </param> /// <param name="extrapolatorRight"> the right extrapolator </param> /// <returns> the curve settings </returns> internal static LoadedCurveSettings of(CurveName curveName, ValueType xValueType, ValueType yValueType, DayCount dayCount, CurveInterpolator interpolator, CurveExtrapolator extrapolatorLeft, CurveExtrapolator extrapolatorRight) { return(new LoadedCurveSettings(curveName, xValueType, yValueType, dayCount, interpolator, extrapolatorLeft, extrapolatorRight)); }
/// <summary> /// Obtains an instance from the specified interpolators and extrapolators. /// </summary> /// <param name="xInterpolator"> the x-value interpolator </param> /// <param name="xExtrapolatorLeft"> the x-value left extrapolator </param> /// <param name="xExtrapolatorRight"> the x-value right extrapolator </param> /// <param name="yInterpolator"> the y-value interpolator </param> /// <param name="yExtrapolatorLeft"> the y-value left extrapolator </param> /// <param name="yExtrapolatorRight"> the y-value right extrapolator </param> /// <returns> the index </returns> /// <exception cref="IllegalArgumentException"> if the name is not known </exception> public static GridSurfaceInterpolator of(CurveInterpolator xInterpolator, CurveExtrapolator xExtrapolatorLeft, CurveExtrapolator xExtrapolatorRight, CurveInterpolator yInterpolator, CurveExtrapolator yExtrapolatorLeft, CurveExtrapolator yExtrapolatorRight) { return(new GridSurfaceInterpolator(xInterpolator, xExtrapolatorLeft, xExtrapolatorRight, yInterpolator, yExtrapolatorLeft, yExtrapolatorRight)); }
public virtual void test_of_lookup_null() { assertThrowsIllegalArg(() => CurveExtrapolator.of(null)); }
public virtual void test_of_lookup_notFound() { assertThrowsIllegalArg(() => CurveExtrapolator.of("Rubbish")); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test(dataProvider = "name") public void test_extendedEnum(CurveExtrapolator convention, String name) public virtual void test_extendedEnum(CurveExtrapolator convention, string name) { ImmutableMap <string, CurveExtrapolator> map = CurveExtrapolator.extendedEnum().lookupAll(); assertEquals(map.get(name), convention); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test(dataProvider = "name") public void test_of_lookup(CurveExtrapolator convention, String name) public virtual void test_of_lookup(CurveExtrapolator convention, string name) { assertEquals(CurveExtrapolator.of(name), convention); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test(dataProvider = "name") public void test_toString(CurveExtrapolator convention, String name) public virtual void test_toString(CurveExtrapolator convention, string name) { assertEquals(convention.ToString(), name); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test(dataProvider = "name") public void test_name(CurveExtrapolator convention, String name) public virtual void test_name(CurveExtrapolator convention, string name) { assertEquals(convention.Name, name); }
/// <summary> /// Sets the extrapolator for x-values on the right, defaulted to 'Flat". /// This is used for x-values larger than the largest known x-value. </summary> /// <param name="extrapolatorRight"> the new value, not null </param> /// <returns> this, for chaining, not null </returns> public Builder extrapolatorRight(CurveExtrapolator extrapolatorRight) { JodaBeanUtils.notNull(extrapolatorRight, "extrapolatorRight"); this.extrapolatorRight_Renamed = extrapolatorRight; return(this); }