![]() |
#2
寒风中的细雨2012-11-20 17:08
|

我把我写的.h&.cpp贴出来
类定义头文件

#include <iostream>
using namespace std;
class fund
{
public:
fund(){};
private:
};
class motherfund: public fund
{
public:
motherfund(double netvalue_) : netvalue(netvalue_) {};
private:
double netvalue;
};
class umbrellafund : public fund
{
public:
umbrellafund(double netvalue_,double stockprice_) : netvalue(netvalue_),stockprice(stockprice_) {};
private:
double netvalue;
double stockprice;
};
using namespace std;
class fund
{
public:
fund(){};
private:
};
class motherfund: public fund
{
public:
motherfund(double netvalue_) : netvalue(netvalue_) {};
private:
double netvalue;
};
class umbrellafund : public fund
{
public:
umbrellafund(double netvalue_,double stockprice_) : netvalue(netvalue_),stockprice(stockprice_) {};
private:
double netvalue;
double stockprice;
};
操作函数头文件

#include <iostream>
#include "classfund.h"//为什么我include了这个头文件它识别不到呢???
using namespace std;
double LOFarbitrage(const motherfund& motherfund_,const umbrellafund& umbrellafundA_,const umbrellafund& umbrellafundB_,int shares_)
#include "classfund.h"//为什么我include了这个头文件它识别不到呢???
using namespace std;
double LOFarbitrage(const motherfund& motherfund_,const umbrellafund& umbrellafundA_,const umbrellafund& umbrellafundB_,int shares_)
操作函数具体说明.CPP

#include <iostream>
#include "classfund.h"//为什么我include了这个头文件它识别不到呢???
using namespace std;
double LOFarbitrage(const motherfund& motherfund_,const umbrellafund& umbrellafundA_,const umbrellafund& umbrellafundB_,int shares_)
{double Pr=0.015;
double Rr=0.005;
double Br=0.0005;
double condition1=umbrellafundA_.stockprice+umbrellafundB_.stockprice)*(1-Br)-(2*motherfund_.netvalue*(1+Pr);
//[1] (Ma+Mb)*x*(1-br)> 2x*Nm*(1+Pr):
double conditon2=umbrellafundA_.stockprice+umbrellafundB_.stockprice)*(1-Br)-(2*motherfund_.netvalue*(1+Rr);
//[2] (Ma+Mb)*x*(1-br)< 2x*Nm*(1+Rr):
if (condition1>0)
return contion1*shares_
else if (condition2<0)
return condition2*shares_
else
return 0;
}
#include "classfund.h"//为什么我include了这个头文件它识别不到呢???
using namespace std;
double LOFarbitrage(const motherfund& motherfund_,const umbrellafund& umbrellafundA_,const umbrellafund& umbrellafundB_,int shares_)
{double Pr=0.015;
double Rr=0.005;
double Br=0.0005;
double condition1=umbrellafundA_.stockprice+umbrellafundB_.stockprice)*(1-Br)-(2*motherfund_.netvalue*(1+Pr);
//[1] (Ma+Mb)*x*(1-br)> 2x*Nm*(1+Pr):
double conditon2=umbrellafundA_.stockprice+umbrellafundB_.stockprice)*(1-Br)-(2*motherfund_.netvalue*(1+Rr);
//[2] (Ma+Mb)*x*(1-br)< 2x*Nm*(1+Rr):
if (condition1>0)
return contion1*shares_
else if (condition2<0)
return condition2*shares_
else
return 0;
}
我的主程序

int main()
{double mothernetvalue;//输入需要的五个值,具体需要的输入函数没写
double umbrellavalueA,umbrellapriceA;
double umbrellavalueB,umbrellapriceB;
int theshares;//用多少份来进行套利
cout<<"输入母基金净值"<<endl;
cin>>mothernetvalue;
cout<<"输入子基金A净值"<<endl;
cin>>umbrellavalueA;
cout<<"输入子基金A市价"<<endl;
cin>>umbrellapriceA;
cout<<"输入子基金B净值"<<endl;
cin>>umbrellavalueB;
cout<<"输入子基金B市价"<<endl;
cin>>umbrellapriceB;
cout<<"每次套利多少份"<<endl;
cin>>theshares;
motherfund the_motherfund(mothernetvalue);
umbrellafund umbrellaA(umbrellavalueA,umbrellapriceA);//建立需要的五个变量
umbrellafund umbrellaB(umbrellavalueB,umbrellapriceB);
double thepayoff=LOFarbitrage(the_motherfund,umbrellaA,umbrellaB,theshares)//代入这个函数计算有没有套利,套利出来是多少,为了简便没有的时候设为0
if (thepayoff==0)
cout<<"此时无套利机会"<<endl;
if (thepayoff!=0)
cout<<"此时有套利机会,可以套利"<<thepayoff<<endl;
}