Sorry for a duplicate post. The other post had gotten messy and since I was not allowed to delete it, I am starting a new post.

Hi, here are the errors I am getting when i compile on cygwin. It is weird that the code compiles and runs perfectly on Visual Studio.

$ g++ -o mainUnix.out mainUnix.cpp
mainUnix.cpp: In function `int main()':
mainUnix.cpp:47: error: expected primary-expression before numeric constant
mainUnix.cpp:47: error: expected `;' before numeric constant
mainUnix.cpp:49: error: invalid initialization of non-const reference of type 'std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >&' from a temporary of type 'int'
mainUnix.cpp:29: error: in passing argument 1 of `void loadRegressionMatrices(std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >&, std::vector<double, std::allocator<double> >&, std::vector<OptionParam, std::allocator<OptionParam> >&)'
mainUnix.cpp:53: error: request for member `size' in `64', which is of non-class type `int'
mainUnix.cpp:55: error: invalid types `int[int]' for array subscript
mainUnix.cpp:55: error: invalid types `int[int]' for array subscript
mainUnix.cpp:55: error: invalid types `int[int]' for array subscript
mainUnix.cpp:55: error: invalid types `int[int]' for array subscript
mainUnix.cpp:55: error: invalid types `int[int]' for array subscript
mainUnix.cpp:60: error: invalid initialization of non-const reference of type 'std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >&' from a temporary of type 'int'
mainUnix.cpp:30: error: in passing argument 1 of `void transpose(std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >&, std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >&)'
mainUnix.cpp:63: error: invalid initialization of non-const reference of type 'std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >&' from a temporary of type 'int'
mainUnix.cpp:31: error: in passing argument 2 of `void computeProduct(std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >&, std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >&, std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >&)'

Here is the relevant portion of Code:

#include <iostream>
#include <string>
#include <fstream>
#include <sstream> //because i use istringstream
#include <vector>
#include <valarray> // because we use exp() in the function N()
#include <math.h> // because we use fabs() in Bisect()
#define TINY 1.0e-20

using namespace std;
enum Type{put=0, call=1};
struct OptionParam{
double S;
int K;
double r;
double T;
double price;
double sigImpl;
Type putOrCall;
};
double BS_Price(double S,double K,double r,double T,double sig, char * optionType);
double N(double x);
double BS_Bisect(char* optionType,double S,double K,double r,double T,double a,double b,double realC);
double computeAvg(vector<double>& K, vector<double>& T, vector<double>& sig, int k, int t, int s);
void loadOLSmatrices(vector< vector<double> >& M, vector<double>& b, vector<OptionParam>& op);
void loadParametersFromFile(vector<OptionParam>& op, char* file, char* type);
void loadParametersFromVector(vector<OptionParam>& op,vector<double>& K,vector<double>& K_2,vector<double>& KT, vector<double>& T, vector<double>& sig);
void computeImpliedVols(vector<OptionParam>& op);
void loadRegressionMatrices(vector<vector<double> >& X,vector<double>& b, vector<OptionParam>& op);
void transpose(vector<vector<double> > & a,vector<vector<double> > & at);
void computeProduct(vector<vector<double> >&x,vector<vector<double> >&y,vector<vector<double> >& prod);
void computeProduct2(vector<vector<double> >&x,vector<double> &y,vector<double>& prod);
void ludcmp(vector<vector<double> >&a, int n, vector<int>& indx, double *d);
void lubksb(vector<vector<double> >&a, int n, vector<int>& indx, vector<double>& b);

int main()
{
vector<vector<double> > A ( 5, vector<double> ( 5 ) );
vector<double> b(5);
vector<OptionParam> op;
loadParametersFromFile(op,"Data.csv","call");

cout << op.size()<<endl;
printf("%lf,%d\n",op[0].price,op[0].K);

computeImpliedVols(op);
vector<vector<double> > _X ( (int)op.size(), vector<double> ( 5 ) );
vector<double> _b((int)op.size() );
loadRegressionMatrices(_X,_b,op);

ofstream csvRegMatrix;
csvRegMatrix.open("RegMatrix.csv");
for (int i=0; i<(int)_X.size(); i++)
{
csvRegMatrix << _X[i][0] << ","<< _X[i][1] << ","<< _X[i][2] << ","<< _X[i][3] << ","<< _X[i][4]<<","<<_b[i] <<endl;
}
csvRegMatrix.close();

vector<vector<double> > _Xt ( 5, vector<double> ( (int)op.size() ) );
transpose(_X,_Xt);

vector<vector<double> > _XtX ( 5, vector<double> ( 5 ) );
computeProduct(_Xt,_X,_XtX);

ofstream csvXtXMatrix;
csvXtXMatrix.open("XtXMatrix.csv");
for (int i=0; i<(int)_XtX.size(); i++)
{
csvXtXMatrix << _XtX[i][0] << ","<< _XtX[i][1] << ","<< _XtX[i][2] << ","<< _XtX[i][3] << ","<< _XtX[i][4] <<endl;
}
csvXtXMatrix.close();

vector<double > _Xt_b ( 5);//, vector<double> ( (int)op.size() ) );
computeProduct2(_Xt,_b,_Xt_b);

vector<int> indx(5);
double d ;
vector<double> beta(5);
int i,j;
vector<vector<double> > _XtXinv ( 5, vector<double> ( 5 ) );
vector<double> col (5);
ludcmp(_XtX,5,indx,&d);
for( j=0;j<5;j++){
for(i=0;i<5;i++)	col[i]=0.0;
col[j]=1.0;
lubksb(_XtX,5,indx,col);
for(i=0;i<5;i++) _XtXinv[i][j]=col[i];
}
computeProduct2(_XtXinv,_Xt_b,beta);
cout<<beta[0]<<","<<beta[4]<<endl;

}

I was wondering is this legal in unix:

vector<vector<double> > _Xt ( 5, vector<double> ( (int)op.size() ) );

The other post had gotten messy and since I was not allowed to delete it, I am starting a new post.

Stop making more posts! I just flagged that other one for cleanup!

And yeah there is a 30 minute edit window, after that normal users cant edit threads.

ok, i solved my own problem. for the sake of the group i wanted to let people know what the "error" was. it is super weird. but when i changed the vector name from "_X" to "X" all the errors vanished!!

I would love to hear why is it so that "_X" is not allowed.

Stop making more posts! I just flagged that other one for cleanup!

And yeah there is a 30 minute edit window, after that normal users cant edit threads.

Sorry about that. I didnt know. newbie here. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.