C++:实现量化Partial-time barrier部分时间障碍期权测试实例
C++:实现量化Partial-time barrier部分时间障碍期权测试实例
#include "partialtimebarrieroption.hpp"
#include "utilities.hpp"
#include <ql/experimental/exoticoptions/partialtimebarrieroption.hpp>
#include <ql/experimental/exoticoptions/analyticpartialtimebarrieroptionengine.hpp>
#include <ql/quotes/simplequote.hpp>
#include <ql/utilities/dataformatters.hpp>
#include <ql/time/calendars/target.hpp>
#include <ql/time/daycounters/actual360.hpp>using namespace QuantLib;
using namespace boost::unit_test_framework;namespace partial_time_barrier_option_test {struct TestCase {Real underlying;Real strike;Integer days;Real result;};}void PartialTimeBarrierOptionTest::testAnalyticEngine() {BOOST_TEST_MESSAGE("Testing analytic engine for partial-time barrier option...");using namespace partial_time_barrier_option_test;Date today = Settings::instance().evaluationDate();Option::Type type = Option::Call;DayCounter dc = Actual360();Date maturity = today + 360;ext::shared_ptr<Exercise> exercise =ext::make_shared<EuropeanExercise>(maturity);Real barrier = 100.0;Real rebate = 0.0;ext::shared_ptr<SimpleQuote> spot = ext::make_shared<SimpleQuote>();ext::shared_ptr<SimpleQuote> qRate = ext::make_shared<SimpleQuote>(0.0);ext::shared_ptr<SimpleQuote> rRate = ext::make_shared<SimpleQuote>(0.1);ext::shared_ptr<SimpleQuote> vol = ext::make_shared<SimpleQuote>(0.25);Handle<Quote> underlying(spot);Handle<YieldTermStructure> dividendTS(flatRate(today, qRate, dc));Handle<YieldTermStructure> riskFreeTS(flatRate(today, rRate, dc));Handle<BlackVolTermStructure> blackVolTS(flatVol(today, vol, dc));const ext::shared_ptr<BlackScholesMertonProcess> process =ext::make_shared<BlackScholesMertonProcess>(underlying,dividendTS,riskFreeTS,blackVolTS);ext::shared_ptr<PricingEngine> engine =ext::make_shared<AnalyticPartialTimeBarrierOptionEngine>(process);TestCase cases[] = {{ 95.0, 90.0, 1, 0.0393 },{ 95.0, 110.0, 1, 0.0000 },{ 105.0, 90.0, 1, 9.8751 },{ 105.0, 110.0, 1, 6.2303 },{ 95.0, 90.0, 90, 6.2747 },{ 95.0, 110.0, 90, 3.7352 },{ 105.0, 90.0, 90, 15.6324 },{ 105.0, 110.0, 90, 9.6812 },{ 95.0, 90.0, 180, 10.3345 },{ 95.0, 110.0, 180, 5.8712 },{ 105.0, 90.0, 180, 19.2896 },{ 105.0, 110.0, 180, 11.6055 },{ 95.0, 90.0, 270, 13.4342 },{ 95.0, 110.0, 270, 7.1270 },{ 105.0, 90.0, 270, 22.0753 },{ 105.0, 110.0, 270, 12.7342 },{ 95.0, 90.0, 359, 16.8576 },{ 95.0, 110.0, 359, 7.5763 },{ 105.0, 90.0, 359, 25.1488 },{ 105.0, 110.0, 359, 13.1376 }};for (auto& i : cases) {Date coverEventDate = today + i.days;ext::shared_ptr<StrikedTypePayoff> payoff =ext::make_shared<PlainVanillaPayoff>(type, i.strike);PartialTimeBarrierOption option(PartialBarrier::DownOut,PartialBarrier::EndB1,barrier, rebate,coverEventDate,payoff, exercise);option.setPricingEngine(engine);spot->setValue(i.underlying);Real calculated = option.NPV();Real expected = i.result;Real error = std::fabs(calculated-expected);Real tolerance = 1e-4;if (error > tolerance)BOOST_ERROR("Failed to reproduce partial-time barrier option value"<< "\n expected: " << expected<< "\n calculated: " << calculated<< "\n error: " << error);}
}test_suite* PartialTimeBarrierOptionTest::suite() {auto* suite = BOOST_TEST_SUITE("Partial-time barrier option tests");suite->add(QUANTLIB_TEST_CASE(&PartialTimeBarrierOptionTest::testAnalyticEngine));return suite;
}
该博文为原创文章,未经博主同意不得转。
本文章博客地址:https://cplusplus.blog.csdn.net/article/details/128365104
C++:实现量化Partial-time barrier部分时间障碍期权测试实例相关推荐
- C++:实现量化barrieroption障碍期权测试实例
C++:实现量化barrieroption障碍期权测试实例 #include "barrieroption.hpp" #include "utilities.hpp&qu ...
- C++:实现量化doublebarrier option双障碍期权 测试实例
C++:实现量化doublebarrier option双障碍期权 测试实例 #include "doublebarrieroption.hpp" #include "u ...
- C++:实现量化Lookback option 回顾式期权测试实例
C++:实现量化Lookback option 回顾式期权测试实例 #include "lookbackoptions.hpp" #include "utilities. ...
- C++:实现量化Forward option远期合约期权测试实例
C++:实现量化Forward option远期合约期权测试实例 #include "forwardoption.hpp" #include "utilities.hpp ...
- C++:实现量化dividend option股息期权 测试实例
C++:实现量化dividend option股息期权 测试实例 #include "dividendoption.hpp" #include "utilities.hp ...
- C++:实现量化Everest Option埃弗勒斯峰型测试实例
C++:实现量化Everest Option埃弗勒斯峰型测试实例 #include "everestoption.hpp" #include "utilities.hpp ...
- C++:实现量化compound option复合期权测试实例
C++:实现量化compound option复合期权测试实例 #include "compoundoption.hpp" #include "utilities.hpp ...
- C++:实现量化cliquet option棘轮期权测试实例
C++:实现量化cliquet option棘轮期权测试实例 #include "cliquetoption.hpp" #include "utilities.hpp&q ...
- 文件时间信息在测试中的应用
1 简介 文件时间信息在测试中也有妙用- 通过记录模块运行前后的文件时间信息来识别运行前后发生变化的文件,从而识别模块运行前后的新增文件.删除的文件和内容发生变化的文件. 利用识别出来的发生变化的文件 ...
最新文章
- 小甲鱼关于push,pop指令的一个编程题
- MPB:深大李猛组-基于PacBio SMRT三代测序的红树林沉积物真菌群落的研究
- 牛客小白月赛12 H	华华和月月种树 (离线dfs序+线段树)
- 苹果7手机html5测试,HTML5 基础测试题
- 算法题目——多米诺骨牌问题(POJ-2663)
- VMware 虚拟机运行卡慢的解决办法
- Oracle 11g ora 15018,OracleASM错误之--ORA-15031、ORA-15014
- MyBatis入门使用方式
- asp导出excel文件格式
- 【STM32 基础实验蜂鸣器发声】
- 关于 未受信任的企业级开发者 提示的解决
- 【微信授权登录】Scope 参数错误或没有 Scope 权限
- 批量保存网页为html文件的几种方法
- 长安清酒·花酿清酒一瓣心醉的甜香
- c语言中,关于延迟函数的理解
- mysql数据库配置_mysql数据库怎么配置
- ARCHS[@]: unbound variable
- 把一个人的特点写具体作文_五年级把一个人的特点写具体的作文10篇
- vs2017c语言一闪而逝6,Visual Studio IDE编写程序时不显示窗口或窗口一闪而逝的解决方法...
- 【GBASE】南大通用GBase 8a MPP Cluster技术特点
热门文章
- c语言验证卡不列克常数,卡布列克数
- Linux(Ubuntu)下C++获取可用内存、当前最大内存等信息
- XIlinx ISE与win8,win10兼容设置
- 用计算机表白我不喜欢你了,还在用“我喜欢你”表白?醒醒吧!
- 使用Charles和小米手机MIX3进行手机HTTPS抓包
- 华为软件开发云又出新服务:开源镜像站正式上线,致敬开源,使能开发者!...
- SCNN网络理解-交通场景的理解
- python读取redis指定key_Python获取Redis所有Key以及内容的方法
- 风格:原理图中电容电阻电感的取值命名风格
- 分形 java_分形(递归)