Trying multi-threaded Heston calibration

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Trying multi-threaded Heston calibration

Ghorpadkar, Suhas

I am trying to use parallel_for_each loop from Microsoft PPL library to speed up Heston calibration. We are using Differential Evolution to optimize time dependent Heston parameters, so I thought the best place to parallelize would be in the HestonBootstrapFunction. I created a new BootstrapFunction class that inherits from CostFunction and overrode its values() method as below. For each date in vol surface, I am expecting to pass in as many CalibrationHelpers as there are strikes and I would like to calculate the calibration errors in parallel for that date. I compiled the code with /GR option to indicate RTTI support. I am getting std::__non_rtti_object exception that I am struggling with. Any help is appreciated.

 

Here is my MTHestonBootstrapFunction.h :

 

#ifndef MT_quantlib_heston_option_helper_hpp

#define MT_quantlib_heston_option_helper_hpp

 

#include <future>

#include <thread>

#include <ql/models/calibrationhelper.hpp>

#include <ql/models/equity/hestonmodelhelper.hpp>

#include <ql/models/equity/piecewisetimedependenthestonmodel.hpp>

#include <ql/instruments/vanillaoption.hpp>

#include <ql/math/optimization/costfunction.hpp>

#include <ppl.h>

#include <concrtrm.h>

 

using namespace std;

using namespace Concurrency;

 

namespace QuantLib {

class MTHestonBootstrapFunction : public CostFunction {

       public:

              MTHestonBootstrapFunction(

                     boost::shared_ptr<PiecewiseTimeDependentHestonModel> model,

                     Size index,

                     std::vector<boost::shared_ptr<CalibrationHelper>> helpers): model_(model), index_(index), helpers_(helpers) {}

             

              Real value(const Array& x) const {

                     Array tmp = values(x);

                     QuantLib::Real v = 0.0;

                     for(Size i=0; i<tmp.size(); i++)

                           v += tmp[i] * tmp[i];

                           //v = std::max(v, std::abs(tmp[i]));

                     return v;

              }

 

              Disposable<Array> values(const Array& x) const{

                     Real theta, kappa, sigma, rho;

                     theta = x[0]; kappa = x[1];

                     sigma = x[2]; rho = x[3];

                     // V0 is set on the first maturity and kept unchanged

                     if(index_ == 0)

                           model_->setV0(x[4]);

                     // kappa is not negociable (faster resolution)

                     // model_->setKappa(index_, kappa);

                     model_->setTheta(index_, theta);

                     model_->setSigma(index_, sigma);

                     model_->setRho(index_, rho);

 

                     Array v(helpers_.size());

 

                     combinable<std::vector<Real> > localErrors;

                     parallel_for_each(helpers_.begin(),  helpers_.end(), [&localErrors] (boost::shared_ptr<CalibrationHelper> helper) {

                           Real error = helper->calibrationError();

                           localErrors.local().push_back(error);

                     });

                    

                     localErrors.combine_each([&](std::vector<Real> & local){

                           for (int k = 0; k < local.size(); ++k){

                                  v[k] = local.at(k);

                           }

                     });

 

                     return v;

              }

       private:

              boost::shared_ptr<PiecewiseTimeDependentHestonModel> model_;

              Size index_;

              std::vector<boost::shared_ptr<CalibrationHelper>> helpers_;

       };

}

 

#endif

 

Thanks a lot,

 

Suhas

 

 

............................................................................

For further important information about AllianceBernstein please click here
http://www.abglobal.com/disclaimer/email/disclaimer.html


------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity
planning reports. http://sdm.link/zohodev2dev
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users