s_normalcdf.m
来自「经济学专业代码」· M 代码 · 共 29 行
M
29 行
% this script computes the cdf of a bivariate normal distribution at a grid of points
% see "Risk and Asset Allocation"-Springer (2005), by A. Meucci
clear; clc; close all;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% input parameters
m=[0 0];
s=[1 1];
r=.5;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% input generate grid according to natural disribution's limits
C=[1 r;
r 1];
S=diag(s)*C*diag(s);
Y=mvnrnd(m,S,50);
Grid1=[min(Y(:,1)) : (max(Y(:,1))-min(Y(:,1)))/25 : max(Y(:,1))];
Grid2=[min(Y(:,2)) : (max(Y(:,2))-min(Y(:,2)))/25 : max(Y(:,2))];
mu = [1 -1]; Sigma = [.9 .4; .4 .3];
[X1,X2] = meshgrid(Grid1,Grid2);
X = [X1(:) X2(:)];
f = mvncdf(X, m, S);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% plot
surf(X1,X2,reshape(f,length(Grid2),length(Grid1)));
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?