-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercise_3_2.cpp
More file actions
70 lines (54 loc) · 2.57 KB
/
exercise_3_2.cpp
File metadata and controls
70 lines (54 loc) · 2.57 KB
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
#include <iostream> // std::cout
#include <fstream> // std::ofstream
#include <iomanip> // std::setw [needed for output formatting]
#include <functional> // std::function
#include <string> // std::string
#include <cmath> // pow, exp
#include <armadillo> // colvec, mat
#include "common.cpp" // Lots of stuff
using namespace arma;
using namespace std::placeholders;
int main()
{
colvec::fixed<1> S_0 = "100";
double K = 100;
double T = 1;
double r = 0.05;
mat::fixed<1, 1> sigma = "0.2";
// Utility: 1x1 matrix
const colvec::fixed<1> mat_one = ones(1, 1);
// Number of simulations
unsigned long int Q = 100000;
// Exercise 3.2
// By using the payoff and the representation in terms of an ex-
// pectation for the option price, compute numerically with Monte Carlo meth-
// ods the price at 0 of an Asian call option, with a 95% CI.
// As an example, consider the same parameters as in Exercise 3.1.
// std::function<colvec::fixed<1>() > discounted_asian_call = [S_0, T, r, sigma, K, mat_one]() -> colvec::fixed<1>
// {
// colvec::fixed<1> lambda = "1";
//
// // FIXME: Maybe with 1000 points per path it will work better
// return options::asian_call(simulate_path<1>(S_0, T, r, sigma, 1000), lambda, K, T) * exp(-r * T) * mat_one;
// };
// std::function<colvec::fixed<1>() > discounted_asian_put = [S_0, T, r, sigma, K, mat_one]() -> colvec::fixed<1>
// {
// colvec::fixed<1> lambda = "1";
//
// // FIXME: Maybe with 1000 points per path it will work better
// return options::asian_call(simulate_path<1>(S_0, T, r, sigma, 1000), lambda, K, T) * exp(-r * T) * mat_one;
// };
std::pair<double, double> asian_call, asian_put;
std::cout << std::endl << std::endl;
std::cout << "Exercise 3.2 (price of an asian call and put option):" << std::endl << std::endl;
asian_call = options::asian_call_montecarlo(Q, as_scalar(S_0), T, r, as_scalar(sigma), 1000, K);
std::cout << "Asian Call price (Montecarlo simulation): " << std::endl;
print_pair(" Montecarlo simulation: ", asian_call);
asian_put = options::asian_put_montecarlo(Q, as_scalar(S_0), T, r, as_scalar(sigma), 1000, K);
std::cout << "Asian Put price (Montecarlo simulation): " << std::endl;
print_pair(" Montecarlo simulation: ", asian_put);
std::cout << "Difference between the price of an asian call and put is " << asian_call.first - asian_put.first;
std::cout << ", while it should be: " << options::asian_put_call_parity(as_scalar(S_0), K, r, T) << std::endl;
std::system("pause");
return 0;
}