Skip to Content
Python金融实战
book

Python金融实战

by Posts & Telecom Press, Yuxing Yan
February 2024
Intermediate to advanced content levelIntermediate to advanced
347 pages
5h 19m
Chinese
Packt Publishing
Content preview from Python金融实战

第10章 Python的循环语句和隐含波动率的计算

本章主要内容涉及两个主题:Python的循环语句和隐含波动率的计算。Python有两个最常用的循环语句:for循环和while循环。将介绍隐含波动率的定义及其背后的逻辑,然后讨论3种计算隐含波动率的方法,分别基于for循环、while循环和二分搜索。二分搜索是其中最有效的方法。应用二分搜索方法的一个前提条件是目标函数单调递增或递减,而期权价格恰恰是波动率的递增函数。本章包括以下主要内容。

  • 什么是隐含波动率
  • 隐含波动率计算的逻辑
  • 理解for循环、while循环及其应用
  • 嵌套(多重)循环
  • 多个IRR的估计
  • 二分搜索方法的原理
  • 计算美式看涨期权的隐含波动率
  • enumerate()函数简介
  • 从Yahoo!Finance和芝加哥期权交易所获取期权数据
  • 以图形表示看跌期权和看涨期权的比率

在第9章中,我们了解到给定一组输入参数S(当前股票价格)、X(执行价格)、T(以年为单位的有效期)、r(连续复利的无风险利率)和sigma(股票回报率的标准方差,也称为波动率)可以利用Black-Scholes-Merton模型来计算看涨期权的价格。可以用以下5行Python代码来为欧式看涨期权定价。

from scipy import log,exp,sqrt,stats 
def bs_call(S,X,T,r,sigma):
  d1=(log(S/X)+(r+sigma*sigma/2.)*T)/(sigma*sqrt(T))
  d2 = d1-sigma*sqrt(T)
  return S*stats.norm.cdf(d1)-X*exp(-r*T)*stats.norm.cdf(d2)

输入一组5个值后,可以得到看涨期权的价格如下。 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

实时数据处理和分析指南

实时数据处理和分析指南

Posts & Telecom Press, Shilpi Saxena, Saurabh Gupta
数据科学实战手册(R+Python)(第2版)

数据科学实战手册(R+Python)(第2版)

Posts & Telecom Press, Prabhanjan Narayanachar Tattar, Tony Ojeda, Sean Patrick Murphy, Sean P Murphy, Benjamin Bengfort, Bengfort Benjamin, ABHIJIT DASGUPTA
Python应用开发指南

Python应用开发指南

Posts & Telecom Press, Ninad Sathaye
编写整洁的Python代码(第2版)

编写整洁的Python代码(第2版)

Posts & Telecom Press, Mariano Anaya

Publisher Resources

ISBN: 9781803230375