美文网首页
2018-03-29 开胃学习数学系列 - 蒙特卡洛

2018-03-29 开胃学习数学系列 - 蒙特卡洛

作者: Kaiweio | 来源:发表于2018-03-30 00:10 被阅读0次

    Lecture 6: Monte Carlo

    蒙特卡洛方法就是通过大量的随机样本,去了解一个系统,得到所要计算的值。
    获得的值不一定是真值,样本量越大,模拟出来的值越接近。

    Topics:

    • Foundation of Monte Carlo
    • Random number generation
    • Discretize stochastic processes
    • Least square MC

    Introduction

    Monte Carlo simulation:

    • one of the most important and widely used numerical methods in scientific computing
    • invented in the 40s, born with computers
      • first used in Mahattan project, then for the development of Hydrogen bomb
    • widely used in quantitative finance, more popular recently with the rise of GPUs

    A classic example

    Compute the value of π using Monte Carlo:

    %pylab inline
    
    import pandas as pd
    import numpy  as np
    import sys
    import fmt
    
    def sim_pi(ns) :
        es = np.random.uniform(size=[ns[-1], 2])
        d = np.array([x*x + y*y < 1. for x, y in es])
        
        return np.array([4.*np.sum(d[:n])/n for n in ns])
    
    ns = 4**(np.arange(8))*100
    ps = sim_pi(ns)
    

    Population and samples

    • 我并不了解这里为什么用了一个μ1

    Sample mean

    • 样本均值
    • 样本均值的无偏估计
    • 为什么要写成 1转置

    Sample standard deviation

    • s 尖是标准差的估计量
    • s 尖服从 卡方分布,在n变大时变成正态
    • 根据琴生不等式,有最后的结论

    Variance of sample variance

    Monte Carlo error

    Std dev of sample std dev

    样本标准差的标准差


    Population and sample statistics

    下面是求圆周率的实例:


    μ4的化简没有完全理解
    1的概率和就是1。

    下面这部分再次对应公式



    var_var 使用上述完整的公式, std用了上面表格里近似的公式。
    作图说明了随机变量的个数和均值方差/标准差,样本标准差的方差/标准差的关系。

    # μ,σ方,μ4
    u = np.pi/4
    v = u*(1-u)
    u4 = np.pi/4*(1-np.pi/4)**4 + (1.-np.pi/4)*(np.pi/4)**4
    
    
    ns = 2**(np.arange(1, 14)) # ns 是 number of random samples
    var_u = v/ns 
    var_var = (u4 - v*v*(ns-3)/(ns-1))/ns
    # 公式如上
    
    beta = u4/v**2
    
    fig = figure(figsize=[12, 4])
    subplot(1, 2, 1)
    loglog(ns, np.transpose([var_u, var_var]), '.-')
    legend(['var of $\hat \mu$', 'var of $\hat s^2$']);
    xlabel('Number of random samples')
    title('Sample Variance');
    
    ax = fig.add_subplot(122)
    # 了解一下add_subplot 的参数和 subplot一样
    loglog(ns, np.transpose([np.sqrt(var_u), np.sqrt((beta-1.)/4./ns)*np.sqrt(v)]), '.-');
    title('Error Estimate')
    legend(['std of mean', 'std of $\hat s$'], loc='best');
    xlabel('Number of random samples');
    
    • prudent to monitor the error of MC error (most people don't). 监测MC error的error很重要(大多数人不会)
    • the err of MC err is more pronounced for fat tailed distributions, with large β. MC error的error 对β较大的 肥尾分布更为明显























    Estimate mean and volatility

    • 有10年的daily return,ri
    • 有sigma 25%
    • 有回报的分布是正太的,β = 3
    • 历史均值估计值 u尖 = 1/n * ri求和
    • 历史均值的标准差 std(μ尖) = sigma / sqrt(10) = 0.079
    • 因为 只有10个独立的样本,所以误差很大
    • 几遍使用日回报也没有帮助, std(μ尖) = 250 * sigma/sqrt(250) / sqrt(10*250) = 0.079
    • vol 则是 日回报ri 的 标准差 s 的 误差? [不确定这个说法]
    • 代入公式 得到非常小的值,所以准确 [这个准确有何意义?已经不是 std了啊?]

    Batching

    • ceteris paribus是指 “在其他条件都不变的情况下”

    Why Monte Carlo?



    在物理学发展的现阶段,计算高维积分唯一的普遍方法,是Monte Carlo.

    当积分区域的维数小于4时,用均匀网格计算积分的方法收敛速度更快,当维数大于4时,Monte Carlo方法的收敛速度更快,而当维数等于4时,两种方法不分高下,. 而计算高维积分时,Monte Carlo 方法是较优的选择。
    Monte Carlo 方法 (一)
















    Curse of dimensionality

    在金融中,我们仅此进入高维领域,每一个随机性来源都是一个单独的维度,every source of randomness is a separate dimension:

    产品 维度
    利率 LMM模型3M转发高达30Y
    篮子选项basket options 往往有几十个名字
    合成CDO synthetic CDOs 投资组合中的数百个发行人
    抵押证券mortgage securities 每月付款,最多30年

    大多数数值方法numerical methods 在高维high dimensionality 上失败

    • PDE:4维是practical limit
    • 树:很少超过3个维度
    x = np.arange(0, 10)*.1
    y = np.arange(0, 10)*.1
    xm, ym = np.meshgrid(x, y)
    
    figure(figsize=[12, 4])
    subplot(1, 2, 1)
    plot(xm, ym, '.');
    xlabel('x')
    ylabel('y')
    title('100 Grid Samples');
    
    subplot(1, 2, 2)
    xs = np.random.uniform(size=[2, 100])
    plot(xs[0,:], xs[1,:], '.');
    title('100 Random Samples');
    xlabel('x')
    ylabel('y');
    
    image.png

    Monte Carlo is effective in combating high dimensions:

    • the same set of random samples cover all dimensions equally

    ℚ measure applications

    • m(t) 是计价证券,ℚ 是 measure induced by the numerarie 计价的m(t)
    • 经常用于高维度的奇异期权和 路径依赖的衍生品 exotic and path dependent derivatives

    XVA adjustments: CVA/FVA/DVA

    • an active research area
    • XVAs can be expressed in expectations

    CVA:当交易对手违约了,我的损失是多少。【条件期望】
    DVA:当我违约了,我的对手损失是多少。【条件期望】
    衍生品价值=无信用风险衍生品价值-CVA+DVA .

    ℙ measure applications

    Market Risk
    Value at Risk: ℙ[v(T)<VaRα]=𝔼t[1l(v(T)<VaRα)]=α
    完全不懂这句话的意思
    Counterparty credit risk:
    EE (expected exposure): et=𝔼[max(vt,0)]=𝔼[vt1(vt>0)]
    完全不懂这句话的意思
    PFE (potential future exposure): ℙ[vt1(vt>0)<PFEα]=α
    完全不懂这句话的意思
    Capital allocation
    a new area where the MC method is successfully applied

    这个1是什么意思

    Advantages of Monte Carlo

    Monte Carlo被广泛用于定量金融有很好的理由:

    • dimensionality independent
    • generic: widely applicable 广泛适用
    • robust: can handle complicated payoff 健壮可以处理复杂的收益
    • easy to implement and modify易于实施和修改
    • precise error estimate 精确的误差估计
    • easy to add more samples on the fly 易于添加更多样品
    • can be made very fast for many problems (next lecture)
      可以很快解决很多问题(下一讲)
    • often used to test more advanced pricing technique, like PDE
      通常用于测试更高级的定价技术,如PDE





















































    相关链接:

    中心矩维基
    中心矩百度
    维基 - 辛普森积分法
    油管 - 辛普森积分法

    Monte Carlo 方法 (一)
    蒙特卡洛算法
    这个帖子里面用蒙特卡洛求 e 1 - 2 积分的例子有学习价值

    相关文章

      网友评论

          本文标题:2018-03-29 开胃学习数学系列 - 蒙特卡洛

          本文链接:https://www.haomeiwen.com/subject/kvmpcftx.html