我试图在Python中模拟几何布朗运动,通过蒙特卡罗模拟为欧洲看涨期权定价.我对Python比较陌生,而且我收到一个我认为错误的答案,因为它无法收敛到BS价格,并且由于某种原因迭代似乎是负面趋势.任何帮助,将不胜感激.
import numpy as np
from matplotlib import pyplot as plt
S0 = 100 #initial stock price
K = 100 #strike price
r = 0.05 #risk-free interest rate
sigma = 0.50 #volatility in market
T = 1 #time in years
N = 100 #number of steps within each simulation
deltat = T/N #time step
i = 1000 #number of simulations
discount_factor = np.exp(-r*T) #discount factor
S = np.zeros([i,N])
t = range(0,N,1)
for y in range(0,i-1):
S[y,0]=S0
for x in range(0,N-1): …Run Code Online (Sandbox Code Playgroud) 我在编写打印矩阵的程序时遇到问题,然后生成单位矩阵.这是我的下面的ccode,任何帮助将不胜感激.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int PrintMatrix(int dim, double matrix[dim][dim]);
int main()
int PrintMatrix(int dim, double matrix[dim][dim]) {
int aa, bb;
for (aa = 0; aa <= dim; aa++) {
for (bb = 0; bb <= dim; bb++) {
printf("%lf ", matrix[aa][bb]);
}
printf("\n");
}
}
double TestMatrix[7][7] = {
{1,0,0,0,0,0,0},
{0,1,0,0,0,0,0},
{0,0,1,0,0,0,0},
{0,0,0,1,0,0,0},
{0,0,0,0,1,0,0},
{0,0,0,0,0,1,0},
{0,0,0,0,0,0,1}
};
PrintMatrix(7, TestMatrix);
return 0;
Run Code Online (Sandbox Code Playgroud)