Black Scholes Loop for Spot/Volatility Values

I have the following question:

"There are three variables of interest: T - t, S, vol. If T- t is held fixed, one can investigate the near term behavior of the option price as S and vol vary. If vol is held fixed, one can view the theoretical future dynamics of the option prices."

Basically I need to have the code evaluate the black scholes formula for each pair of spot and vol values for a range that the user inputs. My code is below, but when it runs it just keeps generating the same results over and over. Not sure what I have done that is wrong and I can't figure out how to export the result in a grid on a text file to show the results.

Any help on this would be much appreciated. The final output needs to show the top row as all the different strikes and the first column shows the different volatilities. Then the data would be filled out as the evaluation of the blackscholes for that pair.

Stdnormal.h and newcounter.h are both header files that work properly. They are used get the business days between the input dates and the normals for black scholes evaulation.

#include <iostream>
#include <fstream>
#include <cmath>
#include <cstdlib>
#include <utility>
#include "StdNormal.h"
#include "newcounter.h"

using namespace std;

double BSF_call(double spot, double rate, double T, double strike, double vol, double div, double isCall){
double sqrtT = sqrt(T);
double d1 = ( log(spot/strike) + (rate - div + 0.5*vol*vol)*(T))/(vol*sqrtT);
double d2 = d1 - vol*sqrtT;
return spot*exp(-div*T)*Normal(d1) - strike*exp(-rate*(T))*Normal(d2);
}

double BSF_put(double spot, double rate, double T, double strike, double vol, double div, double isCall){
double sqrtT = sqrt(T);
double d1 = ( log(spot/strike) + (rate - div + 0.5*vol*vol)*(T))/(vol*sqrtT);
double d2 = d1 - vol*sqrtT;
return -spot*exp(-div*(T))*Normal(-d1) + strike*exp(-rate*(T))*Normal(-d2);
}

int main()
{
double strike;
double spotmin;
double spotmax;
double spotstep;
double volmin;
double volmax;
double volstep;
double rate;
double div;
double isCall;

string temp;
char temp2;
unsigned beginmonth, begindayofmonth, beginyear;
unsigned endmonth, enddayofmonth, endyear;
cout << "enter start date: mm/dd/yyyy" << endl;
cin >> temp;
stringstream stemp(temp);
stemp >> beginmonth >> temp2 >> begindayofmonth >> temp2 >> beginyear;
cout << "enter end date: mm/dd/yyyy" << endl;
cin >> temp;
stemp.clear();
stemp.str(temp);
stemp >> endmonth >> temp2 >> enddayofmonth >> temp2 >> endyear;
date b(beginmonth,begindayofmonth,beginyear);
date e(endmonth,enddayofmonth,endyear);
double totaldays = count_work_days(b, e);
double T = totaldays / 265;

cout << "\nEnter 1 for call or 0 for put\n";
cin >> isCall;
cout << "\nEnter strike\n";
cin >> strike;
cout << "\nEnter spotmin\n";
cin >> spotmin;
cout << "\nEnter spotmax\n";
cin >> spotmax;
cout << "\nEnter spotstep\n";
cin >> spotstep;
cout << "\nEnter volmin\n";
cin >> volmin;
cout << "\nEnter volmax\n";
cin >> volmax;
cout << "\nEnter volstep\n";
cin >> volstep;
cout << "\nEnter div\n";
cin >> div;
cout << "\nEnter rate\n";
cin >> rate;

int vol;
int spot;
if (isCall == 1){
for( int vol = volmin; vol <= volmax; vol += volstep){
for( int spot = spotmin; spot <= spotmax; spot += spotstep){
double result1 = BSF_call(spot, rate, T, strike, vol, div, isCall);
cout << result1 << "\n";
}
}
}
else{
for( int vol = volmin; vol <= volmax; vol += volstep){
for( int spot = spotmin; spot <= spotmax; spot += spotstep){
double result2 = BSF_put(spot, rate, T, strike, vol, div, isCall);
cout << result2 << "\n";
}
}
}

return 0;
}
Topic archived. No new replies allowed.