2018-04-16 开胃学习金融系列 - Incremental Risk Charge Model

IRC可以直接使用straight MC来计算。我们可以生成了大量的PnL scenarios,并读出了99.9% quantile,为了估计MC错误,我们必须应用批处理apply batching(为什么?原因求解)

straight MC的收敛缓慢:only a small percentage of the scenarios hit the 99.9% tail.

nn, rho = 100, .7
# MC路径
nsim = 40000
p = .99*np.ones(nn)
p[:5] = .95
b = 20
lgdl = 5e6
lgdh = 9e6
def irc0(nsim) :
    # (101, 40000) 的随机array
    es = np.random.normal(size=[nn+1, nsim])
    
    # (100, 40000) 的随机array,再做了转置(40000, 100)
    xs = np.array([np.sqrt(rho)*es[0, :] + np.sqrt(1-rho)*e for e in es[1:, :]]).T
    
    #(40000,) 的随机array,5e6 至 9e6之间
    lgd = np.random.uniform(lgdl, lgdh, size=nsim)

    # 比较 p=0.99 和 xs的大小球相互违约概率, 求出违约的损失PnL
    pnls = np.sum(np.greater(norm.cdf(xs), p), 1)*lgd
    
    # 返回的是99.9 的损失percentile
    return np.percentile(pnls, 99.9), pnls

tic = time.clock()
# 前20个的percentile
ircs0 = [(irc0(nsim))[0] for i in range(b)]
t0 = time.clock() - tic

运行时间大概是10秒,返回了20个percentile

df = pd.DataFrame([nsim, np.mean(ircs0), np.std(ircs0)/np.mean(ircs0), t0/b], 
                  index=['paths', 'value', 'rel error', 'run time(s)'], 
                  columns=['IRC'])
fmt.displayDF(df.T, "3g", 4)  

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,449评论 0 10
  • A城出事了,最近不知从哪里传出的消息,城内几大媒体都在热火朝天的争相报道,但究竟事情的来龙去脉如何,竟没有一家电视...
    peter_yuan_93阅读 395评论 0 2
  • ——天材 最难过的关就是“情关”。 成功和健康、两性关系似乎没有直接的关系。 今天结合最好的理论和最好的实践跟大家...
    草原露珠阅读 293评论 0 0
  • 好命名胜于任何注释— 51CTO/至简李云 编程过程中使用单词缩写可以提高效率,本文则记录 Android 开发中...
    By_syk阅读 920评论 0 1