Exception running EuropeanOption example (maybe boost problem?)

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Exception running EuropeanOption example (maybe boost problem?)

Giorgio Pazmandi

Hi all, I get an exception running the EuropeanOption example while running the last calculation (MC Longstaff – Achwartz) (ql version 0.9.7, boost version 1.37)

 

The exception occurs in the LinearLeastSquaresRegression class (used for the calibration of the LS-pathpricer). A matrix nxm (n=5097, m=4) is created and then std::transform is called. n is the number of (x,y) elements to match and v is the vector with the functions for which we want to find the best coefficients. For i=0 the method std::transform evals the function for each of the 5097 x’s but then when it wants to return it tries to destroy some function and inside the destructor I have the exception.

 

Code:

    template <class ArgumentType> inline

    LinearLeastSquaresRegression<ArgumentType>::LinearLeastSquaresRegression(

        const std::vector<ArgumentType> & x,

        const std::vector<Real> &         y,

        const std::vector<boost::function1<Real, ArgumentType> > & v)

    : a_  (v.size(), 0.0),

      err_(v.size(), 0.0) {

     

      […]

 

        Matrix A(n, m);

        for (i=0; i<m; ++i)

            std::transform(x.begin(), x.end(), A.column_begin(i), v[i]); // ß exception here

 

And inside transform():

 

template<class _InIt,

      class _OutIt,

      class _Fn1> inline

      _OutIt transform(_InIt _First, _InIt _Last, _OutIt _Dest, _Fn1 _Func)

      {     // transform [_First, _Last) with _Func

      for (; _First != _Last; ++_First, ++_Dest)

            *_Dest = _Func(*_First);

      return (_Dest); // ß exception here (for loop has finished)

 

      }

 

 

Here is the call stack.

msvcr71d.dll!strcmp()  Line 123

msvcr71d.dll!type_info::operator==(const type_info & rhs={...})  + 0x1a

EquityOption-vc71-mt-gd.exe!boost::detail::function::functor_manager<QuantLib::`anonymous namespace'::MonomialFct,std::allocator<boost::function_base> >::manager(const boost::detail::function::function_buffer & in_buffer={...}, boost::detail::function::function_buffer & out_buffer={...}, boost::detail::function::functor_manager_operation_type op=check_functor_type_tag, boost::mpl::bool_<1> __formal={...})  Line 292 + 0x10

EquityOption-vc71-mt-gd.exe!boost::detail::function::functor_manager<QuantLib::`anonymous namespace'::MonomialFct,std::allocator<boost::function_base> >::manager(const boost::detail::function::function_buffer & in_buffer={...}, boost::detail::function::function_buffer & out_buffer={...}, boost::detail::function::functor_manager_operation_type op=check_functor_type_tag, boost::detail::function::function_obj_tag __formal={...})  Line 368 + 0x20

EquityOption-vc71-mt-gd.exe!boost::detail::function::functor_manager<QuantLib::`anonymous namespace'::MonomialFct,std::allocator<boost::function_base> >::manage(const boost::detail::function::function_buffer & in_buffer={...}, boost::detail::function::function_buffer & out_buffer={...}, boost::detail::function::functor_manager_operation_type op=check_functor_type_tag)  Line 385 + 0x20

EquityOption-vc71-mt-gd.exe!boost::detail::function::basic_vtable1<double,double>::clear(boost::detail::function::function_buffer & functor={...})  Line 503 + 0x11

EquityOption-vc71-mt-gd.exe!boost::function1<double,double>::clear()  Line 851

EquityOption-vc71-mt-gd.exe!boost::function1<double,double>::~function1<double,double>()  Line 750 + 0x2b

EquityOption-vc71-mt-gd.exe!std::transform<std::vector<double,std::allocator<double> >::const_iterator,QuantLib::step_iterator<double *>,boost::function1<double,double> >(std::vector<double,std::allocator<double> >::const_iterator _First={...}, std::vector<double,std::allocator<double> >::const_iterator _Last={...}, QuantLib::step_iterator<double *> _Dest={...}, boost::function1<double,double> _Func={...})  Line 389 + 0x1d

EquityOption-vc71-mt-gd.exe!QuantLib::LinearLeastSquaresRegression<double>::LinearLeastSquaresRegression<double>(const std::vector<double,std::allocator<double> > & x={...}, const std::vector<double,std::allocator<double> > & y={...}, const std::vector<boost::function1<double,double>,std::allocator<boost::function1<double,double> > > & v={...})  Line 77 + 0x8a

EquityOption-vc71-mt-gd.exe!QuantLib::LongstaffSchwartzPathPricer<QuantLib::Path>::calibrate()  Line 152 + 0x1d

EquityOption-vc71-mt-gd.exe!QuantLib::MCLongstaffSchwartzEngine<QuantLib::OneAssetOption::engine,QuantLib::SingleVariate,QuantLib::GenericPseudoRandom<QuantLib::MersenneTwisterUniformRng,QuantLib::InverseCumulativeNormal>,QuantLib::GenericRiskStatistics<QuantLib::GenericGaussianStatistics<QuantLib::GeneralStatistics> > >::calculate()  Line 150 + 0x27

EquityOption-vc71-mt-gd.exe!QuantLib::Instrument::performCalculations()  Line 157 + 0x24

EquityOption-vc71-mt-gd.exe!QuantLib::LazyObject::calculate()  Line 140 + 0xd

EquityOption-vc71-mt-gd.exe!QuantLib::Instrument::calculate()  Line 145

EquityOption-vc71-mt-gd.exe!QuantLib::Instrument::NPV()  Line 173 + 0xc

EquityOption-vc71-mt-gd.exe!main(int __formal=1, int __formal=1)  Line 353 + 0xb

 

Did somebody experience the same problem? Is the boost version too old? Do you have a workaround for this?

 

Thank you in advance

 

Giorgio Pazmandi


------------------------------------------------------------------------------

_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Exception running EuropeanOption example (maybe boost problem?)

Bojan Nikolic


This does look like to be a bug in boost on your platform/compiler
combination. The std::transform takes a copy of the function (i.e.,
fourth) argument and boost seems to trip up when it is time to destroy
it.

I would try expanding out the transform code in the leastsquares
code. Something as simple as below should do I think as a first check.

Best,
Bojan

--- a/ql/math/linearleastsquaresregression.hpp
+++ b/ql/math/linearleastsquaresregression.hpp
@@ -106,7 +106,11 @@
 
         Matrix A(n, m);
         for (i=0; i<m; ++i)
-            std::transform(x.begin(), x.end(), A.column_begin(i), v[i]);
+            for(size_t j=0; j<x.size(); ++j)
+            {
+                A[j][i]=v[i](x[j]);
+            }
+
 
         const SVD svd(A);
         const Matrix& V = svd.V();


--
Bojan Nikolic          ||          http://www.bnikolic.co.uk

------------------------------------------------------------------------------
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Exception running EuropeanOption example (maybe boost problem?)

Giorgio Pazmandi
Hi Bojan, thank you for your tip, without calling std::transform everything
works correctly. I have also seen that the original code works fine with
boost 1.34, so I can either use your patch or the older boost installation.

Thank you again for your help

Giorgio Pazmandi


> -----Original Message-----
> From: Bojan Nikolic [mailto:[hidden email]]
> Sent: giovedì, 26. marzo 2009 16:57
> To: Giorgio Pazmandi
> Cc: [hidden email]
> Subject: Re: [Quantlib-users] Exception running EuropeanOption example
> (maybe boost problem?)
>
>
>
> This does look like to be a bug in boost on your platform/compiler
> combination. The std::transform takes a copy of the function (i.e.,
> fourth) argument and boost seems to trip up when it is time to destroy
> it.
>
> I would try expanding out the transform code in the leastsquares
> code. Something as simple as below should do I think as a first check.
>
> Best,
> Bojan
>
> --- a/ql/math/linearleastsquaresregression.hpp
> +++ b/ql/math/linearleastsquaresregression.hpp
> @@ -106,7 +106,11 @@
>
>          Matrix A(n, m);
>          for (i=0; i<m; ++i)
> -            std::transform(x.begin(), x.end(), A.column_begin(i),
> v[i]);
> +            for(size_t j=0; j<x.size(); ++j)
> +            {
> +                A[j][i]=v[i](x[j]);
> +            }
> +
>
>          const SVD svd(A);
>          const Matrix& V = svd.V();
>
>
> --
> Bojan Nikolic          ||          http://www.bnikolic.co.uk
>
> -----------------------------------------------------------------------
> -------
> _______________________________________________
> QuantLib-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/quantlib-users


------------------------------------------------------------------------------
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Which Boost install?

Tom Picking
I want to do some pricing of equity derivative products in Python 2.5  
on Vista and figured QuantLib looks like an interesting project to  
work with.

At the moment I am just trying to get all the dependencies installed,  
but I'm not sure which Boost installation I need: multi-thread, single-
thread, static, DLL etc. Please could someone let me know.

Thanks
Tom


------------------------------------------------------------------------------
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Which Boost install?

Bojan Nikolic

Tom Picking <[hidden email]> writes:

> At the moment I am just trying to get all the dependencies installed,  
> but I'm not sure which Boost installation I need: multi-thread, single-
> thread, static, DLL etc. Please could someone let me know.

The majority of boost libraries are header-only libraries, i.e., they
have no compiled code. I believe QuantLib only uses this subset, so in
fact it shouldn't matter which variant of Boost you install since the
compiled parts will not be used.

In general I would suggest installing at least the single-threaded
release-mode DLL. On unix you can install multiple variants which is
the best solution, but I'm not sure if that is easy to achieve on
Windows.

Best,
Bojan

--
Bojan Nikolic          ||          http://www.bnikolic.co.uk

------------------------------------------------------------------------------
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Which Boost install?

Luigi Ballabio
On Mon, 2009-04-06 at 16:00 +0100, Bojan Nikolic wrote:

> Tom Picking <[hidden email]> writes:
>
> > At the moment I am just trying to get all the dependencies installed,  
> > but I'm not sure which Boost installation I need: multi-thread, single-
> > thread, static, DLL etc. Please could someone let me know.
>
> The majority of boost libraries are header-only libraries, i.e., they
> have no compiled code. I believe QuantLib only uses this subset, so in
> fact it shouldn't matter which variant of Boost you install since the
> compiled parts will not be used.

That's correct as long as you don't try and compile the test suite.
You'll require Boost libraries for the latter.

I'm assuming that you'll use VC7, since that's what is commonly used to
compile Python extensions. I'm also assuming that you're using the
latest QuantLib (0.9.7.) Correct me if that's not the case.
In VC7, you'll have to compile QuantLib in "Release" configuration and
install the "Multithread" flavor of Boost; in both cases, that's the
configuration that will give you libraries with a -mt- filename (not
-mt-s- or -mt-whatever.)

Hope this helps,
        Luigi


--

Never mistake motion for action.
-- Ernest Hemingway



------------------------------------------------------------------------------
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users