Skip to content

Instantly share code, notes, and snippets.

@mmizutani
Created October 5, 2013 03:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmizutani/6836238 to your computer and use it in GitHub Desktop.
Save mmizutani/6836238 to your computer and use it in GitHub Desktop.
DemoVasicekDynamics
void DemoVasicekDynamics()
{
Real b=0.1; //long term rate
Real lambda = 0.0; //risk parameter
Real r0=0.05; //spot interest rate
Real a=0.1; //speed of mean reversion
Real sigma=0.01; //vol. parameter
std::vector<std::vector<double>> xAxisVecs,yAxisVecs;
std::vector<std::string> curveTitleVec;
for (double a=0.02;a<=0.15;a=a+0.02) //move variable a
{
std::vector<double> xAxis;
std::vector<double> yAxis;
boost::shared_ptr<Vasicek> modelVaiscek(new Vasicek(r0,a,b,sigma,lambda));
for (double endTime=0;endTime<=20;endTime=endTime+0.5) //move time
{
double x=endTime;
double bondPrice1=modelVaiscek->discountBond(0,endTime,r0);
double dx=0.01;
double bondPrice2=modelVaiscek->discountBond(0,endTime+dx,r0);
double y=(std::log(bondPrice1)-std::log(bondPrice2))/dx;
std::cout << "x=" << x << " y=" << y << std::endl;
xAxis.push_back(x);
yAxis.push_back(y);
}
std::stringstream oss;
oss << a ;
std::string tmp = oss.str();
std::string legend="a="+tmp;
xAxisVecs.push_back(xAxis);
yAxisVecs.push_back(yAxis);
curveTitleVec.push_back(legend);
}
PlotGraph(xAxisVecs,yAxisVecs,curveTitleVec);
}
int main(int, char* []) {
try {
boost::timer timer;
std::cout << std::endl;
DemoVasicekDynamics();
return 0;
} catch (std::exception& e) {
std::cout << e.what() << std::endl;
return 1;
} catch (...) {
std::cout << "unknown error" << std::endl;
return 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment