当前位置: 首页 > article >正文

MATLAB实现历史模拟法计算VaR(Value at Risk)

MATLAB实现历史模拟法计算VaR(Value at Risk)

历史模拟法(Historical Simulation Method)是一种用于计算风险值(Value at Risk, VaR)的非参数方法。它基于过去的资产价格或收益数据来估计未来的潜在损失。

MATLAB代码如下:

 完整代码见: https://download.csdn.net/download/corn1949/90005834

clc;close all;clear all;warning off;% clear all
rand('seed', 100);
randn('seed', 100);
format long g;

pricemat = [100, 101, 102, 99, 98, 100, 103, 105, 104, 102,105,106,106,108.5,103,110,112,135,100,111,112,113,95,96,96,98]';% 价格数据
returnmat = (pricemat(2:end)-pricemat(1:end-1)) ./ pricemat(1:end-1);% 计算收益率

% 设定置信水平(例如90%或99%等)
confidence_level = 0.90;
% 计算VaR所需的分位数(例如,对于95%的置信水平,分位数为5%)
quantile = 1 - confidence_level;

%% 方法1 排序法
% 对收益率进行排序
sorted_returns = sort(returnmat);

% 找到对应的分位数位置的收益率
% var_index = round(quantile * length(sorted_returns));
var_index = ceil(quantile * length(sorted_returns));

% VaR值(注意:这是负值,表示潜在的损失)
var_value = -sorted_returns(var_index);


%% 方法2 

%% 绘图



MATLAB程序结果如下:

在90%的置信水平下,VaR为: 0.05
在90%的置信水平下,VaR为: 0.05
>> 

完整代码见: https://download.csdn.net/download/corn1949/90005834


http://www.kler.cn/a/398620.html

相关文章:

  • [Meachines] [Hard] Yummy 任意文件下载+JWT签名绕过+SQLI+定时任务劫持+hg权限提升+rsync权限提升
  • Scala的Array(1)
  • 服务端高并发分布式结构进阶之路
  • QEMU 模拟器中运行的 Linux 系统
  • word 中长公式换行 / 对齐 | Mathtype 中长公式换行拆分 | latex 中长公式换行
  • linux笔记(防火墙)
  • 常见的压缩数据结构
  • 软考之面向服务架构SOA-通信方法
  • DP动态规划基础题(Kadane算法)
  • springboot vue海洋馆预约系统源码和答辩PPT论文
  • PostgreSQL学习总结(13)—— PostgreSQL 15.8 如何成就数据库性能王者?
  • 【MySQL】MySQL数据库入门:构建你的数据基石
  • scp命令详解
  • 树状数组+概率论,ABC380G - Another Shuffle Window
  • ZooKeeper单机、集群模式搭建教程
  • 力扣 LeetCode 145. 二叉树的后序遍历(Day6:二叉树)
  • 读书笔记《Lean In 向前一步》
  • SpringBoot接收前端传递参数
  • C++设计思想-001-设计模式-单例模式
  • Controller Baseband commands速览