Created
October 5, 2013 03:13
-
-
Save mmizutani/6836238 to your computer and use it in GitHub Desktop.
DemoVasicekDynamics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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