当前位置: 首页>>代码示例>>Java>>正文


Java LevenbergMarquardt类代码示例

本文整理汇总了Java中net.finmath.optimizer.LevenbergMarquardt的典型用法代码示例。如果您正苦于以下问题:Java LevenbergMarquardt类的具体用法?Java LevenbergMarquardt怎么用?Java LevenbergMarquardt使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


LevenbergMarquardt类属于net.finmath.optimizer包,在下文中一共展示了LevenbergMarquardt类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sabrCalibrateParameterForImpliedNormalVols

import net.finmath.optimizer.LevenbergMarquardt; //导入依赖的package包/类
public static double[] sabrCalibrateParameterForImpliedNormalVols(final double underlying, final double maturity, final double[] givenStrikes, final double[] givenVolatilities, final double[] parameterInitialValues, double[] parameterSteps, final double[] parameterLowerBound, final double[] parameterUpperBound) throws SolverException {
	/*
	 * Using Levenberg Marquardt to calibrate SABR
	 */

	double[] targetValues = givenVolatilities;
	int maxIteration = 1000;
	int numberOfThreads = 8;

	LevenbergMarquardt lm = new LevenbergMarquardt(parameterInitialValues, targetValues, maxIteration, numberOfThreads) {			
		private static final long serialVersionUID = -4481118838855868864L;

		@Override
		public void setValues(double[] parameters, double[] values) throws SolverException {
			for(int parameterIndex = 0; parameterIndex<parameters.length; parameterIndex++) {
				parameters[parameterIndex] = Math.min(Math.max(parameters[parameterIndex],parameterLowerBound[parameterIndex]),parameterUpperBound[parameterIndex]);
			}
			for(int strikeIndex = 0; strikeIndex < givenStrikes.length; strikeIndex++) {
				double strike = givenStrikes[strikeIndex];
				values[strikeIndex] = AnalyticFormulas.sabrBerestyckiNormalVolatilityApproximation(parameters[0] /* alpha */, parameters[1] /* beta */, parameters[2] /* rho */, parameters[3] /* nu */, parameters[4] /* displacement */, underlying, strike, maturity);
			}
		}
	};
	lm.setErrorTolerance(1E-16);

	lm.run();

	double[] bestParameters = lm.getBestFitParameters();

	return bestParameters;
}
 
开发者ID:finmath,项目名称:finmath-lib,代码行数:32,代码来源:SABRModel.java

示例2: testSABRCalibration

import net.finmath.optimizer.LevenbergMarquardt; //导入依赖的package包/类
@Test
public void testSABRCalibration() throws SolverException {
	/*
	 * Using Levenberg Marquardt to calibrate SABR
	 */

	final double[] givenStrikes		= {  -0.01, -0.005,    0.0,  0.005,   0.01,   0.02,   0.03 };
	final double[] givenVolatilities	= { 0.0055, 0.0059, 0.0060, 0.0061, 0.0063, 0.0066, 0.0070 };

	final double underlying = 0.0076;
	final double maturity = 20;

	double alpha = 0.006;
	double beta = 0.05;
	double rho = 0.95;
	double nu = 0.075;
	double displacement = 0.02;


	double[] initialParameters = { alpha, beta, rho, nu, displacement };
	double[] targetValues = givenVolatilities;
	int maxIteration = 500;
	int numberOfThreads = 8;

	for(double displacement2 = 0.5; displacement2>0; displacement2 -= 0.001) {
		givenVolatilities[0] = givenVolatilities[0] + 0.00001;
		final double displacement3 = displacement2;
		LevenbergMarquardt lm = new LevenbergMarquardt(initialParameters, targetValues, maxIteration, numberOfThreads) {			
			private static final long serialVersionUID = -4799790311777696204L;

			@Override
			public void setValues(double[] parameters, double[] values) throws SolverException {
				for(int strikeIndex = 0; strikeIndex < givenStrikes.length; strikeIndex++) {
					double strike = givenStrikes[strikeIndex];
					values[strikeIndex] = AnalyticFormulas.sabrBerestyckiNormalVolatilityApproximation(parameters[0] /* alpha */, parameters[1] /* beta */, parameters[2] /* rho */, parameters[3] /* nu */, parameters[4] /* displacement */, underlying, strike, maturity);
				}
			}
		};
		lm.setErrorTolerance(1E-16);

		lm.run();

		double[] bestParameters = lm.getBestFitParameters();

		//			System.out.println(lm.getRootMeanSquaredError() + "\t");
		System.out.println(givenVolatilities[0] + "\t" + lm.getRootMeanSquaredError() + "\t" + Arrays.toString(bestParameters));
	}
}
 
开发者ID:finmath,项目名称:finmath-lib,代码行数:49,代码来源:AnalyticFormulasTest.java


注:本文中的net.finmath.optimizer.LevenbergMarquardt类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。