-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathquantlib.t.cpp
75 lines (64 loc) · 2.14 KB
/
quantlib.t.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <gtest/gtest.h>
#include "quantlib.h"
namespace { using namespace opcalc; }
TEST(quantlib, supportModelsAndProcesses)
{
for ( auto engine : { "BaroneAdesiWhaley", "FDAmericanCrankNicolson",
"FDDividendAmericanCrankNicolson", "BjerksundStensland" } )
{
for ( auto process : { "BlackScholesMerton", "GarmanKohlagen",
"ExtendedBlackScholesMerton", "VegaStressedBlackScholesProcess" } )
{
ASSERT_NO_THROW(
quantlib::value(engine, process,
quantlib::OptionInput() ) );
ASSERT_THROW(
quantlib::value("BogusEngine", process,
quantlib::OptionInput() ),
std::runtime_error);
}
ASSERT_THROW(
quantlib::value(engine, "BogusProcess",
quantlib::OptionInput() ),
std::runtime_error);
}
}
TEST(quantlib, valuesFromLiterature)
{
/* case taken from QuantLib test suite, which itself cites "the literature"
* as the source of these values */
quantlib::OptionInput input;
input.type = QuantLib::Option::Call;
input.strike = 100;
input.timeToMaturity = 0.10;
input.spot = 90.00;
input.dividend = 0.10;
input.riskFreeRate = 0.10;
input.volatility = 0.15;
EXPECT_NEAR(0.0206,
quantlib::value(
"BaroneAdesiWhaley",
"BlackScholesMerton",
input).NPV(),
3.0e-3);
}
TEST(quantlib, valuesFromBloomberg)
{
// case values taken from OVME on the Bloomberg Terminal
quantlib::OptionInput input;
input.type = QuantLib::Option::Put;
input.strike = 100;
input.timeToMaturity = 0.10;
input.spot = 90.00;
input.dividend = 0.10;
input.riskFreeRate = 0.10;
input.volatility = 0.15;
QuantLib::VanillaOption result
= quantlib::value(
"FDDividendAmericanCrankNicolson",
"BlackScholesMerton",
input);
EXPECT_NEAR(10.04, result.NPV(), 0.04);
EXPECT_NEAR(-0.9943, result.delta(), 0.0025);
EXPECT_NEAR(0.00691, result.gamma(), 0.0037); // quite far off!
}