我对 QuantLib 还很陌生,还不知道源的所有细节,但我试图测试几个选项 NPV 的简单多线程计算,并且遇到运行时错误。这是我的测试代码,它是从 QL 中包含的 EquityOpiton 示例扩展而来的。
// options
VanillaOption europeanOption(payoff, europeanExercise);
VanillaOption bermudanOption(payoff, bermudanExercise);
VanillaOption americanOption(payoff, americanExercise);
boost::thread_group worker_threads;
for( int x = 0; x < 3; ++x )
{
     switch (x)
     {
     case 0:
        europeanOption.setPricingEngine(boost::shared_ptr(
           new FDEuropeanEngine(bsmProcess,
                                                100,99)));
        worker_threads.create_thread( boost::bind( &VanillaOption::NPV, &europeanOption ) );
     case 1:
        bermudanOption.setPricingEngine(boost::shared_ptr(
          new FDBermudanEngine(bsmProcess,
                                                100,99)));
        worker_threads.create_thread( boost::bind( &VanillaOption::NPV, &bermudanOption ) );
     case 2:
       americanOption.setPricingEngine(boost::shared_ptr(
         new FDAmericanEngine(bsmProcess,
                                                100,99)));
        worker_threads.create_thread( boost::bind( &VanillaOption::NPV, &americanOption ) );
      default:
        break;
  }
}
worker_threads.join_all();
究竟是什么导致了这些运行时错误,我该如何解决?我猜它与共享指针有关,但我注意到它们在整个 QL 中被大量使用,我不确定是哪一个导致了问题。