想了3天还是compile不可以
请各位大大分享一下是那里错了,我跟另外2个同学想了一个星期了下面是Binomial.h里的内容
#ifndef BINOMIAL_H
#define BINOMIAL_H
#define SUCCESS 0
#define FAILURE -1
enum CALL_PUT {Call, Put};
enum AMER_EURO {European, American};
#define OPTION_MULTIPLIER(x) ((x) == Call ? 1.0 : -1.0)
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
/*-----------------------------------------------------------------------------
** FUNCTION: CRRBinomialTree.
**
** DESCRIPTION: Calculates the price of an option using the Cox, Ross and Rubinstein
** binomial tree model.
**
** RETURNS: SUCCESS and the premium, otherwise FAILURE.
**
**---------------------------------------------------------------------------*/
int CRRBinomialTree(
CALL_PUT callOrPut, /* (I) put or call flag (use Call or Put) */
AMER_EURO amerOrEuro, /* (I) option type (use European, American) */
double spotPrice, /* (I) spot price of underlying */
double strike, /* (I) strike price of option */
double maturity, /* (I) maturity of option in years */
double vol, /* (I) annual volatility of underlying */
double rate, /* (I) annual continuous compounded discount rate */
int nStep, /* (I) number of steps in tree */
double *value); /* (O) option value */
#endif
这是Binomial.cpp的内容
#include<iostream>
#include"Binomial.h"
#include"cmath"
using namespace std;
int CRRBinomialTree(CALL_PUT callOrPut, AMER_EURO amerOrEuro, double spotPrice, double strike, double maturity, double vol, double rate, int nStep,double *value)
{
double u,d,p,discount;
int i;
u=exp(vol*sqrt(maturity/nStep));d=1/u;p=(exp(rate*maturity/nStep)-d)/(u-d);discount=exp(-rate*maturity/nStep);
if(amerOrEuro==European){
for(i=0;i<=nStep;i++)
value[i]=MAX(OPTION_MULTIPLIER(callOrPut)*(spotPrice*pow(u,nStep-2i)-strike),0);
while(nStep>0){
for(i=0;i<=nStep-1;i++)
value[i]=discount*(p*value[i]+(1-p)*value[i+1]);
nStep--;}
}
else if(amerOrEuro==American){
for(i=0;i<=nStep;i++)
value[i]=MAX(OPTION_MULTIPLIER(callOrPut)*(spotPrice*pow(u,nStep-2i)-strike),0);
while(nStep>0){
for(i=0;i<=nStep-1;i++)
value[i]=MAX(discount*(p*value[i]+(1-p)*value[i+1]),MAX(OPTION_MULTIPLIER(callOrPut)*(spotPrice*pow(u,nStep-2i)-strike),0));
nStep--;}
}
else
return FAILURE;
return SUCCESS;
}
当我compile的时候出现
1>c:\users\zhang fan\desktop\新建文件夹\binomial.cpp(14) : error C2059: syntax error : 'bad suffix on number'
1>c:\users\zhang fan\desktop\新建文件夹\binomial.cpp(14) : error C2146: syntax error : missing ')' before identifier 'i'
1>c:\users\zhang fan\desktop\新建文件夹\binomial.cpp(14) : error C2059: syntax error : 'bad suffix on number'
1>c:\users\zhang fan\desktop\新建文件夹\binomial.cpp(14) : error C2059: syntax error : ')'
1>c:\users\zhang fan\desktop\新建文件夹\binomial.cpp(22) : error C2059: syntax error : 'bad suffix on number'
1>c:\users\zhang fan\desktop\新建文件夹\binomial.cpp(22) : error C2146: syntax error : missing ')' before identifier 'i'
1>c:\users\zhang fan\desktop\新建文件夹\binomial.cpp(22) : error C2059: syntax error : 'bad suffix on number'
1>c:\users\zhang fan\desktop\新建文件夹\binomial.cpp(22) : error C2059: syntax error : ')'
1>c:\users\zhang fan\desktop\新建文件夹\binomial.cpp(25) : error C2059: syntax error : 'bad suffix on number'
1>c:\users\zhang fan\desktop\新建文件夹\binomial.cpp(25) : error C2146: syntax error : missing ')' before identifier 'i'
1>c:\users\zhang fan\desktop\新建文件夹\binomial.cpp(25) : error C2059: syntax error : 'bad suffix on number'
1>c:\users\zhang fan\desktop\新建文件夹\binomial.cpp(25) : error C2059: syntax error : 'bad suffix on number'
1>c:\users\zhang fan\desktop\新建文件夹\binomial.cpp(25) : error C2059: syntax error : 'bad suffix on number'
1>c:\users\zhang fan\desktop\新建文件夹\binomial.cpp(25) : error C2059: syntax error : ')'
根据我的分析,错误是相同的,可是就是不知道是那里错?