public double integratedCovariance(int i, int j, double t, Vector x) { if (corrModel_.isTimeIndependent()) { try { // if all objects support these methods // thats by far the fastest way to get the // integrated covariance return(corrModel_.correlation(i, j, 0.0, x) * volaModel_.integratedVariance(j, i, t, x)); //verifier la methode integratedVariance, qui bdoit etre implémenté } catch (System.Exception) { // okay proceed with the // slow numerical integration routine } } try { Utils.QL_REQUIRE(x.empty() != false, () => "can not handle given x here"); } catch { //OK x empty } double tmp = 0.0; VarProxy_Helper helper = new VarProxy_Helper(this, i, j); GaussKronrodAdaptive integrator = new GaussKronrodAdaptive(1e-10, 10000); for (int k = 0; k < 64; ++k) { tmp += integrator.value(helper.value, k * t / 64.0, (k + 1) * t / 64.0); } return(tmp); }
public virtual Matrix integratedCovariance(double t, Vector x) { // this implementation is not intended for production. // because it is too slow and too inefficient. // This method is useful for testing and R&D. // Please overload the method within derived classes. //QL_REQUIRE(x.empty(), "can not handle given x here"); try { if (!(x.empty())) { throw new ApplicationException("can not handle given x here"); } } catch { } //x is empty or null Matrix tmp = new Matrix(size_, size_, 0.0); for (int i = 0; i < size_; ++i) { for (int j = 0; j <= i; ++j) { Var_Helper helper = new Var_Helper(this, i, j); GaussKronrodAdaptive integrator = new GaussKronrodAdaptive(1e-10, 10000); for (int k = 0; k < 64; ++k) { tmp[i, j] += integrator.value(helper.value, k * t / 64.0, (k + 1) * t / 64.0); } tmp[j, i] = tmp[i, j]; } } return(tmp); }
public double integrate(double a, double b, ConundrumIntegrand integrand) { double result = .0; //double abserr =.0; //double alpha = 1.0; //double epsabs = precision_; //double epsrel = 1.0; // we are interested only in absolute precision //size_t neval =0; // we use the non adaptive algorithm only for semi infinite interval if (a > 0) { // we estimate the actual boudary by testing integrand values double upperBoundary = 2 * a; while (integrand.value(upperBoundary) > precision_) { upperBoundary *= 2.0; } // sometimes b < a because of a wrong estimation of b based on stdev if (b > a) { upperBoundary = Math.Min(upperBoundary, b); } GaussKronrodNonAdaptive gaussKronrodNonAdaptive = new GaussKronrodNonAdaptive(precision_, 1000000, 1.0); // if the integration intervall is wide enough we use the // following change variable x -> a + (b-a)*(t/(a-b))^3 upperBoundary = Math.Max(a, Math.Min(upperBoundary, hardUpperLimit_)); if (upperBoundary > 2 * a) { VariableChange variableChange = new VariableChange(integrand.value, a, upperBoundary, 3); result = gaussKronrodNonAdaptive.value(variableChange.value, .0, 1.0); } else { result = gaussKronrodNonAdaptive.value(integrand.value, a, upperBoundary); } // if the expected precision has not been reached we use the old algorithm if (!gaussKronrodNonAdaptive.integrationSuccess()) { GaussKronrodAdaptive integrator = new GaussKronrodAdaptive(precision_, 100000); b = Math.Max(a, Math.Min(b, hardUpperLimit_)); result = integrator.value(integrand.value, a, b); } } // if a < b we use the old algorithm else { b = Math.Max(a, Math.Min(b, hardUpperLimit_)); GaussKronrodAdaptive integrator = new GaussKronrodAdaptive(precision_, 100000); result = integrator.value(integrand.value, a, b); } return(result); }
public double integrate(double a, double b, ConundrumIntegrand integrand) { double result = .0; //double abserr =.0; //double alpha = 1.0; //double epsabs = precision_; //double epsrel = 1.0; // we are interested only in absolute precision //size_t neval =0; // we use the non adaptive algorithm only for semi infinite interval if (a > 0) { // we estimate the actual boudary by testing integrand values double upperBoundary = 2 * a; while (integrand.value(upperBoundary) > precision_) upperBoundary *= 2.0; // sometimes b < a because of a wrong estimation of b based on stdev if (b > a) upperBoundary = Math.Min(upperBoundary, b); GaussKronrodNonAdaptive gaussKronrodNonAdaptive = new GaussKronrodNonAdaptive(precision_, 1000000, 1.0); // if the integration intervall is wide enough we use the // following change variable x -> a + (b-a)*(t/(a-b))^3 if (upperBoundary > 2 * a) { VariableChange variableChange = new VariableChange(integrand.value, a, upperBoundary, 3); result = gaussKronrodNonAdaptive.value(variableChange.value, .0, 1.0); } else { result = gaussKronrodNonAdaptive.value(integrand.value, a, upperBoundary); } // if the expected precision has not been reached we use the old algorithm if (!gaussKronrodNonAdaptive.integrationSuccess()) { GaussKronrodAdaptive integrator = new GaussKronrodAdaptive(precision_, 1000000); result = integrator.value(integrand.value, a, b); } } // if a < b we use the old algorithm else { GaussKronrodAdaptive integrator = new GaussKronrodAdaptive(precision_, 1000000); result = integrator.value(integrand.value, a, b); } return result; }
public double integratedCovariance(int i, int j, double t,Vector x) { if (corrModel_.isTimeIndependent()) { try { // if all objects support these methods // thats by far the fastest way to get the // integrated covariance return corrModel_.correlation(i, j, 0.0, x) *volaModel_.integratedVariance(j, i, t, x); //verifier la methode integratedVariance, qui bdoit etre implémenté } catch (System.Exception) { // okay proceed with the // slow numerical integration routine } } //QL_REQUIRE(x.empty(), "can not handle given x here"); try { if (x.empty() == false) throw new ApplicationException("can not handle given x here"); } catch { //OK x empty } double tmp=0.0; VarProxy_Helper helper = new VarProxy_Helper(this, i, j); GaussKronrodAdaptive integrator=new GaussKronrodAdaptive(1e-10, 10000); for (int k=0; k<64; ++k) { tmp+=integrator.value(helper.value, k*t/64.0, (k+1)*t/64.0); } return tmp; }
public virtual Matrix integratedCovariance(double t, Vector x) { // this implementation is not intended for production. // because it is too slow and too inefficient. // This method is useful for testing and R&D. // Please overload the method within derived classes. //QL_REQUIRE(x.empty(), "can not handle given x here"); try { if (!(x.empty())) throw new ApplicationException("can not handle given x here"); } catch { } //x is empty or null Matrix tmp= new Matrix(size_, size_,0.0); for (int i=0; i<size_; ++i) { for (int j=0; j<=i;++j) { Var_Helper helper = new Var_Helper(this, i, j); GaussKronrodAdaptive integrator=new GaussKronrodAdaptive(1e-10, 10000); for (int k=0; k < 64; ++k) { tmp[i,j] +=integrator.value(helper.value, k * t / 64.0, (k + 1) * t / 64.0); } tmp[j,i]=tmp[i,j]; } } return tmp; }