⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 termstru_forward_interpolated.cc

📁 Financial Recipes
💻 CC
字号:
#include <vector>using namespace std;#include "fin_recipes.h" double term_structure_forward_linearly_interpolated(double time, 						    const vector<double>& obs_times, 						    const vector<double>& obs_forwards) {// assume observations in increasing time to maturity order.    int no_obs = obs_times.size();    if (no_obs<1) return 0;    double t_min = obs_times[0];    if (time <= t_min) return obs_forwards[0];  // earlier than lowest obs.    double t_max = obs_times[no_obs-1];      if (time >= t_max) return obs_forwards[no_obs-1]; // later than latest obs    int t=1;  // find which two observations we are between    while ( (t<no_obs) && (time>obs_times[t])) 	{ ++t; };     double lambda = (obs_times[t]-time)/(obs_times[t]-obs_times[t-1]);    // by ordering assumption, time is  between t-1,t    double r = obs_forwards[t-1] * lambda + obs_forwards[t] * (1.0-lambda);     return r;};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -