What I tried to do here is
There're 2 methods that each will have final result as an array.
At this point I don't know where to go/ how to fix it.
What I need is array U that supposed to be combination of U_1 and U_2. and I need to use them in the window form application/GUI.
Anybody help me please. I don't know what am I doing. This school assignment due tomorrow.
I get errors
Error 1 No overload for 'GetU_1' matches delegate 'System.Threading.ThreadStart'
Error 2 No overload for 'GetU_2' matches delegate 'System.Threading.ThreadStart'
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace MCConsole2
{
public class MultiThreading
{
public int M, N;
public double S, sig, dt, r;
public bool iscall;
public double[] U_1, U_2;
MultiThreading MT = new MultiThreading();
public double []ComputeU(double S, double K, double sig, double dt, double r, int M, int N, bool iscall)
{
Thread U_1Thread = new Thread(new ThreadStart(GetU_1));
Thread U_2Thread = new Thread(new ThreadStart(GetU_2));
U_1Thread.Start();
U_2Thread.Start();
U_1Thread.Join();
U_2Thread.Join();
double []U=new double [M];
int a, b;
for (a = 0; a < M; a++)
{
if (a < M / 2)
{
U[a]=U_1[a];
}
else
{
U[a]=U_2[a-(M/2)];
}
}
return U;
}
public void GetU_1 (double S,double K,double sig,double dt,double r,int M,int N,bool iscall)
{
Random rnd = new Random();
int row, col, row1, col1, row2;
double[,] rand = new double[M/2, N];
for (row = 0; row < M/2; row++)
for (col = 0; col < N; col++)
{
rand[row, col] = Math.Sqrt(-2 * Math.Log(rnd.NextDouble())) * Math.Sin(2 * Math.PI * rnd.NextDouble());//Using Box Muller Random Method.
}
//rand = random number matrix
double[,] pxs = new double[M/2, N];
for (row1 = 0; row1 < M/2; row1++)
{
pxs[row1, 0] = S;
}
for (row1 = 0; row1 < M/2; row1++)
for (col1 = 1; col1 < N; col1++)
{
pxs[row1, col1] = pxs[row1, col1 - 1] * Math.Exp(((r - (Math.Pow(sig, 2)) / 2) * dt) + (sig * Math.Sqrt(dt) * rand[row1, col1]));
}
//pxs = price path
double[] U_1 = new double[M / 2];
for (row2 = 0; row2 < M / 2; row2++)
{
if (iscall == true)
{
U_1[row2] = Math.Max(0, pxs[row2, N - 1] - K);
}
else
{
U_1[row2] = Math.Max(0, K - pxs[row2, N - 1]);
}
}
// U_1 = Last column after apply in pay-off function
}
public void GetU_2 (double S, double K, double sig, double dt, double r, int M, int N, bool iscall)
{
Random rnd = new Random();
int row, col, row1, col1, row2;
double[,] rand = new double[M / 2, N];
for (row = 0; row < M / 2; row++)
for (col = 0; col < N; col++)
{
rand[row, col] = Math.Sqrt(-2 * Math.Log(rnd.NextDouble())) * Math.Sin(2 * Math.PI * rnd.NextDouble());//Using Box Muller Random Method.
}
//rand = random number matrix
double[,] pxs = new double[M / 2, N];
for (row1 = 0; row1 < M / 2; row1++)
{
pxs[row1, 0] = S;
}
for (row1 = 0; row1 < M / 2; row1++)
for (col1 = 1; col1 < N; col1++)
{
pxs[row1, col1] = pxs[row1, col1 - 1] * Math.Exp(((r - (Math.Pow(sig, 2)) / 2) * dt) + (sig * Math.Sqrt(dt) * rand[row1, col1]));
}
//pxs = price path
double[] U_2 = new double[M / 2];
for (row2 = 0; row2 < M / 2; row2++)
{
if (iscall == true)
{
U_2[row2] = Math.Max(0, pxs[row2, N - 1] - K);
}
else
{
U_2[row2] = Math.Max(0, K - pxs[row2, N - 1]);
}
}
// U_2 = Last column after apply in pay-off function
}
}
}