コード例 #1
0
ファイル: VGFiniteDiff.cs プロジェクト: yuxi214/QuantSys
        private double vgB(int j)
        {
            //Calculates the B coefficient at each step
            double u1 = NR.Expint(1, j * deltS * lambda_n);
            double u2 = NR.Expint(1, (M - j) * deltS * lambda_p);

            return(1 + r * deltT + Bn + Bp + (deltT / nu) * (u1 + u2));
        }
コード例 #2
0
ファイル: VGFiniteDiff.cs プロジェクト: yuxi214/QuantSys
        private void PrepPreCalc()
        {
            //Pre-calculates the four main vectors based on expint
            expintN    = new double[M + 1];
            expintP    = new double[M + 1];
            expLambdaN = new double[M + 1];
            expLambdaP = new double[M + 1];

            for (int k = 0; k < M + 1; k++)
            {
                expintN[k]    = NR.Expint(1, (k + 1) * deltS * lambda_n);
                expintP[k]    = NR.Expint(1, (k + 1) * deltS * lambda_p);
                expLambdaN[k] = Math.Exp(-lambda_n * (k + 1) * deltS);
                expLambdaP[k] = Math.Exp(-lambda_p * (k + 1) * deltS);
                spotPrice[k]  = Math.Exp(x_index[k]);
            }
        }
コード例 #3
0
ファイル: VGFiniteDiff.cs プロジェクト: yuxi214/QuantSys
        private double vgH(int l, int j, int i)
        {
            //Calculates the Heaviside term at each step, takes the exercise boundary as input from the x_j function
            double sum1 = 0, sum2 = 0;
            double u1 = r * K - q * spotPrice[j];

            if (l <= j)
            {
                return(0);
            }

            for (int k = l - j; k <= M - j - 1; k++)
            {
                sum1 += (1 / nu) * (mainGrid[j + k, i] - k * (mainGrid[j + k + 1, i] - mainGrid[j + k, i])) * (expintP[k - 1] - expintP[k]);
            }
            for (int k = l - j; k <= M - j - 1; k++)
            {
                sum2 += ((mainGrid[j + k + 1, i] - mainGrid[j + k, i]) / (lambda_p * nu * deltS)) * (expLambdaP[k - 1] - expLambdaP[k]);
            }

            double u2 = (1 / nu) * (K * NR.Expint(1, (l - j) * deltS * lambda_p) - spotPrice[j] * NR.Expint(1, (l - j) * deltS * (lambda_p - 1)));

            return(u1 - sum1 - sum2 + u2);
        }
コード例 #4
0
ファイル: VGFiniteDiff.cs プロジェクト: yuxi214/QuantSys
        private double vgR(int j, int i)
        {
            //Calculates the R coefficient at each step
            double sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0;

            for (int k = 1; k <= j - 1; k++)
            {
                sum1 += (mainGrid[j - k, i] - mainGrid[j, i] - k * (mainGrid[j - k - 1, i] - mainGrid[j - k, i])) * (expintN[k - 1] - expintN[k]);
            }
            for (int k = 1; k <= j - 1; k++)
            {
                sum2 += ((mainGrid[j - k - 1, i] - mainGrid[j - k, i]) / (lambda_n * deltS)) * (expLambdaN[k - 1] - expLambdaN[k]);
            }
            for (int k = 1; k <= M - j - 1; k++)
            {
                sum3 += (mainGrid[j + k, i] - mainGrid[j, i] - k * (mainGrid[j + k + 1, i] - mainGrid[j + k, i])) * (expintP[k - 1] - expintP[k]);
            }
            for (int k = 1; k <= M - j - 1; k++)
            {
                sum4 += ((mainGrid[j + k + 1, i] - mainGrid[j + k, i]) / (lambda_p * deltS)) * (expLambdaP[k - 1] - expLambdaP[k]);
            }

            return(sum1 + sum2 + sum3 + sum4 + (K * NR.Expint(1, j * deltS * lambda_n)) - (spotPrice[j] * NR.Expint(1, j * deltS * (lambda_n + 1))));
        }