# include <boost/python.hpp>
# include <iostream>
# include <math.h>
# include <vector>
# include <D:\Users\212334548\Personal\QuantLib-1.2.1\ql\quantlib.hpp>
# include <ctime>
# include <stdlib.h>
using namespace QuantLib;
using namespace boost::python;
class interpolation
{
public:
interpolation()
{
};
~interpolation()
{
};
std::vector<std::vector<double>> linearonrates(double** data,int daycount,char* holiday,char* compounding,int size)
{
int n = size;
std :: vector <double > xVec (n) , yVec (n);
for (int i=0;i<n;i++)
{
xVec[i] = data[i][0];
yVec[i] = data[i][1];
}
LinearInterpolation linInt ( xVec . begin (), xVec . end (), yVec . begin ());
std::vector<std::vector<double>> vec;
for(int i = xVec[0] ; i<=xVec[n-1] ; i+=1000)
{
//std :: cout << linInt (i) << std :: endl ;
std::vector<double> row;
row.push_back(i);
row.push_back(linInt(i));
vec.push_back(row);
}
return vec;
};
std::vector<std::vector<double>> linearonlogrates(double** data,int daycount,char* holiday,char* compounding,int size)
{
int n = size;
std :: vector <double > xVec (n) , yVec (n);
for (int i=0;i<n;i++)
{
xVec[i] = data[i][0];
yVec[i] = std::log(data[i][1]);
}
LinearInterpolation linInt ( xVec . begin (), xVec . end (), yVec . begin ());
std::vector<std::vector<double>> vec;
for(int i = xVec[0] ; i<=xVec[n-1] ; i+=1000)
{
//std :: cout << linInt (i) << std :: endl ;
std::vector<double> row;
row.push_back(i);
row.push_back(std::exp(linInt(i)));
vec.push_back(row);
}
return vec;
};
std::vector<std::vector<double>> linearondiscountfactors(double** data,int daycount,char* holiday,char* compounding)
{
std::vector<std::vector<double>> vec;
//code here
return vec;
};
std::vector<std::vector<double>> linearonlogdiscountfactors(double** data,int daycount,char* holiday,char* compounding)
{
std::vector<std::vector<double>> vec;
//code here
return vec;
};
std::vector<std::vector<double>> cubiconrates(double** data,int daycount,char* holiday,char* compounding)
{
std::vector<std::vector<double>> vec;
//code here
return vec;
};
std::vector<std::vector<double>> cubiconlogrates(double** data,int daycount,char* holiday,char* compounding)
{
std::vector<std::vector<double>> vec;
//code here
return vec;
};
};
int main()
{
//code here ...
///*-------------------------------------------------------------------------------------------------
double **data;//= {{0,3.4},{2000,4.5},{4000,6.0},{8000,7.8},{16000,9.6}};
data = new double*[5];
for(int i=0;i<5;i++)
{
data[i] = new double[2];
}
data[0][0] = 0.0;
data[0][1] = 3.4;
data[1][0] = 2000.0;
data[1][1] = 4.5;
data[2][0] = 4000.0;
data[2][1] = 6.0;
data[3][0] = 8000.0;
data[3][1] = 7.8;
data[4][0] = 16000.0;
data[4][1] = 9.6;
int daycount = 360;
char* holiday = "None";
char* compounding = "Continuous";
interpolation *inter = new interpolation();
std::vector<std::vector<double>> vec = inter->linearonlogrates(data,daycount,holiday,compounding,5);
//std::copy(vec.begin(), vec.end(), std::ostream_iterator<double>(std::cout, "\n"));
//std::cout <<"data : "<< vec;
for(int i=0;i<vec.size();i++)
{
std::cout <<vec[i][0]<< "\t" << vec[i][1]<<"\n";
}
//-------------------------------------------------------------------------------------------------*/
double tmp;
std::cin >> tmp;
return 0;
}
BOOST_PYTHON_MODULE(InterP)
{
class_<interpolation>("interpolation")
.def("linearonrates", &interpolation::linearonrates)
;
}
这是代码,我在其中尝试使用 boot-python 来制作包装器。如果我删除最后六行,一切似乎都正常。但是在包含这些行时,会生成如下链接错误:
>interpolation.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) struct boost::python::converter::registration const & __cdecl boost::python::converter::registry::lookup(struct boost::python::type_info)" (__imp_?lookup@registry@converter@python@boost@@YAABUregistration@234@Utype_info@34@@Z) referenced in function "struct boost::python::converter::registration const & __cdecl boost::python::converter::detail::registry_lookup2<class interpolation const volatile >(class interpolation const volatile & (__cdecl*)(void))" (??$registry_lookup2@$$CDVinterpolation@@@detail@converter@python@boost@@YAABUregistration@123@P6AADVinterpolation@@XZ@Z)
1>d:\users\212334548\documents\visual studio 2010\Projects\wrap_interpolation\Debug\wrap_interpolation.exe : fatal error LNK1120: 32 unresolved externals