@@ -119,12 +119,12 @@ class ASTRunner : public AcyclicVisitor,
119119 public Visitor<LoopNode> {
120120public:
121121 ASTRunner (ComputationGraph& g, const std::vector<std::string>& opLabels, const boost::shared_ptr<ModelCG> model,
122- const bool generatePayLog, const std::string& script, bool & interactive, Context& context ,
123- ASTNode*& lastVisitedNode, std::set<std::size_t >& keepNodes,
122+ const bool generatePayLog, const bool includePastCashflows, const std::string& script, bool & interactive,
123+ Context& context, ASTNode*& lastVisitedNode, std::set<std::size_t >& keepNodes,
124124 std::vector<ComputationGraphBuilder::PayLogEntry>& payLogEntries)
125125 : g_(g), opLabels_(opLabels), model_(model), size_(model ? model->size () : 1), generatePayLog_(generatePayLog),
126- script_(script ), interactive_(interactive ), keepNodes_(keepNodes), payLogEntries_(payLogEntries ),
127- context_(context), lastVisitedNode_(lastVisitedNode) {
126+ includePastCashflows_(includePastCashflows ), script_(script ), interactive_(interactive ),
127+ keepNodes_(keepNodes), payLogEntries_(payLogEntries), context_(context), lastVisitedNode_(lastVisitedNode) {
128128 filter.emplace (size_, true );
129129 value.push (RandomVariable ());
130130 filter_node.push (ComputationGraph::nan);
@@ -1029,7 +1029,7 @@ class ASTRunner : public AcyclicVisitor,
10291029 QL_REQUIRE (model_, " model is null" );
10301030 // handle case of past payments: do not evaluate the other parameters, since not needed (e.g. past fixings)
10311031 Date pay = boost::get<EventVec>(paydate).value ;
1032- if (pay <= model_->referenceDate ()) {
1032+ if (pay <= model_->referenceDate () && (!log || !includePastCashflows_) ) {
10331033 value.push (RandomVariable (size_, 0.0 ));
10341034 std::size_t node = cg_const (g_, 0.0 );
10351035 value_node.push (node);
@@ -1053,7 +1053,9 @@ class ASTRunner : public AcyclicVisitor,
10531053 QL_REQUIRE (obs <= pay, " observation date (" << obs << " ) <= payment date (" << pay << " ) required" );
10541054 RandomVariable result; // uninitialised, since model dependent
10551055 value.push (result);
1056- std::size_t node = model_->pay (amount_node, obs, pay, pccy);
1056+ std::size_t node =
1057+ pay <= model_->referenceDate () ? cg_const (g_, 0.0 ) : model_->pay (amount_node, obs, pay, pccy);
1058+ std::size_t cfnode = pay <= model_->referenceDate () ? amount_node : node;
10571059 value_node.push (node);
10581060 TRACE (" pay( " << amount << " , " << obsdate << " , " << paydate << " , " << paycurr << " ) (#" << node
10591061 << " )" ,
@@ -1092,10 +1094,10 @@ class ASTRunner : public AcyclicVisitor,
10921094 }
10931095 // add nodes necessary to write paylog to keepNodes set
10941096 std::size_t filterNode = filter_node.top () == ComputationGraph::nan ? cg_const (g_, 1.0 ) : filter_node.top ();
1095- keepNodes_.insert (node );
1097+ keepNodes_.insert (cfnode );
10961098 keepNodes_.insert (filterNode);
10971099 // add paylog entry data
1098- payLogEntries_.push_back ({node , filterNode, obs, pay, pccy, (Size)legno, cftype, (Size)slot});
1100+ payLogEntries_.push_back ({cfnode , filterNode, obs, pay, pccy, (Size)legno, cftype, (Size)slot});
10991101 }
11001102 }
11011103 }
@@ -1463,6 +1465,7 @@ class ASTRunner : public AcyclicVisitor,
14631465 const boost::shared_ptr<ModelCG> model_;
14641466 const Size size_;
14651467 const bool generatePayLog_;
1468+ const bool includePastCashflows_;
14661469 const std::string script_;
14671470 bool & interactive_;
14681471 std::set<std::size_t >& keepNodes_;
@@ -1479,14 +1482,15 @@ class ASTRunner : public AcyclicVisitor,
14791482
14801483} // namespace
14811484
1482- void ComputationGraphBuilder::run (const bool generatePayLog, const std::string& script, bool interactive) {
1485+ void ComputationGraphBuilder::run (const bool generatePayLog, const bool includePastCashflows, const std::string& script,
1486+ bool interactive) {
14831487
14841488 keepNodes_.clear ();
14851489 payLogEntries_.clear ();
14861490
14871491 ASTNode* loc;
1488- ASTRunner runner (g_, opLabels_, model_, generatePayLog, script, interactive, *context_, loc, keepNodes_ ,
1489- payLogEntries_);
1492+ ASTRunner runner (g_, opLabels_, model_, generatePayLog, generatePayLog && includePastCashflows, script, interactive ,
1493+ *context_, loc, keepNodes_, payLogEntries_);
14901494
14911495 randomvariable_output_pattern pattern;
14921496 if (model_ == nullptr || model_->type () == ModelCG::Type::MC) {
0 commit comments