量化庫
編譯 QuantLib 範例
我遵循了從這裡http://quantlib.org/install/macosx.shtml安裝 QuantLib for mac 的指導方針,並使用以下命令修復了標誌:
導出 CXXFLAGS = -stdlib=libstdc++
導出 LDFLAGS = -mmacosx-version-min=10.6
但是,當我嘗試按照指南中的說明編譯範例時,出現以下錯誤:
In file included from BermudanSwaption.cpp:22: In file included from /opt/local/include/ql/quantlib.hpp:43: In file included from /opt/local/include/ql/experimental/all.hpp:25: In file included from /opt/local/include/ql/experimental/volatility/all.hpp:21: In file included from /opt/local/include/ql/experimental/volatility/zabr.hpp:31: In file included from /opt/local/include/ql/math/statistics/incrementalstatistics.hpp:35: In file included from /opt/local/include/boost/accumulators/statistics/stats.hpp:14: In file included from /opt/local/include/boost/accumulators/statistics_fwd.hpp:12: /opt/local/include/boost/mpl/print.hpp:50:19: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions] const int m_x = 1 / (sizeof(T) - sizeof(T)); ^ 1 warning generated. Undefined symbols for architecture x86_64: "QuantLib::MultiStepSwap::nextTimeStep(QuantLib::CurveState const&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >&, std::__1::vector<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> >, std::__1::allocator<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> > > >&)", referenced from: vtable for QuantLib::MultiStepSwap in BermudanSwaption-a6bf28.o "QuantLib::ExerciseAdapter::nextTimeStep(QuantLib::CurveState const&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >&, std::__1::vector<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> >, std::__1::allocator<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> > > >&)", referenced from: vtable for QuantLib::ExerciseAdapter in BermudanSwaption-a6bf28.o "QuantLib::OneStepForwards::nextTimeStep(QuantLib::CurveState const&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >&, std::__1::vector<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> >, std::__1::allocator<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> > > >&)", referenced from: vtable for QuantLib::OneStepForwards in BermudanSwaption-a6bf28.o "QuantLib::BermudanExercise::BermudanExercise(std::__1::vector<QuantLib::Date, std::__1::allocator<QuantLib::Date> > const&, bool)", referenced from: _main in BermudanSwaption-a6bf28.o "QuantLib::MultiStepNothing::nextTimeStep(QuantLib::CurveState const&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >&, std::__1::vector<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> >, std::__1::allocator<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> > > >&)", referenced from: vtable for QuantLib::MultiStepNothing in BermudanSwaption-a6bf28.o "QuantLib::MultiStepRatchet::nextTimeStep(QuantLib::CurveState const&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >&, std::__1::vector<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> >, std::__1::allocator<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> > > >&)", referenced from: vtable for QuantLib::MultiStepRatchet in BermudanSwaption-a6bf28.o "QuantLib::MultiStepForwards::nextTimeStep(QuantLib::CurveState const&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >&, std::__1::vector<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> >, std::__1::allocator<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> > > >&)", referenced from: vtable for QuantLib::MultiStepForwards in BermudanSwaption-a6bf28.o "QuantLib::MultiStepSwaption::nextTimeStep(QuantLib::CurveState const&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >&, std::__1::vector<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> >, std::__1::allocator<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> > > >&)", referenced from: vtable for QuantLib::MultiStepSwaption in BermudanSwaption-a6bf28.o "QuantLib::OneStepOptionlets::nextTimeStep(QuantLib::CurveState const&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >&, std::__1::vector<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> >, std::__1::allocator<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> > > >&)", referenced from: vtable for QuantLib::OneStepOptionlets in BermudanSwaption-a6bf28.o "QuantLib::MultiStepOptionlets::nextTimeStep(QuantLib::CurveState const&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >&, std::__1::vector<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> >, std::__1::allocator<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> > > >&)", referenced from: vtable for QuantLib::MultiStepOptionlets in BermudanSwaption-a6bf28.o "QuantLib::OneStepCoinitialSwaps::nextTimeStep(QuantLib::CurveState const&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >&, std::__1::vector<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> >, std::__1::allocator<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> > > >&)", referenced from: vtable for QuantLib::OneStepCoinitialSwaps in BermudanSwaption-a6bf28.o "QuantLib::OneStepCoterminalSwaps::nextTimeStep(QuantLib::CurveState const&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >&, std::__1::vector<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> >, std::__1::allocator<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> > > >&)", referenced from: vtable for QuantLib::OneStepCoterminalSwaps in BermudanSwaption-a6bf28.o "QuantLib::MultiStepCoinitialSwaps::nextTimeStep(QuantLib::CurveState const&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >&, std::__1::vector<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> >, std::__1::allocator<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> > > >&)", referenced from: vtable for QuantLib::MultiStepCoinitialSwaps in BermudanSwaption-a6bf28.o "QuantLib::MultiStepInverseFloater::nextTimeStep(QuantLib::CurveState const&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >&, std::__1::vector<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> >, std::__1::allocator<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> > > >&)", referenced from: vtable for QuantLib::MultiStepInverseFloater in BermudanSwaption-a6bf28.o "QuantLib::MultiStepCoterminalSwaps::nextTimeStep(QuantLib::CurveState const&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >&, std::__1::vector<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> >, std::__1::allocator<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> > > >&)", referenced from: vtable for QuantLib::MultiStepCoterminalSwaps in BermudanSwaption-a6bf28.o "QuantLib::MultiStepCoterminalSwaptions::nextTimeStep(QuantLib::CurveState const&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >&, std::__1::vector<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> >, std::__1::allocator<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> > > >&)", referenced from: vtable for QuantLib::MultiStepCoterminalSwaptions in BermudanSwaption-a6bf28.o "QuantLib::MultiStepPeriodCapletSwaptions::nextTimeStep(QuantLib::CurveState const&, std::__1::vector<unsigned long, std::__1::allocator<unsigned long> >&, std::__1::vector<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> >, std::__1::allocator<std::__1::vector<QuantLib::MarketModelMultiProduct::CashFlow, std::__1::allocator<QuantLib::MarketModelMultiProduct::CashFlow> > > >&)", referenced from: vtable for QuantLib::MultiStepPeriodCapletSwaptions in BermudanSwaption-a6bf28.o "QuantLib::Error::Error(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from: QuantLib::DiscretizedOption::reset(unsigned long) in BermudanSwaption-a6bf28.o QuantLib::Instrument::setupArguments(QuantLib::PricingEngine::arguments*) const in BermudanSwaption-a6bf28.o QuantLib::Option::setupArguments(QuantLib::PricingEngine::arguments*) const in BermudanSwaption-a6bf28.o QuantLib::Payoff::accept(QuantLib::AcyclicVisitor&) in BermudanSwaption-a6bf28.o QuantLib::BlackVolTermStructure::accept(QuantLib::AcyclicVisitor&) in BermudanSwaption-a6bf28.o QuantLib::SimpleQuote::value() const in BermudanSwaption-a6bf28.o QuantLib::Handle<QuantLib::Quote>::operator->() const in BermudanSwaption-a6bf28.o ... "QuantLib::detail::operator<<(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, QuantLib::detail::percent_holder const&)", referenced from: calibrateModel(boost::shared_ptr<QuantLib::ShortRateModel> const&, std::__1::vector<boost::shared_ptr<QuantLib::CalibrationHelper>, std::__1::allocator<boost::shared_ptr<QuantLib::CalibrationHelper> > > const&) in BermudanSwaption-a6bf28.o _main in BermudanSwaption-a6bf28.o "QuantLib::operator<<(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, QuantLib::Date const&)", referenced from: QuantLib::InterestRateIndex::valueDate(QuantLib::Date const&) const in BermudanSwaption-a6bf28.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
我做錯了什麼嗎?這裡的“連結器”有什麼問題?我非常感謝您的幫助,因為我一直在努力讓它工作很長時間。
你不能只編譯 BermudanSwaption.cpp 並希望一切都會好起來。您必須編譯整個 QuantLib 庫並連結到生成的庫文件。請Google“編譯和連結 C++”以獲取更多資訊。
到目前為止,在 Mac 上實現它的最簡單方法是使用 Xcode 來實現。您將需要創建一個新的 Xcode 項目,並將整個 Quantlib 項目文件導入其中。接下來,您將需要創建一個 main() 函式。Xcode 會自動為您進行編譯和連結。
在我的螢幕截圖中,我讓 QuantLib 在 Xcode 中工作,並且正在嘗試 OU 程序。
幾分鐘前我也遇到過這樣的問題,我意識到這個錯誤是由 Mac 設置的標準庫引起的。與最近幾個 MAC 版本的預設設置
-stdlib=libstdc++
相比,在建構時應該設置一個。libc++