Hello everyone.......I'm trying to make an interpolation using an excel sheet that contains yrs and rates. I'm finding it pretty difficult to input my csv file so that it makes calculations at each row. One of my problems is that the top row contains values for yrs which is part of my function. I want to calculate prices at each row (based on the yr value) and output result at each row. Anyone???


insert
Code:
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <time.h>
#include <stdlib.h>
#include <fstream>
#include <string>
#include <vector> // for rand()


using namespace std;


class Bond
{
public:
    double RT;
    double B;  
    double S;  
    vector<double> obs_times;
    vector<double> obs_yields;
    
    double LinearInterpolation(double time)
    {
        if (obs_times.size() < 1)
            return 0;
        double t_min = obs_times[0];
        if (time < t_min)
            return obs_yields[0];
        
        double t_max = obs_times[obs_times.size() - 1];
        if (time >= t_max)
            return obs_yields[obs_times.size() - 1];
        
        int t = 1;
        
        while ((t < obs_times.size()) && (time > obs_times[t])) 
        { 
            ++t;    
        };
        
        double lambda = (obs_times[t] - time) / (obs_times[t] - obs_times[t - 1]);  
        double r = obs_yields[t - 1] * lambda + obs_yields[t] * (1.0 - lambda);
        return r;
    }
};


int main(int argc, char** argv) 
{
    Bond b;
    
   /* double tempdouble;
    string tempfile ;
    
    ifstream inFile;
    inFile.open("Bumped YC2.txt");
  
    while (inFile >>  tempdouble)
    {      
        b.obs_yields.push_back(tempdouble);
    }
    
           
  //this is how far I've gone, just to allocate each rate to a particular time and make sure that the number of years is constant at each loop but the calculation continues to the next line
     
    b.obs_times.push_back(0.25);
    b.obs_times.push_back(0.5);
    b.obs_times.push_back(1);
    b.obs_times.push_back(2);
    b.obs_times.push_back(3);
    b.obs_times.push_back(4);
    b.obs_times.push_back(5);
        
    b.obs_yields.push_back(0.01792);
    b.obs_yields.push_back(0.02015);
    b.obs_yields.push_back(0.02281); 
    b.obs_yields.push_back(0.01551);
    b.obs_yields.push_back(0.01531);
    b.obs_yields.push_back(0.01621);
    b.obs_yields.push_back(0.01765);         
  
    return 0;
}


my data sample

0.5 1 2 3 4 5
0.8085 1.128 0.746 0.8275 1.0133 1.227
0.8085 1.128 0.76 0.866 1.0621 1.272
0.808 1.1269 0.778 0.888 1.0894 1.307
0.804 1.1231 0.788 0.9145 1.1268 1.36
0.804 1.1231 0.798 0.9117 1.1265 1.392
0.804 1.1231 0.797 0.9118 1.1265 1.373
0.801 1.1214 0.759 0.8745 1.079 1.313
0.7995 1.1191 0.745 0.854 1.0546 1.3075
0.7985 1.1188 0.734 0.8426 1.046 1.275
0.7945 1.1143 0.745 0.84 1.0363 1.246
0.788 1.1104 0.721 0.818 1.0098 1.23
0.783 1.1058 0.711 0.812 1.022 1.257