Value at Risk Practical

download Value at Risk Practical

of 2

Transcript of Value at Risk Practical

  • 8/10/2019 Value at Risk Practical

    1/2

    VALUE AT RISK: HISTORICAL SIMULATION, MONTE CARLO SIMULATION AND

    VARIANCE COVARIANCE METHODS IN MATLAB

    By JOHN MUTEBA MWAMBA

    DEPARTMENT OF ECONOMICS AND ECONOMETRICS

    UNIVERSITY OF JOHANNESBURG

    Value at risk in Matlab

    Historical Simulation: The alpha quantile

    x=retALSI %returns of your asset

    mu=mean(x)

    sigma=std(x)

    VaR.hist=quantile(x,alpha); where alpha is 95,97,99%,..

    VaR.hist=quantile(x,[0.950 0.975 0.990 0.999]) , % for historical simulation

    %X is a vector of returns. To generate for instance 10000 returns point in Matlab us this code

    %returns=normrnd(0.2,1,1,10000);

    Monte Carlo Simulation: Simulation from normal distribution

    mydata=normrnd(mu,sigma,1,5000); sigma and mu are empirical value of historical returns

    %then use VaR.hist to compute the VaR

    VAR=quantile(mydata,[0.950 0.975 0.990 0.999])

    Variance covariance method in Matlab

    %For one asset VaR=[mu+Z*sigma]

    % Different values of Z

    0.95 0.975 0.99 0.999Z 1.645 1.960 2.326 3.090

  • 8/10/2019 Value at Risk Practical

    2/2

    Z=[1.645 1.96 2.326 3.090]

    VaRCov=[mu+Z*sigma]

    %For a portfolio of more than one asset; use function portvrisk (in financial toolbox)

    %import your data in Matlab as a matrixportfo is the name of your dataset

    PortReturn=mean(mean(portfo)); % expected return of portfolio i.e. mean of portfolio returns

    PortRisk=mean(std(portfo));% stdv of portfolio I.e. stdev of portfolio returns

    RiskThreshold=[0.05;0.025;0.01;0.001]; %default alpha is 0.05

    VaRvc=portvrisk(PortReturn,PortRisk,RiskThreshold)