Hello,
I am getting incorrect results while trying to price American option using Projected SOR. This is for a class project, and I have been instructed to implement it by transforming Black-Scholes into Heat equation for the algorithm.
For this assignment:
K = 25;
r = 0.02;
volatility = 0.05;
Dividend Rate = 0.03;
T=1;
(Delta)X = 0.05
(Delta)t = 0.00125
so lambda = (delta)t/(delta)x^2 = 0.5
For the algorithm, the range for x is -2.5 <= x <= 2.5 after converting to heat equation.
I am to find prices for values of S=5, 25, and 125.
Variables: jMax = iMax = 101 = size of vectors/arrays since C++ uses zero-based vector indexing.
qDiv = (2 * (r - dividend yield)) / volatility^2
q = (2 * r) / volatility^2
The implementation is per class notes that I can attach if needed. The code segment for the American Call/Implicit FDM scheme is below.
Results from this are below:
Implicit Scheme Calculation for American Call
Using Projected SOR Iterative Algorithm.
S = 5: 0
S = 25: 1.17982
S = 125: 96.8086
Any help would be appreciated. I am completely stuck on this and I received little help from the instructor when I asked him about it this morning (he didn't even look at my code!) and I only have until Wednesday night to correct my code.
I am getting incorrect results while trying to price American option using Projected SOR. This is for a class project, and I have been instructed to implement it by transforming Black-Scholes into Heat equation for the algorithm.
For this assignment:
K = 25;
r = 0.02;
volatility = 0.05;
Dividend Rate = 0.03;
T=1;
(Delta)X = 0.05
(Delta)t = 0.00125
so lambda = (delta)t/(delta)x^2 = 0.5
For the algorithm, the range for x is -2.5 <= x <= 2.5 after converting to heat equation.
I am to find prices for values of S=5, 25, and 125.
Variables: jMax = iMax = 101 = size of vectors/arrays since C++ uses zero-based vector indexing.
qDiv = (2 * (r - dividend yield)) / volatility^2
q = (2 * r) / volatility^2
The implementation is per class notes that I can attach if needed. The code segment for the American Call/Implicit FDM scheme is below.
Code:
//Runs projected SOR for American Call with implicit scheme
void ProjSORCallImp(int jMax, int iMax, double lambda, double qDiv, double q)
{
//Heading for output of values
cout << endl;
cout << "Implicit Scheme Calculation for American Call";
cout << endl;
cout << "Using Projected SOR Iterative Algorithm." << endl;
cout << endl;
int i, j;
double tau;
double b[jMax];
double vPrev[jMax];
double vNext[jMax];
double w[jMax];
double g[jMax][iMax];
double terminateCondition;
double compareValue;
//populate g matrix
for (j = 0; j < jMax; j++)
{
for (i = 0; i < iMax; i++)
{
compareValue=exp(((qDiv+1)/2)*(-2.5+(j*0.05)))-exp(((qDiv-1)/2)*(-2.5+(j*0.05)));
g[j][i]=exp(((pow(qDiv-1,2)/4)+q)*(i*.00125))*max(compareValue, (double)0);
}
}
//set up iteration vector
for (j = 0; j < jMax; j++)
{
w[j] = g[j][0];
}
//Begin i loop (time increments) for prototype core algorithm
for(i = 0; i <= iMax - 1; i++)
{
tau = (double)i * 0.00125;
//set up b vector
b[1]=w[1]+lambda*g[0][i+1];
for (j = 2; j <= jMax - 3; j++)
{
b[j]=w[j];
}
b[jMax-2]=w[jMax-2]+lambda*g[jMax-1][i+1];
//set v = max(w, g+1)
for(j = 0; j <= jMax - 1; j++)
{
vPrev[j] = max(w[j],g[j][i+1]);
}
//Populate with initial values
for (j = 0; i < jMax; i++)
{
vNext[i] = 0;
}
//do loop while not within desired tolerance
do
{
for (j = 1; j <= jMax - 2; j++)
{
compareValue = vPrev[j]+(1.3/(1+(2*lambda)))*(b[j]+lambda*vNext[j-1]-(1+(2*lambda))*vPrev[j]+lambda*vPrev[j+1]);
vNext[j] = max(g[j][i+1], compareValue);
}
terminateCondition = vPrev[82]; //for comparison for tolerance
for (i = 0; i < jMax; i++)
{
vPrev[i] = vNext[i]; //sets vPrev vector for next iteration
}
}
while (sqrt(pow(vNext[82] - terminateCondition, 2)) > 0.00000001);
//set new iteration vector
for(j = 0; j < jMax; j++)
{
w[j] = vNext[j];
}
}
double Stock[jMax];
double Value[jMax];
for(j = 0; j < jMax; j++)
{
Stock[j] = 25.0*exp((j*0.05)-2.5);
Value[j] = 25.0*exp((((qDiv-1)*((j*0.05)-2.5))/-2)-((pow(qDiv-1,2)/4)+q)*.125)*w[j];
}
cout << "S = 5: " << Value[18] << endl;
cout << "S = 25: " << Value[50] << endl;
cout << "S = 125: " << Value[82] << endl;
}
Implicit Scheme Calculation for American Call
Using Projected SOR Iterative Algorithm.
S = 5: 0
S = 25: 1.17982
S = 125: 96.8086
Any help would be appreciated. I am completely stuck on this and I received little help from the instructor when I asked him about it this morning (he didn't even look at my code!) and I only have until Wednesday night to correct my code.