QuantLib Library - error C2143: syntax error : missing ';' before '.'

Hi All,

Kindly assist and thank you in advance.

I am trying to you the GeneralLinearLeastSquares class in the QuantLib (signature below) but I get this error:

c:\program files (x86)\microsoft visual studio 10.0\vc\include\algorithm(1043): error C2064: term does not evaluate to a function taking 1 arguments

I suspect it is the parameters that I am passing and/or how I am passing them. See the defition here:

http://quantlib.org/reference/class_quant_lib_1_1_general_linear_least_squares.html

// begin my code
#include "stdafx.h"
#include "boost\lambda\lambda.hpp"
#include <ql\math\generallinearleastsquares.hpp>
#include <vector>
#include <list>

using namespace std;
using namespace QuantLib;


int _tmain(int argc, _TCHAR* argv[])
{


int xCord [] = {10, 20, 30 };
int yCord [] = {10, 20, 30 };
int zCord [] = {10, 20, 30 };

//vector<int> * x, * y, *z;
const vector <int> xVec(xCord,xCord+3);
const vector <int> yVec(yCord,yCord+3);
const vector <int> zVec(zCord,zCord+3);

GeneralLinearLeastSquares t = GeneralLinearLeastSquares(xVec,yVec,zVec);

//t.coefficients();


return 0;
}
//End of my code

GeneralLinearLeastSquares defition)
template<class xContainer , class yContainer , class vContainer >
QuantLib::GeneralLinearLeastSquares::GeneralLinearLeastSquares ( const xContainer & x,
const yContainer & y,
const vContainer & v
) [inline]
Last edited on
Should be:
 
GeneralLinearLeastSquares t(xVec,yVec,zVec);
Thank you kbw, I changed the code to your suggestion but still having the same error.

#include "stdafx.h"
#include "boost\lambda\lambda.hpp"
#include <ql\math\generallinearleastsquares.hpp>
#include <vector>
#include <list>

using namespace std;
using namespace QuantLib;


int _tmain(int argc, _TCHAR* argv[])
{


int xCord [] = {10, 20, 30 };
int yCord [] = {10, 20, 30 };
int zCord [] = {10, 20, 30 };

//vector<int> * x, * y, *z;
const vector <int> xVec(xCord,xCord+3);
const vector <int> yVec(yCord,yCord+3);
const vector <int> zVec(zCord,zCord+3);

GeneralLinearLeastSquares t(xVec,yVec,zVec);

//t.coefficients();


return 0;
}
Getting this error now: error C2143: syntax error : missing ';' before '.'

This is the change I made:

GeneralLinearLeastSquares.GeneralLinearLeastSquares(xVec,yVec,zVec);

I was previously accessing a funiton as if a class.
What is GeneralLinearLeastSquares ? A function? A class? Something else?

Also, please use code tags when posting code, to make it readable:

http://www.cplusplus.com/articles/z13hAqkS/

It's a class. The constructor takes 3 containers as parameters. From the documentation in the link, my suggestion is correct.

There must be something else going on.
OK.

@Gunit2003:

That's not how you invoke a constructor. You don't call a constructor explicitly, like a function. The constructor is invoked automatically when you create an object of that type.

The code kbw showed you is the correct way to create an object using that constructor. You had it right in your second post - so why did you change it?

Last edited on
I compiled this using GCC, it's fine.
1
2
3
4
5
6
7
#include <ql/math/generallinearleastsquares.hpp>
#include <vector>

int main()
{
        QuantLib::GeneralLinearLeastSquares t(std::vector<int>(), std::vector<int>(), std::vector<int>());
}
Last edited on
Try to add dimension to the array and the function fails :( .

1
2
3
4
5
6
7
#include <ql/math/generallinearleastsquares.hpp>
#include <vector>

int main()
{
        QuantLib::GeneralLinearLeastSquares t(std::vector<int>(4), std::vector<int>(4), std::vector<int>(4));
}


I managed to run the code above (kbw's) in visual c++. However, when I give the vectors dimensions, it breaks. Since this function is a matrix multiplication one, the vectors (matrices) have to have certain dimensions. I am trying to solve the following using generalized least squares.

3x + 2y = 7
-6x + 6y = 6

The matrices from the above are 2 x 2 for x and 2 x 1 for y,

3 2
-6 6

and

7
6

The GeneralLinearLeastSquares functions should solve the above for me. Thank you in advance folks.




Last edited on
This fails as well,

Note that the x vector is multidimensional and the y and z are not.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

#include <ql/math/generallinearleastsquares.hpp>
#include <vector>

int _tmain(int argc, _TCHAR* argv[])
{

 vector<vector<int> > xVec (2, vector<int> (2));
 vector <int> yVec (2);
 vector <int> zVec (2);
 
//QuantLib::GeneralLinearLeastSquares t( vector <int> (), vector <int> (), vector <int> ());
QuantLib::GeneralLinearLeastSquares t( xVec , yVec, zVec);

int done;
cin >> done;

//GeneralLinearLeastSquares test(xVec,yVec,std::vector<int>());

//t.coefficients()

return 0;
}
//End of my code
This is the definition of generallinearleastsquares.hpp.

https://github.com/lballabio/quantlib/blob/master/QuantLib/ql/math/generallinearleastsquares.hpp


Also, I have used the transform function that is failing in this simple example and its failing here too.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "stdafx.h"
#include "boost/multi_array.hpp"
#include <cassert>
#include <ql\math\generallinearleastsquares.hpp>
#include <vector>
#include <list>
#include <iostream>
#include "boost\lambda\lambda.hpp"

#define HEIGHT 2
#define WIDTH 2

using namespace std;
using namespace QuantLib;


int _tmain(int argc, _TCHAR* argv[])
{

vector<vector<int> > xVec (2, vector<int> (2));
vector <int> yVec (2);
vector <int> zVec (2);
  
Matrix A (2,2);

  for (int i=0; i<2 ;++i){
	  std::transform(yVec.begin(), yVec.end(), A.column_begin(i), *(zVec.begin())++);
  }


 
//QuantLib::GeneralLinearLeastSquares t( vector<vector<int> > (), vector <int> (), vector <int> ());
//QuantLib::GeneralLinearLeastSquares test(xVec , yVec, zVec);

int done;
cin >> done;


return 0;
}
//End of my code
Last edited on
Topic archived. No new replies allowed.