FTQuant  0.1
ThomasAlgorithm.cpp
Go to the documentation of this file.
1 #include <BlackSholes.hpp>
2 #include <vector>
3 
9 void thomas_algorithm(std::vector<double>& v, std::vector<double>& a,
10  std::vector<double>& b, std::vector<double>& c,
11  std::vector<double>& f) {
12  std::size_t n = a.size() - 1;
13 
14  std::vector<double> alpha;
15  alpha.resize(n + 1);
16 
17  std::vector<double> beta;
18  beta.resize(n + 1);
19 
20  alpha[2] = b[1] / c[1];
21  beta[2] = f[1] / c[1];
22 
23  for (std::size_t j = 2; j <= n - 1; j++) {
24  alpha[j + 1] = b[j] / (c[j] - a[j] * alpha[j]);
25  beta[j + 1] = (f[j] + a[j] * beta[j]) / (c[j] - a[j] * alpha[j]);
26  }
27 
28  v[n] = (f[n] + a[n] * beta[n]) / (c[n] - a[n] * alpha[n]);
29 
30  for (std::size_t j = n - 1; j >= 1; j--) {
31  v[j] = beta[j + 1] + alpha[j + 1] * v[j + 1];
32  }
33 }
Contains the definition of the Black-Sholes model.
void thomas_algorithm(std::vector< double > &v, std::vector< double > &a, std::vector< double > &b, std::vector< double > &c, std::vector< double > &f)
Implementation of Thomas algorithm for tridiagonal matrices.