Hi I'm trying to generate random number for Monte Carlo Simulation that follows normal distribution.
Can anybody tell me why this gives me same present value every time I run the program?
Thanks.
#include <iostream>
#include <vector>
#include <cmath>
#include <random>
using namespace std;
double monteCarlo(int S0, double r, double vol, int T, double U, double D, int stepNum)
{
double price;
int half = 182;
int i = 0;
double S_t = S0;
double early = 0;
while (i<stepNum) {
default_random_engine generator;
normal_distribution<double> dist(0, 1);
double phi = dist(generator);
S_t = S_t + r * S_t*(1 / 365) + vol * S_t*phi*sqrt((double)1 / 365);
if (i%half == 0 && S_t > U*(double)S0&&i%half < 6) {
early = S0 * (1.0 + 3.39*(i / half) / 100.0)*exp((T - (i / (2 * half)))*r);
break;
}
void main()
{
vector<double> price;
double sum = 0;
int M = 10;
for (int i = 0;i < M;i++) {
price.push_back(monteCarlo(1000, 0.0342, 0.012653287, 3, 1.05, 0.80, 365 * 3));
}
for (unsigned int i = 0;i < price.size();i++) {
sum += price[i];
}
cout << "Present value of the equity-linked security: " << sum / M << endl;
return;
}