Skip to content

Commit fe78641

Browse files
committed
Merge remote-tracking branch 'origin/main' into feature/solving-linear-systems-with-cuda
2 parents 060681c + b8fe822 commit fe78641

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

pdesolvers/main.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ def main():
1616
# solver2 = pde.Heat1DExplicitSolver(equation1)
1717

1818
# testing for bse
19-
equation2 = pde.BlackScholesEquation('call', 300, 1, 0.2, 0.05, 100, 10, 100)
19+
equation2 = pde.BlackScholesEquation('call', 300, 1, 0.2, 0.05, 100, 100, 20000)
2020

21-
solver1 = pde.BlackScholesExplicitSolver(equation2)
21+
solver1 = pde.BlackScholesCNSolver(equation2)
2222
res1 = solver1.solve()
2323
# res2 = solver2.solve()
2424

2525
print(res1.get_result())
26-
# res1.plot()
26+
res1.plot()
2727

2828
if __name__ == "__main__":
2929
main()

pdesolvers/solvers/black_scholes_solvers.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from operator import truediv
2-
31
from scipy import sparse
42
from scipy.sparse.linalg import spsolve
53
import numpy as np
@@ -85,9 +83,9 @@ def solve(self):
8583
dS = S[1] - S[0]
8684
dT = T[1] - T[0]
8785

88-
alpha = 0.25 * dT * ((self.equation.sigma**2) * (S**2) - self.equation.rate*S)
89-
beta = -dT * 0.5 * (self.equation.sigma**2 * (S**2) + self.equation.rate)
90-
gamma = 0.25 * dT * (self.equation.sigma**2 * (S**2) + self.equation.rate * S)
86+
alpha = 0.25 * dT * ((self.equation.sigma**2) * (S**2) / (dS**2) - self.equation.rate * S / dS)
87+
beta = -dT * 0.5 * (self.equation.sigma**2 * (S**2) / (dS**2) + self.equation.rate)
88+
gamma = 0.25 * dT * (self.equation.sigma**2 * (S**2) / (dS**2) + self.equation.rate * S / dS)
9189

9290
lhs = sparse.diags([-alpha[2:], 1-beta[1:], -gamma[1:-1]], [-1, 0, 1], shape = (self.equation.s_nodes - 1, self.equation.s_nodes - 1), format='csr')
9391
rhs = sparse.diags([alpha[2:], 1+beta[1:], gamma[1:-1]], [-1, 0, 1], shape = (self.equation.s_nodes - 1, self.equation.s_nodes - 1) , format='csr')

0 commit comments

Comments
 (0)