1+ #pragma once
2+
3+ #include " lfmc/estimator/control_variate_estimator.hpp"
4+ #include " lfmc/estimator/monte_carlo_estimator.hpp"
5+ #include " lfmc/numerical_scheme/euler_maruyama.hpp"
6+ #include " lfmc/path_generator/path_generator.hpp"
7+ #include " lfmc/payoff/control_variate_payoffs.hpp"
8+ #include " lfmc/payoff/payoff.hpp"
9+ #include " lfmc/pipeline/pipeline.hpp"
10+ #include " lfmc/random_source/antithetic_random_source.hpp"
11+ #include " lfmc/random_source/pseudo_random_source.hpp"
12+ #include " lfmc/strategy/strategy_runner.hpp"
13+ #include " lfmc/stochastic_process/stochastic_process.hpp"
14+
15+ #include < memory>
16+ #include < random>
17+ #include < string>
18+
19+ namespace lfmc {
20+
21+ template <StochasticProcess SP , NumericalScheme<SP > NS >
22+ class StrategyFactory {
23+ public:
24+ static std::unique_ptr<StrategyRunner<SP , NS >>
25+ create_pseudo_random_strategy (SP process, NS scheme,
26+ std::unique_ptr<Payoff> payoff,
27+ unsigned seed = std::random_device{}()) {
28+ auto rs = std::make_unique<PseudoRandomSource>(seed);
29+ auto pg = std::make_unique<PathGenerator<SP , NS >>(process, scheme);
30+ auto est = std::make_unique<MonteCarloEstimator>();
31+
32+ Pipeline<SP , NS > pipeline (std::move (rs), std::move (pg),
33+ std::move (payoff), std::move (est));
34+
35+ return std::make_unique<StrategyRunner<SP , NS >>(
36+ std::move (pipeline), " PseudoRandom" );
37+ }
38+
39+ static std::unique_ptr<StrategyRunner<SP , NS >>
40+ create_antithetic_strategy (SP process, NS scheme,
41+ std::unique_ptr<Payoff> payoff,
42+ unsigned seed = std::random_device{}()) {
43+ auto rs = std::make_unique<AntitheticRandomSource>(seed);
44+ auto pg = std::make_unique<PathGenerator<SP , NS >>(process, scheme);
45+ auto est = std::make_unique<MonteCarloEstimator>();
46+
47+ Pipeline<SP , NS > pipeline (std::move (rs), std::move (pg),
48+ std::move (payoff), std::move (est));
49+
50+ return std::make_unique<StrategyRunner<SP , NS >>(
51+ std::move (pipeline), " Antithetic" );
52+ }
53+
54+ static std::unique_ptr<StrategyRunner<SP , NS >>
55+ create_control_variate_strategy (SP process, NS scheme,
56+ std::unique_ptr<Payoff> target_payoff,
57+ std::unique_ptr<Payoff> control_payoff,
58+ double control_expectation,
59+ unsigned seed = std::random_device{}()) {
60+ auto rs = std::make_unique<PseudoRandomSource>(seed);
61+ auto pg = std::make_unique<PathGenerator<SP , NS >>(process, scheme);
62+ auto po = std::make_unique<ControlVariatePayoff>(
63+ std::move (target_payoff), std::move (control_payoff));
64+ auto est = std::make_unique<ControlVariateEstimator>(control_expectation);
65+
66+ Pipeline<SP , NS > pipeline (std::move (rs), std::move (pg),
67+ std::move (po), std::move (est));
68+
69+ return std::make_unique<StrategyRunner<SP , NS >>(
70+ std::move (pipeline), " ControlVariate" );
71+ }
72+
73+ // Add more factory methods as we make/implement more VR strategies:
74+ // - create_quasi_monte_carlo_strategy()
75+ // - create_importance_sampling_strategy()
76+ // etc.
77+ };
78+
79+ } // namespace lfmc
0 commit comments