Skip to content

Commit 859e9dd

Browse files
committed
refactor: move everythig into folders and fix convergency tests
1 parent 28b9e85 commit 859e9dd

41 files changed

Lines changed: 508 additions & 280 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmake/README.md

Lines changed: 0 additions & 9 deletions
This file was deleted.

include/lfmc/estimator.hpp renamed to include/lfmc/estimator/control_variate_estimator.hpp

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,14 @@
11
#pragma once
22

3-
#include "lfmc/types.hpp"
3+
#include "lfmc/core/types.hpp"
4+
#include "lfmc/estimator/estimator.hpp"
45

56
#include <expected>
67
#include <string>
78
#include <vector>
89

910
namespace lfmc {
1011

11-
class Estimator {
12-
public:
13-
virtual std::expected<void, std::string> add_payoffs(const std::vector<Payoffs>& payoffs) = 0;
14-
virtual bool converged() const = 0;
15-
virtual std::expected<double, std::string> result() const = 0;
16-
// virtual void merge(Estimator const& other) = 0;
17-
virtual ~Estimator() = default;
18-
};
19-
20-
class MonteCarloEstimator : public Estimator {
21-
private:
22-
double sum = 0.0;
23-
std::size_t count = 0;
24-
25-
public:
26-
std::expected<void, std::string> add_payoffs(const std::vector<Payoffs>& payoffs) override;
27-
bool converged() const override;
28-
std::expected<double, std::string> result() const override;
29-
// void merge(Estimator const& other) override;
30-
};
31-
3212
// TODO if control is analytically known, can put it at payoff level
3313
class ControlVariateEstimator : public Estimator {
3414
private:
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#pragma once
2+
3+
#include "lfmc/core/types.hpp"
4+
5+
#include <expected>
6+
#include <string>
7+
#include <vector>
8+
9+
namespace lfmc {
10+
11+
class Estimator {
12+
public:
13+
virtual std::expected<void, std::string> add_payoffs(const std::vector<Payoffs>& payoffs) = 0;
14+
virtual bool converged() const = 0;
15+
virtual std::expected<double, std::string> result() const = 0;
16+
// virtual void merge(Estimator const& other) = 0;
17+
virtual ~Estimator() = default;
18+
};
19+
20+
} // namespace lfmc
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#pragma once
2+
3+
#include "lfmc/core/types.hpp"
4+
#include "lfmc/estimator/estimator.hpp"
5+
6+
#include <expected>
7+
#include <string>
8+
#include <vector>
9+
10+
namespace lfmc {
11+
12+
class MonteCarloEstimator : public Estimator {
13+
private:
14+
double sum = 0.0;
15+
std::size_t count = 0;
16+
17+
public:
18+
std::expected<void, std::string> add_payoffs(const std::vector<Payoffs>& payoffs) override;
19+
bool converged() const override;
20+
std::expected<double, std::string> result() const override;
21+
// void merge(Estimator const& other) override;
22+
};
23+
24+
} // namespace lfmc
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
3+
#include "lfmc/stochastic_process/stochastic_process.hpp"
4+
5+
#include <cmath>
6+
7+
namespace lfmc {
8+
9+
template <StochasticProcess P> class EulerMaruyama {
10+
public:
11+
double step(P const& process, double x, double t, double dt, double z) const noexcept {
12+
double drift = process.drift(x, t);
13+
double diffusion = process.diffusion(x, t);
14+
return x + drift * dt + diffusion * std::sqrt(dt) * z;
15+
}
16+
};
17+
} // namespace lfmc

include/lfmc/numerical_scheme.hpp renamed to include/lfmc/numerical_scheme/numerical_scheme.hpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#pragma once
22

3-
#include "lfmc/stochastic_process.hpp"
4-
53
#include <cmath>
64
#include <concepts>
75

@@ -13,15 +11,6 @@ concept NumericalScheme =
1311
{ s.step(p, x, t, dt, z) } -> std::convertible_to<double>;
1412
};
1513

16-
template <StochasticProcess P> class EulerMaruyama {
17-
public:
18-
double step(P const& process, double x, double t, double dt, double z) const noexcept {
19-
double drift = process.drift(x, t);
20-
double diffusion = process.diffusion(x, t);
21-
return x + drift * dt + diffusion * std::sqrt(dt) * z;
22-
}
23-
};
24-
2514
/**
2615
* @brief Exact simulation for Geometric Brownian Motion.
2716
*

include/lfmc/path_generator.hpp renamed to include/lfmc/path_generator/path_generator.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#pragma once
22

3-
#include "lfmc/numerical_scheme.hpp"
4-
#include "lfmc/stochastic_process.hpp"
5-
#include "lfmc/types.hpp"
3+
#include "lfmc/core/types.hpp"
4+
#include "lfmc/numerical_scheme/numerical_scheme.hpp"
5+
#include "lfmc/stochastic_process/stochastic_process.hpp"
66

77
#include <expected>
88
#include <string>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#pragma once
2+
3+
#include "lfmc/core/types.hpp"
4+
#include "lfmc/payoff/payoff.hpp"
5+
6+
#include <expected>
7+
#include <vector>
8+
9+
namespace lfmc {
10+
11+
class AsianCall : public Payoff {
12+
private:
13+
double strike_;
14+
15+
public:
16+
explicit AsianCall(double strike);
17+
18+
std::expected<std::vector<Payoffs>, std::string>
19+
generate_payoffs(const std::vector<Path>& paths) const override;
20+
};
21+
22+
class AsianPut : public Payoff {
23+
private:
24+
double strike_;
25+
26+
public:
27+
explicit AsianPut(double strike);
28+
29+
std::expected<std::vector<Payoffs>, std::string>
30+
generate_payoffs(const std::vector<Path>& paths) const override;
31+
};
32+
33+
} // namespace lfmc

0 commit comments

Comments
 (0)