ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

Derivatives analytics with python ---- Part 1

2021-05-06 16:33:37  阅读:328  来源: 互联网

标签:Derivatives plt python value ---- vol call np import


Derivatives analytics with python ---- Part 1

Market-based Valuation

This is a book that I think really helpful and practical to our quant work. But the python code in it is outdated, and some of them are missing the important parts, so from now on, I will use the mindmap to structure the knowledge in it and rewrite the codes in python 3.7. I hope this can help more people.

This is the overall structure of this book and it is also the information from the first chapter.

Mindmap

在这里插入图片描述

European Call Option Inner Value Plot

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.rcParams['font.family'] = 'serif'

# Option Strike
K = 8000
# Graphical Output
S = np.linspace(7000, 9000, 100) # index level values
h = np.maximum(S - K, 0) # inner values of call option
plt.figure()
plt.plot(S, h, lw=2.5) # plot inner values at maturity
plt.xlabel('index level $S_t$ at maturity')
plt.ylabel('inner value of European call option')
plt.grid(True)

在这里插入图片描述

European Call Option Value Plot

# first, define the valuation formula for European Call option
import numpy as np
import scipy.stats as si
import sympy as sy
from sympy.stats import Normal, cdf
def BSM_call_value(S0, K, q, T, r, vol):
    # q denotes the dividend rate
    d1 = (np.log(S / K) + (r - q + 0.5 * vol ** 2) * T) / (vol * np.sqrt(T))
    d2 = (np.log(S / K) + (r - q - 0.5 * vol ** 2) * T) / (vol * np.sqrt(T))
    call = (S * np.exp(-q * T) * si.norm.cdf(d1, 0.0, 1.0) - K * np.exp(-r * T) * si.norm.cdf(d2, 0.0, 1.0))
    return call
import sys
sys.path.append('05_com')
# Model and Option Parameters
K = 8000 # strike price
T = 1.0 # time-to-maturity
r = 0.025 # constant, risk-less short rate
vol = 0.2 # constant volatility
# Sample Data Generation
S = np.linspace(4000, 12000, 150) # vector of index level values
h = np.maximum(S - K, 0) # inner value of option
C = [BSM_call_value(S0, K, 0, T, r, vol) for S0 in S][0]
# calculate call option values
# Graphical Output
plt.figure()
plt.plot(S, h, 'b-.', lw=2.5, label='inner value')
# plot inner value at maturity
plt.plot(S, C, 'r', lw=2.5, label='present value')
# plot option present value
plt.grid(True)
plt.legend(loc=0)
plt.xlabel('index level $S_0$')
plt.ylabel('present value $C(t=0)$')
plt.show()

在这里插入图片描述

标签:Derivatives,plt,python,value,----,vol,call,np,import
来源: https://blog.csdn.net/weixin_42494663/article/details/116448096

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有