コード例 #1
0
        //-------------------------------------------------------------------------
        public virtual void coverage()
        {
            ParameterizedFunctionalCurve test1 = ParameterizedFunctionalCurve.of(METADATA, PARAMETERS, VALUE_FUNCTION, DERIVATIVE_FUNCTION, SENSITIVITY_FUNCTION);

            coverImmutableBean(test1);

            DoubleArray   @params  = DoubleArray.of(1.2);
            CurveMetadata metadata = DefaultCurveMetadata.builder().curveName("test").yValueType(ValueType.DISCOUNT_FACTOR).xValueType(ValueType.YEAR_FRACTION).build();

            System.Func <DoubleArray, double, double> value = (DoubleArray t, double?u) =>
            {
                return(t.get(0) * u);
            };
            System.Func <DoubleArray, double, double> deriv = (DoubleArray t, double?u) =>
            {
                return(t.get(0));
            };
            System.Func <DoubleArray, double, DoubleArray> sensi = (DoubleArray t, double?u) =>
            {
                return(DoubleArray.of(u));
            };
            ParameterizedFunctionalCurve test2 = ParameterizedFunctionalCurve.of(metadata, @params, value, deriv, sensi);

            coverBeanEquals(test1, test2);
        }
コード例 #2
0
        public virtual void test_withMetadata()
        {
            ParameterizedFunctionalCurve @base    = ParameterizedFunctionalCurve.of(METADATA, PARAMETERS, VALUE_FUNCTION, DERIVATIVE_FUNCTION, SENSITIVITY_FUNCTION);
            CurveMetadata metadata                = DefaultCurveMetadata.builder().curveName("test").yValueType(ValueType.DISCOUNT_FACTOR).xValueType(ValueType.YEAR_FRACTION).build();
            ParameterizedFunctionalCurve expected = ParameterizedFunctionalCurve.of(metadata, PARAMETERS, VALUE_FUNCTION, DERIVATIVE_FUNCTION, SENSITIVITY_FUNCTION);

            assertEquals(@base.withMetadata(metadata), expected);
        }
コード例 #3
0
        public virtual void test_withPerturbation()
        {
            ParameterizedFunctionalCurve @base    = ParameterizedFunctionalCurve.of(METADATA, PARAMETERS, VALUE_FUNCTION, DERIVATIVE_FUNCTION, SENSITIVITY_FUNCTION);
            DoubleArray parameters                = PARAMETERS.minus(2d);
            ParameterizedFunctionalCurve expected = ParameterizedFunctionalCurve.of(METADATA, parameters, VALUE_FUNCTION, DERIVATIVE_FUNCTION, SENSITIVITY_FUNCTION);

            assertEquals(@base.withPerturbation((i, v, m) => v - 2d), expected);
        }
コード例 #4
0
        //-------------------------------------------------------------------------

        public virtual void test_withParameter()
        {
            ParameterizedFunctionalCurve @base    = ParameterizedFunctionalCurve.of(METADATA, PARAMETERS, VALUE_FUNCTION, DERIVATIVE_FUNCTION, SENSITIVITY_FUNCTION);
            DoubleArray parameters                = DoubleArray.of(1.2, 1d, 8.9);
            ParameterizedFunctionalCurve expected = ParameterizedFunctionalCurve.of(METADATA, parameters, VALUE_FUNCTION, DERIVATIVE_FUNCTION, SENSITIVITY_FUNCTION);

            assertEquals(@base.withParameter(1, 1d), expected);
        }
コード例 #5
0
        public virtual void test_sensitivities()
        {
            ParameterizedFunctionalCurve test = ParameterizedFunctionalCurve.of(METADATA, PARAMETERS, VALUE_FUNCTION, DERIVATIVE_FUNCTION, SENSITIVITY_FUNCTION);
            DoubleArray sensiVal = DoubleArray.of(1d, 2d, 3d);

            assertEquals(test.createParameterSensitivity(sensiVal), UnitParameterSensitivity.of(METADATA.CurveName, METADATA.ParameterMetadata.get(), sensiVal));
            assertEquals(test.createParameterSensitivity(USD, sensiVal), CurrencyParameterSensitivity.of(METADATA.CurveName, METADATA.ParameterMetadata.get(), USD, sensiVal));
        }
コード例 #6
0
        //-------------------------------------------------------------------------
        public virtual void test_values()
        {
            ParameterizedFunctionalCurve test = ParameterizedFunctionalCurve.of(METADATA, PARAMETERS, VALUE_FUNCTION, DERIVATIVE_FUNCTION, SENSITIVITY_FUNCTION);
            double x = 5.2;

            assertEquals(test.yValue(x), VALUE_FUNCTION.apply(PARAMETERS, x));
            assertEquals(test.firstDerivative(x), DERIVATIVE_FUNCTION.apply(PARAMETERS, x));
            assertEquals(test.yValueParameterSensitivity(x), UnitParameterSensitivity.of(METADATA.CurveName, METADATA.ParameterMetadata.get(), SENSITIVITY_FUNCTION.apply(PARAMETERS, x)));
        }
        //-------------------------------------------------------------------------
        public virtual void test_curve()
        {
            ParameterizedFunctionalCurveDefinition test = ParameterizedFunctionalCurveDefinition.builder().dayCount(ACT_365F).valueFunction(VALUE_FUNCTION).derivativeFunction(DERIVATIVE_FUNCTION).sensitivityFunction(SENSITIVITY_FUNCTION).initialGuess(INITIAL_PARAMS).name(CURVE_NAME).nodes(NODES).parameterMetadata(PARAM_METADATA).xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.ZERO_RATE).build();
            DefaultCurveMetadata         metadata       = DefaultCurveMetadata.builder().curveName(CURVE_NAME).xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.ZERO_RATE).dayCount(ACT_365F).parameterMetadata(PARAM_METADATA).build();
            DoubleArray                  parameters     = DoubleArray.of(1d, 1.5d, -0.5d);
            ParameterizedFunctionalCurve expected       = ParameterizedFunctionalCurve.builder().metadata(metadata).valueFunction(VALUE_FUNCTION).derivativeFunction(DERIVATIVE_FUNCTION).sensitivityFunction(SENSITIVITY_FUNCTION).parameters(parameters).build();

            assertEquals(test.curve(VAL_DATE, metadata, parameters), expected);
        }
コード例 #8
0
 public override bool Equals(object obj)
 {
     if (obj == this)
     {
         return(true);
     }
     if (obj != null && obj.GetType() == this.GetType())
     {
         ParameterizedFunctionalCurve other = (ParameterizedFunctionalCurve)obj;
         return(JodaBeanUtils.equal(metadata, other.metadata) && JodaBeanUtils.equal(parameters, other.parameters) && JodaBeanUtils.equal(valueFunction, other.valueFunction) && JodaBeanUtils.equal(derivativeFunction, other.derivativeFunction) && JodaBeanUtils.equal(sensitivityFunction, other.sensitivityFunction));
     }
     return(false);
 }
コード例 #9
0
        //-------------------------------------------------------------------------
        public virtual void test_of()
        {
            ParameterizedFunctionalCurve test = ParameterizedFunctionalCurve.of(METADATA, PARAMETERS, VALUE_FUNCTION, DERIVATIVE_FUNCTION, SENSITIVITY_FUNCTION);

            assertEquals(test.ValueFunction, VALUE_FUNCTION);
            assertEquals(test.DerivativeFunction, DERIVATIVE_FUNCTION);
            assertEquals(test.SensitivityFunction, SENSITIVITY_FUNCTION);
            assertEquals(test.Metadata, METADATA);
            assertEquals(test.Name, METADATA.CurveName);
            assertEquals(test.getParameter(2), PARAMETERS.get(2));
            assertEquals(test.ParameterCount, PARAMETERS.size());
            assertEquals(test.getParameterMetadata(1), METADATA.getParameterMetadata(1));
            assertEquals(test.Parameters, PARAMETERS);
        }
コード例 #10
0
        private readonly IList <ParameterMetadata> parameterMetadata;  // derived, not a property

        //-------------------------------------------------------------------------
        /// <summary>
        /// Obtains an instance.
        /// </summary>
        /// <param name="metadata">  the metadata </param>
        /// <param name="parameters">  the parameters </param>
        /// <param name="valueFunction">  the value function </param>
        /// <param name="derivativeFunction">  the derivative function </param>
        /// <param name="sensitivityFunction">  the parameter sensitivity function </param>
        /// <returns> the instance </returns>
        public static ParameterizedFunctionalCurve of(CurveMetadata metadata, DoubleArray parameters, System.Func <DoubleArray, double, double> valueFunction, System.Func <DoubleArray, double, double> derivativeFunction, System.Func <DoubleArray, double, DoubleArray> sensitivityFunction)
        {
            return(ParameterizedFunctionalCurve.builder().metadata(metadata).parameters(parameters).valueFunction(valueFunction).derivativeFunction(derivativeFunction).sensitivityFunction(sensitivityFunction).build());
        }