(*initialisation of variables*)
n = 10;(*expected value greater than 3*)
r = 0.03;
\[Sigma] = 0.2;
sMax = 2;
sMin = -2;
(*define \[CapitalDelta]x.*)
\[CapitalDelta]x = (sMax - sMin)/(n - 1);
(*adding vector matrix... any assignment of v value should be
included here*)
vecMatrix = Array[v, n];
(*reusable internal variables*)
p = 0.5 (\[Sigma]^2)/(\[CapitalDelta]x^2);
q = (2 r - (\[Sigma]^2))/\[CapitalDelta]x;
x = (2 p + r) - 0.75 q;
y = 5 p + q;
a = p - 0.25 q;
b = -2 p - r;
c = p + 0.25 q;
(*introducing matC for one time initialisation*)
matC = SparseArray[{Band[{1, 1}, {n, n}, n - 1] -> x,
Band[{1, 2}, {n, n}, {n - 1, n - 3}] -> y,
Band[{2, 1}, {n - 1, n}] -> a, Band[{2, 2}, {n - 1, n}] -> b,
Band[{2, 3}, {n - 1, n}] -> c}, {n, n}];
MatrixForm [matC]*
MatrixForm[vecMatrix]
|
|
||||
| show 2 more comments |
|
I've done a lot of option pricing with MMA, but I can't relate your code to plain old Black-Scholes:
where
(I added this simple stuff to help others understand your question.) I don't see where the Black-Scholes part comes into your code? It would help educate others if you put your question in a context, for example, black-scholes option pricing is easy if you have one option, but if you have 100,000 at varying strikes, etc. But your question seems to really be about matrix algebra and sparce arrays. |
|||||||||
|
|
You have a syntax error in the last line. I suspect you mean:
which yields:
As an aside, comments that just say As a further comment on your code, all your variables are global to your session, so the comment "reusable internal variables" is misleading. If you want to scope variables as internal to a particular calculation, you need to use scoping constructs like |
|||||
|
Dot(.) and you wrapped the lists inMatrixFormbefore multiplying. See the question I linked previously. – Verbeia♦ Oct 7 '12 at 10:59