Skip to content

Commit

Permalink
Binary search in times (#1876)
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio committed Jan 5, 2024
2 parents 7ca3a94 + 4923b79 commit 6aca59e
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions ql/models/parameter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,8 @@ namespace QuantLib {
explicit Impl(std::vector<Time> times) : times_(std::move(times)) {}

Real value(const Array& params, Time t) const override {
Size size = times_.size();
for (Size i=0; i<size; i++) {
if (t<times_[i])
return params[i];
}
return params[size];
Size i = std::upper_bound(times_.begin(), times_.end(), t) - times_.begin();
return params[i];
}

private:
Expand Down

0 comments on commit 6aca59e

Please sign in to comment.