File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,25 +26,14 @@ template <StochasticProcess SP, NumericalScheme<SP> NS> class Pipeline {
2626
2727 std::expected<double , std::string> run (size_t steps, double T) {
2828 while (!estimator_->converged ()) {
29- auto normals = random_source_->generate_normals (steps);
30- if (!normals) {
31- return std::unexpected (" Failed to generate random normals" );
32- }
33-
34- auto paths = path_generator_->generate_paths (normals.value (), steps, T);
35- if (!paths) {
36- return std::unexpected (" Failed to generate paths" );
37- }
38-
39- auto payoffs = payoff_->generate_payoffs (paths.value ());
40- if (!payoffs) {
41- return std::unexpected (" Failed to generate payoffs" );
42- }
43-
44- auto result = estimator_->add_payoffs (payoffs.value ());
45- if (!result) {
46- return std::unexpected (result.error ());
47- }
29+ auto result =
30+ random_source_->generate_normals (steps)
31+ .and_then ([&](auto normals) {
32+ return path_generator_->generate_paths (normals, steps, T);
33+ })
34+ .and_then ([&](auto paths) { return payoff_->generate_payoffs (paths); })
35+ .and_then ([&](auto payoffs) { return estimator_->add_payoffs (payoffs); })
36+ .or_else ([](auto error) { return std::unexpected (error); });
4837 }
4938
5039 return estimator_->result ();
You can’t perform that action at this time.
0 commit comments