Ejemplo n.º 1
0
void AmericanOption::trainingpaths_erstellen(int l) {
	RNG generator;
	
	double** wdiff = DoubleFeld(N, D);
	for (int m = 0; m < Mtraining(l); ++m) {
		if (l == 0 || m >= Mtraining(l - 1)) {
			for (int d = 0; d < D; ++d)
				for (int n = 0; n < N; ++n)
					if (m % 2 == 0)
						wdiff[n][d] = generator.nextGaussian() * sqrt(dt);
					else
						wdiff[n][d] *= -1.;
			Pfadgenerieren(X[l][m], wdiff, 0, X0);
		} else
			for (int d = 0; d < D; ++d)
				for (int n = 0; n < N; ++n)
					X[l][m][n][d] = X[l - 1][m][n][d];
	}
	deleteDoubleFeld(wdiff, N, D);
}
Ejemplo n.º 2
0
void AmericanOption::addLevelPath(int l) {
	static RNG generator;
	double** XX = NULL;
	double ** wdiff = NULL;

	wdiff = DoubleFeld(N, D);
	XX = DoubleFeld(N, D);

	for (int d = 0; d < D; ++d)
		for (int n = 0; n < N; ++n)
			wdiff[n][d] = generator.nextGaussian() * sqrt(dt);

	Pfadgenerieren(XX, wdiff, 0, X0);
	double e1 = Pfad(XX, l);

	Levelergs[l].push_back(e1);

	deleteDoubleFeld(XX, N, D);
	deleteDoubleFeld(wdiff, N, D);
}
void AmericanOption::Pfadgenerieren(double** X, double** wdiff, int start,
		double * S) {
	for (int j = 0; j < D; ++j)
		X[start][j] = S[j];

//	if (PfadModell == GENERISCHE) {
//		for (int n = start + 1; n < N; ++n)
//			for (int d = 0; d < D; ++d)
//				X[n][d] = xi(wdiff[n][d]);
//	}

	if (PfadModell == ITO) {
		for (int n = start + 1; n < N; ++n)
			for (int d = 0; d < D; ++d)
				X[n][d] = X[n - 1][d]
						* exp(
								(((r - delta) - 0.5 * sigma[d] * sigma[d]) * dt
										+ sigma[d] * wdiff[n][d]));
		return;
	}

	if (PfadModell == LIBOREXP) {
		double wdiff[D];
		for (int n = start + 1; n < N; ++n) {

			double** zwischen = DoubleFeld(6, D);
			for (int d = 0; d < D; ++d)
				zwischen[0][d] = (X[n - 1][d]);
			double DDT = sqrt(dt / 5.);
			double RZWISCHEN[D];
			double GG[D];
			double G[D];
			static RNG generator;
			for (int schritt = 1; schritt < 6; schritt++) {
				for (int d = 0; d < DrivingFactors; ++d)
					wdiff[d] = DDT * generator.nextGaussian();
				double t = (double) (n - 1) * dt
						+ 0.05 * ((double) schritt - 0.5);
				zwischen[schritt][0] = log(S[0]);
				for (int d = 0; d < D; ++d) {
					RZWISCHEN[d] = (zwischen[schritt - 1][d]);
					G[d] = 0.2 * g((double) d * dt - t);
					GG[d] = pow(
							0.2
									* g(
											(double) (d + 1) * dt
													+ 0.05
															* ((double) schritt
																	- 0.5)), 2);
				}

				for (int i = n; i < D; ++i) {
					double driftsum = 0;
					for (int j = n; j <= i; ++j)
						driftsum += dt * RZWISCHEN[j] * G[i] * G[j]
								* corr[i - 1][j - 1] / (1. + dt * RZWISCHEN[j]);
					zwischen[schritt][i] = zwischen[schritt - 1][i]
							* exp(
									(driftsum - 0.5 * GG[i - n]) * 0.05
											+ G[i]
													* prod(chol[i - 1], wdiff,
															DrivingFactors));
				}
			}
			for (int d = 0; d < D; ++d) {
				X[n][d] = zwischen[5][d];
				if (d < n)
					X[n][d] = X[n - 1][d];
			}
			deleteDoubleFeld(zwischen, 6, D);
		}
	}

//	deleteDoubleFeld(wdiff, D);
	if (X[N - 1][0] < 0)
		printf("Error0\n");
//if(generator_noch_loeschen)delete generator;

}