i have this main : - #include <stdio.h>
-
#include <stdlib.h>
-
#include <string.h>
-
#include <math.h>
-
#include "nrutil.h"
-
-
int N = 2;
-
double S[1000], K_nou[1000], rate[1000], call_price_market[1000], h1[1000], T1[1000] ;
-
FILE *ihandle1, *ihandle2, *ihandle3 , *ihandle4 , *ihandle5 , *ihandle6 ,*ihandle7 , *ohandle , *ohandle1 ;
-
double *S1,*S4, *h_1 , *h_4 ;
-
void amoeba(double **,double *,int,double,double(*)(double []),int *);
-
double func_nllse(double *);
-
double **p,**e,*fp,*x,ftol = 1.0e-8,lambbda ;
-
int nfunk, marime_k;
-
-
int main(void)
-
{
-
int ii=1, jj , tt , counter ,i;
-
-
ihandle1 =fopen("D:\\test_2_param\\K1.txt","rt");
-
for (marime_k=0; (not (feof (ihandle1))); marime_k++){
-
double aux;
-
fscanf(ihandle1,"%lf",&aux);
-
K_nou[marime_k] = aux;
-
}
-
ihandle2 =fopen("D:\\test_2_param\\S.txt","rt");
-
for (i=0;i<marime_k;i++)
-
{
-
double aux;
-
fscanf(ihandle2,"%lf",&aux);
-
S[i] = aux;
-
}
-
ihandle3 =fopen("D:\\test_2_param\\call_price_market.txt","rt");
-
for (i=0;i<marime_k;i++)
-
{
-
double aux;
-
fscanf(ihandle3,"%lf",&aux);
-
call_price_market[i] = aux;
-
}
-
ihandle4 =fopen("D:\\test_2_param\\h1.txt","rt");
-
for (i=0;i<marime_k;i++)
-
{
-
double aux;
-
fscanf(ihandle4,"%lf",&aux);
-
h1[i] = aux;
-
}
-
ihandle5 =fopen("D:\\test_2_param\\T.txt","rt");
-
for (i=0;i<marime_k;i++)
-
{
-
double aux;
-
fscanf(ihandle5,"%lf",&aux);
-
T1[i] = aux;
-
}
-
ihandle6 =fopen("D:\\test_2_param\\rate1.txt","rt");
-
for (i=0;i<marime_k;i++)
-
{
-
double aux;
-
fscanf(ihandle6,"%lf",&aux);
-
rate[i] = aux;
-
}
-
if(!(ohandle=fopen("D:\\test_2_param\\nllse.dat","wt")))
-
{
-
printf("could not open the first output file\n");
-
exit(1);
-
}
-
if(!(ohandle1=fopen("D:\\test_2_param\\h.dat","wt")))
-
{
-
printf("could not open the first output file\n");
-
exit(1);
-
}
-
p=dmatrix(1,N+1,1,N+1);
-
e=dmatrix(1,N+1,1,N+1);
-
x=dvector(1,N);
-
fp=dvector(1,N);
-
-
p[1][1] = 1.0;
-
p[1][2] = 0.6;
-
-
for(ii=1; ii<=N+1; ii++)
-
for(jj=1; jj<=N+1; jj++)
-
{
-
e[ii][jj] = (ii==jj? 1.0:0.0);
-
}
-
-
for(jj=1; jj<=N; jj++)
-
x[jj] = p[1][jj];
-
-
fp[1] = func_nllse(x);
-
-
for(ii=2; ii<=N+1; ii++)
-
{
-
for(jj=1; jj<=N; jj++)
-
{
-
switch(jj)
-
{
-
case 1: lambbda = 0.5; break;
-
case 2: lambbda = 0.05; break;
-
case 3: lambbda = 5.0; break;
-
case 4: lambbda = 0.5;break;
-
case 5: lambbda = 0.5;
-
}
-
x[jj] = p[ii][jj] = p[1][jj] + lambbda *e[ii-1][jj];
-
}
-
fp[ii] = func_nllse(x);
-
}
-
printf("a\n");
-
amoeba(p,fp,N,ftol,func_nllse,&nfunk);
-
fprintf(ohandle,"covergence\n");
-
for(ii=1;ii<=N+1;ii++)
-
{
-
for(jj=1;jj<=N;jj++)
-
{
-
fprintf(ohandle,"%f ",p[ii][jj]);
-
}
-
fprintf(ohandle,"%f\n",-fp[ii]);
-
}
-
-
fclose(ihandle1);
-
fclose(ihandle2);
-
fclose(ihandle3);
-
fclose(ihandle4);
-
fclose(ihandle5);
-
fclose(ihandle6);
-
fclose(ohandle);
-
fclose(ohandle1);
-
-
system("PAUSE");
-
}
-
-
and this is the function that is used in main : - #include <stdio.h>
-
#include <stdlib.h>
-
#include <string.h>
-
#include <math.h>
-
#include "nrutil.h"
-
#include "random_poisson.h"
-
#include "random_normal.h"
-
#define max(x1,x2) ((x1) > (x2))? (x1):(x2)
-
-
double func_nllse(double *p){
-
FILE *out ;
-
double S[1000], K_nou[1000], rate[1000], call_price_market[1000], h1[1000], T1[1000];
-
double *S1 ,*S2 ,*S3 , *S4,*h_1 ,*h_2,*h_3,*h_4, K , S0 , **s1, **s4 ;
-
double beta_0,beta_1,beta_2,c_lat,delta ,mu_1,xi,lambda,gamma_1,bro,k,gamma,a , d;
-
double *Call , *Put ;
-
double **payoff_call1,**payoff_put1,*sum_payoffs_call1,**payoff_call4,**payoff_put4,*sum_payoffs_put1,*sum_payoffs_put4,*sum_payoffs_call4;
-
double r , dt , *t , T, **x, **y, **z, nllse=0;
-
int i , j , R ,l, marime_k;
-
-
T = 0.048 ;
-
R = 390 ;
-
dt =T/R ;
-
r = 0.022 ;
-
// R = 390 ;
-
// t[1] = 0.0 ;
-
// dt =T/360 ;
-
-
beta_0 = 1.21e-7 ;
-
beta_1 = 0.60 ;
-
beta_2 = 0.038 ;
-
c_lat = 2.69 ;
-
delta = 7.16e-4 ;
-
mu_1 = 0.02 ;
-
lambda = 4.56 ;
-
gamma_1 = 2.54 ;
-
xi =1+lambda*(mu_1*mu_1+gamma_1*gamma_1) ;
-
bro = -0.007356 ;
-
k = p[1] ;
-
gamma = p[2] ;
-
a = beta_1+beta_2*((1/xi)+c_lat*c_lat)-1 ;
-
d =1/xi ;
-
-
t =dvector(1,R) ;
-
S1 =dvector(1,R) ;
-
S4 =dvector(1,R) ;
-
h_1 =dvector(1,R) ;
-
h_4 =dvector(1,R) ;
-
sum_payoffs_call1 =dvector(1,marime_k);
-
sum_payoffs_put1 =dvector(1,marime_k);
-
sum_payoffs_call4 =dvector(1,marime_k);
-
sum_payoffs_put4 =dvector(1,marime_k);
-
payoff_call1 =dmatrix(1,1000,1,marime_k);
-
payoff_call4 =dmatrix(1,1000,1,marime_k);
-
payoff_put1 =dmatrix(1,1000,1,marime_k);
-
payoff_put4 =dmatrix(1,1000,1,marime_k);
-
Call =dvector(1,marime_k);
-
Put =dvector(1,marime_k);
-
-
x=dmatrix(1, 1000, 1, R);
-
y=dmatrix(1, 1000, 1, R);
-
z=dmatrix(1, 1000, 1, R);
-
t[1] = 0.0 ;
-
h_1[1] = 0.00000057 ;
-
h_4[1] = 0.00000057 ;
-
S1[1] = 1158.9 ;
-
S4[1] = 1158.9 ;
-
K = 1160.0 ;
-
-
for(l=1; l<marime_k; l++)
-
{
-
sum_payoffs_call1[l] =0;
-
sum_payoffs_put1[l] =0;
-
sum_payoffs_call4[l] =0;
-
sum_payoffs_put4[l] =0;
-
}
-
for(int l=0;l<=marime_k;l++)
-
{
-
h_1[1]=h1[l] ;
-
h_4[1]=h1[l] ;
-
S1[1]=S[l];
-
S4[1]=S[l];
-
r=rate[l];
-
T=T1[l];
-
-
for(i=1;i<=1000; i++)
-
{
-
for(j=2;j<=R ; j++)
-
{
-
x[i][j]= random_normal11(0.0, 1.0);
-
y[i][j]= random_normal12(0.0, 1.0);
-
z[i][j]=random_poisson(lambda*k*dt) ;
-
t[j] = t[j-1] + dt ;
-
h_1[j]=h_1[j-1]+(beta_0+h_1[j-1]*a)*dt +beta_2*d*h_1[j-1]*(gamma_1*y[i][j]+mu_1+bro*gamma*gamma_1)*(gamma_1*y[i][j]+mu_1+bro*gamma*gamma_1)*z[i][j] ;
-
S1[j] = S1[j-1]*exp((r-(h_1[j]/2)+lambda*k*(1-exp(sqrt(h_1[j])*(mu_1+bro*gamma*gamma_1)+(1/2)*h_1[j]*gamma_1*gamma_1)))*dt
-
+sqrt(h_1[j])*sqrt(dt)*x[i][j]+(gamma_1*y[i][j]+mu_1+bro*gamma*gamma_1)*sqrt(h_1[j])*z[i][j]);
-
h_4[j]=h_4[j-1]+(beta_0+h_4[j-1]*a)*dt +beta_2*d*h_4[j-1]*(gamma_1*(y[i][j])+mu_1+bro*gamma*gamma_1)*(gamma_1*(y[i][j])+mu_1+bro*gamma*gamma_1)*(-z[i][j]) ;
-
S4[j] = S4[j-1]*exp((r-(h_4[j]/2)+lambda*k*(1-exp(sqrt(h_4[j])*(mu_1+bro*gamma*gamma_1)+(1/2)*h_4[j]*gamma_1*gamma_1)))*dt
-
+sqrt(h_4[j])*sqrt(dt)*(x[i][j])+(gamma_1*(y[i][j])+mu_1+bro*gamma*gamma_1)*sqrt(h_4[j])*(-z[i][j]));
-
}
-
for(int l=1; l<marime_k; l++)
-
{
-
payoff_call1[i][l] =max(0.0, S1[R]-K_nou[l]);
-
payoff_put1[i][l] =max(0.0, K_nou[l]-S1[R]);
-
payoff_call4[i][l] =max(0.0, S4[R]-K_nou[l]);
-
payoff_put4[i][l] =max(0.0, K_nou[l]-S4[R]);
-
}
-
for(int l=1; l<marime_k; l++)
-
{
-
sum_payoffs_call1[l] += payoff_call1[i][l] ;
-
sum_payoffs_put1[l] += payoff_put1[i][l] ;
-
sum_payoffs_call4[l] += payoff_call4[i][l] ;
-
sum_payoffs_put4[l] += payoff_put4[i][l] ;
-
}
-
}
-
}
-
for(int l=1; l<marime_k; l++)
-
{
-
Call[l] = exp(-rate[l]*T1[l])*(sum_payoffs_call1[l]+sum_payoffs_call4[l])/2000.0 ;
-
nllse += ( Call[l]-call_price_market[l])*(Call[l]-call_price_market[l] ) ;
-
}
-
return (-nllse) ;
-
}
-
but , the main can't see the files that i introduced in main, or can't see those dt that use a file from main , T . what can i do to be more clear for my computer ?
5 1523
do you mean they can't share the headers??
Please clarify what you are trying to do, and what error/unexpected behaviour you are getting
no, my function can't see the files that i read in main .
for example , when i initialize the vectors : - for(int l=0;l<=marime_k;l++)
-
{
-
h_1[1]=h1[l] ;
-
printf("h_1=%.1f\n", h_1[2]);
-
h_4[1]=h1[l] ;
-
S1[1]=S[l];
-
printf("S=%.1f\n", S[2]);
-
S4[1]=S[l];
-
printf("S=%.1f\n", S[2]);
-
r=rate[l];
-
printf(" rate=%.1f\n", rate[2]);
-
T=T1[l];
-
printf("T1=%.1f\n", T1[1]);
-
printf("T1=%.1f\n", T1[2]);
-
dt =T1[l]/R ;
all the values are zero . and this is not true .
Yes, they are all zero: -
double func_nllse(double *p){
-
FILE *out ;
-
double S[1000], K_nou[1000], rate[1000], call_price_market[1000], h1[1000], T1[1000];
-
etc......
-
because the arrays are declared as local variables in the function. These are not the arrays you initialized.
You need to pass in the arrays you initialized as function arguments.
no , those are the values that i use to initialize my vectors .
i take each value from h1[1000] ... and each vector will be an initial value for h_1 and h_4 ...and each value from S[1000] will be an initial value for *S_1 and *S_4 .
that's why i initialized that way .
- #include <stdio.h>
-
#include <stdlib.h>
-
#include <string.h>
-
#include <math.h>
-
#include "nrutil.h"
-
#include "random_poisson.h"
-
#include "random_normal.h"
-
#define max(x1,x2) ((x1) > (x2))? (x1):(x2)
-
-
double func_nllse(double *p){
-
FILE *out ;
-
extern double *S , *K_nou , *rate , *call_price_market , *h1 , *T1 ;
-
extern double *S1 , *S4, *h_1 , *h_4 ;
-
extern double beta_0,beta_1,beta_2,c_lat,delta ,mu_1,xi,lambda,gamma_1,bro,a ,d;
-
extern double *Call , *Put ;
-
extern double **payoff_call1,**payoff_put1,**payoff_call4,**payoff_put4,
-
*sum_payoffs_call1,*sum_payoffs_put1,*sum_payoffs_call4,*sum_payoffs_put4;
-
extern double r , dt , *t , T, **v, **y, **z ;
-
double k, gamma ,nllse=0 ;
-
int i , j ,l, marime_k ;
-
extern int R ;
-
-
k = p[1] ;
-
gamma = p[2] ;
-
-
for(int l=0;l<=marime_k;l++)
-
{
-
h_1[1]=h1[l] ;
-
printf("h_1=%.1f\n", h_1[1]);
-
h_4[1]=h1[l] ;
-
S1[1]=S[l];
-
printf("S=%.1f\n", S[1]);
-
S4[1]=S[l];
-
printf("S=%.1f\n", S[1]);
-
r=rate[l];
-
printf(" rate=%.1f\n", rate[1]);
-
T=T1[l];
-
printf("T1=%.1f\n", T1[1]);
-
dt =T1[l]/R ;
-
for(i=1;i<=1000; i++)
-
{
-
for(j=2;j<=R ; j++)
-
{
-
v[i][j]= random_normal11(0.0, 1.0);
-
y[i][j]= random_normal12(0.0, 1.0);
-
z[i][j]=random_poisson(lambda*k*dt) ;
-
//printf(" z=%.1f\n",z[i][j]);
-
t[j] = t[j-1] + T/R ;
-
h_1[j]=h_1[j-1]+(beta_0+h_1[j-1]*a)*dt +beta_2*d*h_1[j-1]*(gamma_1*y[i][j]+mu_1+bro*gamma*gamma_1)*(gamma_1*y[i][j]+mu_1+bro*gamma*gamma_1)*z[i][j] ;
-
S1[j] = S1[j-1]*exp((r-(h_1[j]/2)+lambda*k*(1-exp(sqrt(h_1[j])*(mu_1+bro*gamma*gamma_1)+(1/2)*h_1[j]*gamma_1*gamma_1)))*dt
-
+sqrt(h_1[j])*sqrt(dt)*v[i][j]+(gamma_1*y[i][j]+mu_1+bro*gamma*gamma_1)*sqrt(h_1[j])*z[i][j]);
-
h_4[j]=h_4[j-1]+(beta_0+h_4[j-1]*a)*dt +beta_2*d*h_4[j-1]*(gamma_1*(y[i][j])+mu_1+bro*gamma*gamma_1)*(gamma_1*(y[i][j])+mu_1+bro*gamma*gamma_1)*(-z[i][j]) ;
-
S4[j] = S4[j-1]*exp((r-(h_4[j]/2)+lambda*k*(1-exp(sqrt(h_4[j])*(mu_1+bro*gamma*gamma_1)+(1/2)*h_4[j]*gamma_1*gamma_1)))*dt
-
+sqrt(h_4[j])*sqrt(dt)*(v[i][j])+(gamma_1*(y[i][j])+mu_1+bro*gamma*gamma_1)*sqrt(h_4[j])*(-z[i][j]));
-
}
-
for(int l=1; l<marime_k; l++)
-
{
-
payoff_call1[i][l] =max(0.0, S1[R]-K_nou[l]);
-
payoff_put1[i][l] =max(0.0, K_nou[l]-S1[R]);
-
payoff_call4[i][l] =max(0.0, S4[R]-K_nou[l]);
-
payoff_put4[i][l] =max(0.0, K_nou[l]-S4[R]);
-
}
-
for(int l=1; l<marime_k; l++)
-
{
-
sum_payoffs_call1[l] += payoff_call1[i][l] ;
-
sum_payoffs_put1[l] += payoff_put1[i][l] ;
-
sum_payoffs_call4[l] += payoff_call4[i][l] ;
-
sum_payoffs_put4[l] += payoff_put4[i][l] ;
-
}
-
}
-
}
-
for(int l=1; l<marime_k; l++)
-
{
-
Call[l] = exp(-rate[l]*T1[l])*(sum_payoffs_call1[l]+sum_payoffs_call4[l])/2000.0 ;
-
nllse += ( Call[l]-call_price_market[l])*(Call[l]-call_price_market[l] ) ;
-
}
-
return (-nllse) ;
-
}
i have a break point here: - for(int l=1; l<marime_k; l++)
-
{
-
payoff_call1[i][l] =max(0.0, S1[R]-K_nou[l]);
-
payoff_put1[i][l] =max(0.0, K_nou[l]-S1[R]);
-
payoff_call4[i][l] =max(0.0, S4[R]-K_nou[l]);
-
payoff_put4[i][l] =max(0.0, K_nou[l]-S4[R]);
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Martyn Lawson |
last post by:
Hi,
I am currently working as an Analyst on a .NET Web Project using ASP.NET and
C#.NET.
I have a couple of, at least what should be, quick questions:
1. My understanding of UML says that...
|
by: lkrubner |
last post by:
I'm offering users the ability to type weblog posts into a form and
post them. They type the text into a TEXTAREA which is on a form. The
form, when submitted, hits a PHP script. Before it is...
|
by: Bernard |
last post by:
Hi All,
I am not sure if I should be asking this question on clc or clc++. Let me try on
both. I hope that this is not too trivial for the brilliant minds over here.
I know that OOP questions...
|
by: Frank J. Reashore |
last post by:
Hello Everyone,
I am implementing a simple interface in C# using Visual Studio .net and was
quite surprised to discover that the C# compiler does NOT complain if a
method on the interface is not...
|
by: Colin McGuire |
last post by:
Hi all, when I write the class below
Private Class employee
End Class
and then add the line "Implements IVF" which is an interface I have
written, the IDE modifies my code to display
|
by: LBS |
last post by:
Hello guys
I'm trying to implement a wrapper class, and I'm havinf difficulty
implementing the transaction.
I have several classes. The wrapper WrapDbCommand, WrapConnection..etc, and
the...
|
by: Pete |
last post by:
I'm doing exercise 8-2 from "Accelerated C++" where we're supposed to
implement library algorithms, trying to minimize the number of iterator
operations. I have two questions so far.
First,...
|
by: raylopez99 |
last post by:
What's the best way of implementing a multi-node tree in C++? What I'm
trying to do is traverse a tree of possible chess moves given an intial
position (at the root of the tree). Since every...
|
by: Tristan Wibberley |
last post by:
Hi
I've got implementing overloaded operator new and delete pretty much
down. Just got to meet the alignment requirements of the class on which
the operator is overloaded.
But how does one...
|
by: CJ |
last post by:
We were discussing implementing malloc(), in particular the following
situation.
Suppose the user requests 1Mb of memory. Unfortunately, we only have
512Kb available. In this situation, most...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |