Skip to content

Commit 8cf6970

Browse files
style: apply clang-format
1 parent bd7f433 commit 8cf6970

4 files changed

Lines changed: 95 additions & 153 deletions

File tree

src/payoffs/asian_payoffs.cpp

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,74 +3,66 @@
33
#include "lfmc/payoff.hpp"
44
#include "lfmc/types.hpp"
55

6+
#include <algorithm>
67
#include <expected>
78
#include <numeric>
8-
#include <algorithm>
9-
#include <vector>
109
#include <string>
10+
#include <vector>
1111

1212
namespace lfmc {
1313

14-
15-
16-
1714
class AsianCall : public Payoff {
18-
private:
15+
private:
1916
double strike_;
2017

21-
public:
18+
public:
2219
explicit AsianCall(double strike) : strike_(strike) {}
2320

2421
std::expected<std::vector<Payoffs>, std::string>
2522
generate_payoffs(const std::vector<Path>& paths) const override {
2623
Payoffs payoffs;
27-
24+
2825
payoffs.reserve(paths.size());
2926

3027
for (const auto& path : paths) {
31-
28+
3229
if (path.empty())
3330
return std::unexpected("Empty path encountered in AsianCall");
3431

35-
double mean = std::reduce(path.begin(), path.end(), 0.0)
36-
/ static_cast<double>(path.size());
32+
double mean =
33+
std::reduce(path.begin(), path.end(), 0.0) / static_cast<double>(path.size());
3734
payoffs.push_back(std::max(mean - strike_, 0.0));
3835
}
3936

4037
return std::vector<Payoffs>{payoffs};
4138
}
4239
};
4340

44-
4541
class AsianPut : public Payoff {
46-
private:
42+
private:
4743
double strike_;
4844

49-
public:
45+
public:
5046
explicit AsianPut(double strike) : strike_(strike) {}
5147

5248
std::expected<std::vector<Payoffs>, std::string>
5349
generate_payoffs(const std::vector<Path>& paths) const override {
54-
55-
50+
5651
Payoffs payoffs;
57-
58-
59-
52+
6053
payoffs.reserve(paths.size());
6154

6255
for (const auto& path : paths) {
6356
if (path.empty())
6457
return std::unexpected("Empty path encountered in AsianPut");
6558

66-
67-
double mean = std::reduce(path.begin(), path.end(), 0.0)
68-
/ static_cast<double>(path.size());
59+
double mean =
60+
std::reduce(path.begin(), path.end(), 0.0) / static_cast<double>(path.size());
6961
payoffs.push_back(std::max(strike_ - mean, 0.0));
7062
}
7163

7264
return std::vector<Payoffs>{payoffs};
7365
}
7466
};
7567

76-
}
68+
} // namespace lfmc

src/payoffs/barrier_payoffs.cpp

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,34 @@
33
#include "lfmc/payoff.hpp"
44
#include "lfmc/types.hpp"
55

6+
#include <algorithm>
67
#include <expected>
78
#include <numeric>
8-
#include <algorithm>
9-
#include <vector>
109
#include <string>
10+
#include <vector>
1111

1212
namespace lfmc {
1313

1414
class UpAndOutCall : public Payoff {
15-
private:
15+
private:
1616
double strike_;
1717
double barrier_;
1818

19-
public:
20-
UpAndOutCall(double strike, double barrier)
21-
: strike_(strike), barrier_(barrier) {}
22-
19+
public:
20+
UpAndOutCall(double strike, double barrier) : strike_(strike), barrier_(barrier) {}
2321

2422
std::expected<std::vector<Payoffs>, std::string>
2523
generate_payoffs(const std::vector<Path>& paths) const override {
26-
27-
24+
2825
Payoffs payoffs;
2926
payoffs.reserve(paths.size());
3027

3128
for (const auto& path : paths) {
3229
if (path.empty())
3330
return std::unexpected("Empty path encountered in UpAndOutCall");
3431

35-
bool knocked_out = std::any_of(path.begin(), path.end(),
36-
[this](double s) { return s >= barrier_; });
37-
38-
39-
32+
bool knocked_out =
33+
std::any_of(path.begin(), path.end(), [this](double s) { return s >= barrier_; });
4034

4135
if (knocked_out) {
4236
payoffs.push_back(0.0);
@@ -49,35 +43,30 @@ class UpAndOutCall : public Payoff {
4943
}
5044
};
5145

52-
53-
5446
class DownAndInPut : public Payoff {
55-
private:
47+
private:
5648
double strike_;
5749
double barrier_;
5850

59-
public:
60-
DownAndInPut(double strike, double barrier)
61-
: strike_(strike), barrier_(barrier) {}
51+
public:
52+
DownAndInPut(double strike, double barrier) : strike_(strike), barrier_(barrier) {}
6253

6354
std::expected<std::vector<Payoffs>, std::string>
6455
generate_payoffs(const std::vector<Path>& paths) const override {
6556
Payoffs payoffs;
6657
payoffs.reserve(paths.size());
6758

6859
for (const auto& path : paths) {
69-
70-
60+
7161
if (path.empty())
7262
return std::unexpected("Empty path encountered in DownAndInPut");
7363

74-
bool knocked_in = std::any_of(path.begin(), path.end(),
75-
[this](double s) { return s <= barrier_; });
64+
bool knocked_in =
65+
std::any_of(path.begin(), path.end(), [this](double s) { return s <= barrier_; });
7666

7767
if (knocked_in) {
7868
payoffs.push_back(std::max(strike_ - path.back(), 0.0));
79-
80-
69+
8170
} else {
8271
payoffs.push_back(0.0);
8372
}
@@ -86,4 +75,4 @@ class DownAndInPut : public Payoff {
8675
return std::vector<Payoffs>{payoffs};
8776
}
8877
};
89-
}
78+
} // namespace lfmc

src/payoffs/lookback_payoffs.cpp

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,18 @@
33
#include "lfmc/payoff.hpp"
44
#include "lfmc/types.hpp"
55

6+
#include <algorithm>
67
#include <expected>
78
#include <numeric>
8-
#include <algorithm>
9-
#include <vector>
109
#include <string>
10+
#include <vector>
1111

1212
namespace lfmc {
1313

14-
15-
class LookbackCall : public Payoff {
16-
public:
14+
class LookbackCall : public Payoff {
15+
public:
1716
std::expected<std::vector<Payoffs>, std::string>
1817

19-
20-
2118
generate_payoffs(const std::vector<Path>& paths) const override {
2219
Payoffs payoffs;
2320
payoffs.reserve(paths.size());
@@ -26,8 +23,6 @@ namespace lfmc {
2623
if (path.empty())
2724
return std::unexpected("Empty path encountered in LookbackCall");
2825

29-
30-
3126
double min_price = *std::min_element(path.begin(), path.end());
3227
payoffs.push_back(path.back() - min_price);
3328
}
@@ -36,11 +31,8 @@ namespace lfmc {
3631
}
3732
};
3833

39-
40-
4134
class LookbackPut : public Payoff {
42-
public:
43-
35+
public:
4436
std::expected<std::vector<Payoffs>, std::string>
4537
generate_payoffs(const std::vector<Path>& paths) const override {
4638
Payoffs payoffs;
@@ -51,14 +43,12 @@ class LookbackPut : public Payoff {
5143
return std::unexpected("Empty path encountered in LookbackPut");
5244

5345
double max_price = *std::max_element(path.begin(), path.end());
54-
55-
56-
46+
5747
payoffs.push_back(max_price - path.back());
5848
}
5949

6050
return std::vector<Payoffs>{payoffs};
6151
}
6252
};
6353

64-
}
54+
} // namespace lfmc

0 commit comments

Comments
 (0)