Code:
double function_temp(float p1, float var1)
{
float rho = 0.3f; // Model Param
float sigma0 = 0.02f; // Model Param
float m0 = 1.4f; // Model Param
int k = 6; // Fixed Param
float lambda = -0.1f; // Option Param
float initPrice = 50.f; // Option Param
// float strikePrice = 65.f; // Option Param
float interest = 0.00018f; // Option Param
// int noOfSum = 50; // Sym Param
int width = 128; // Sym Param
int height = 256; // Sym Param
return (double)clMonteCarloAMSM.runCLKernels2(
p1,//gkk, // Model Param
b,//b, // Model Param
rho, // Model Param
sigma0, // Model Param
m0, // Model Param
k, // Fixed Param
lambda, // Option Param
initPrice, // Option Param
var1,//strikePrice, // Option Param
interest, // Option Param
22,//noOfSum, // Sym Param
width, // Sym Param
height // Sym Param
);
}
Code:
void function_cx_1_func(const real_1d_array &c, const real_1d_array &x, double &func, void *ptr)
{
func = function_temp((float)c[0],(float)x[0]);
std::cout<<" c[0] = " << c[0] << " x[0] = " << x[0] << std::endl;
}
Code:
main(int argc, char * argv[])
{
real_2d_array x = "[[25],[30],[35],[40],[45],[50],[55],[60],[65],[70],[75]]";
real_1d_array y = "[24.99959, 20.01935, 15.03914, 10.07982, 5.9340054, 1.814159, 0.3633873, 0.05629168, 0.006411664, 0.000785, 0.00005]";
real_1d_array c = "[0.99]";
/* real_2d_array x = "[[-1],[-0.8],[-0.6],[-0.4],[-0.2],[0],[0.2],[0.4],[0.6],[0.8],[1.0]]";
real_1d_array y = "[0.223130, 0.382893, 0.582748, 0.786628, 0.941765, 1.000000, 0.941765, 0.786628, 0.582748, 0.382893, 0.223130]";
real_1d_array c = "[0.3]"; */
real_1d_array bndl = "[0.00002]";
real_1d_array bndu = "[0.99999]";
double epsf = 0;
double epsx = 0.0001;
ae_int_t maxits = 0;
ae_int_t info;
lsfitstate state;
lsfitreport rep;
double diffstep = 0.0001;
//
// Fitting without weights
//
lsfitcreatef(x, y, c, diffstep, state);
lsfitsetbc(state, bndl, bndu);
lsfitsetcond(state, epsf, epsx, maxits);
alglib::lsfitfit(state, function_cx_1_func);
lsfitresults(state, info, c, rep);
printf("%s\n", c.tostring(1).c_str()); // EXPECTED: [1.0]
}
The function clMonteCarloAMSM.runCLKernels2(...) is an integral computed by Monte Carlo technique as it is evident from the name.
The plot of the sum([runCLKernels2(gkk_real = 0.95,...,strikePrice_i) - runCLKernels2(gkk,...,,strikePrice_i),i=1..11]^2 w.r.t.
gkk (minimization parameter) is:
I've changed something and it makes a lot of steps, but there is a new problem. It doesn't converge to the right value (0.95). I tried different very close initial values: 0.92 -> 0.9, 0.99 -> 1.0, 0.97 -> 1.0
Thank you for your answer.