Skip to Content
Python for Finance(第二版)
book

Python for Finance(第二版)

by Yves Hilpisch
May 2025
Intermediate to advanced
720 pages
10h 7m
Chinese
O'Reilly Media, Inc.
Content preview from Python for Finance(第二版)

第 18 章 模拟财务模型 金融模型模拟

本作品已使用人工智能进行翻译。欢迎您提供反馈和意见:translation-feedback@oreilly.com

科学的目的不是分析或描述,而是为世界建立有用的模型。

爱德华-德博诺

第 12 章较为详细地介绍了 使用 Python 和NumPy 对随机过程进行蒙特卡罗仿真。本章将应用其中介绍的基本技术来实现仿真类,作为DX 软件包的核心组件。随机过程的集合仅限于三种广泛使用的随机过程。本章主要包括以下几节:

"随机数生成"

本节将开发一个函数,利用方差缩小技术生成标准正态分布随机数。1

"通用模拟类"

本节将开发一个通用模拟类,其他具体模拟类将从该类继承基本属性和方法。

"几何布朗运动"

本节将介绍几何布朗运动(GBM),它是通过布莱克和斯科尔斯(1973)以及默顿(1973) 的开创性著作而被引入期权定价文献的;在本书中多次使用,尽管它有众所周知的缺点, 而且有越来越多的经验证据表明它是期权和衍生品估值的基准过程。

"跳跃扩散"

默顿(Merton,1976 年)将跳跃扩散引入金融领域,为 GBM 增加了对数正态分布的跳跃成分。例如,短期价外(OTM)期权通常似乎已经考虑到了更大跳跃的可能性;换句话说,依靠 GBM 作为金融模型往往无法令人满意地解释这种 OTM 期权的市场价值,而跳跃扩散则可以做到这一点。

"方根扩散"

考克斯、英格索尔和罗斯(1985 年)在金融学中推广的平方根扩散法被用来模拟利率和波动率等均值回复量;除了均值回复外,该过程还保持正值,这通常是这些量的理想特征。

有关本章介绍的模型模拟的更多细节,请参阅 Hilpisch (2015)。特别是,该书包含了基于 Merton(1976 年)的跳跃扩散模型的完整案例研究。

随机数生成

随机数生成 是蒙特卡罗模拟的核心任务。2第 12 章介绍了如何使用 Python 和numpy.random 等子包生成不同分布的随机数。对于手头的项目,标准正态分布随机数是最重要的。这就是为什么这里定义的方便函数sn_random_numbers() 可以用来生成这种特殊类型的随机数:

#
# DX Package
#
# Frame -- Random Number Generation
#
# sn_random_numbers.py
#
# Python for Finance, 2nd ed.
# (c) Dr. Yves J. Hilpisch
#
import numpy as np


def sn_random_numbers(shape, antithetic=True, moment_matching=True,
                      fixed_seed=False):
    ''' Returns an ndarray object of shape shape with (pseudo)random numbers
    that are standard normally distributed.

    Parameters
    ==========
    shape: tuple (o, n, m)
        generation of array with shape (o, n, m)
    antithetic: Boolean
        generation of antithetic variates
    moment_matching: Boolean
        matching of first and second moments
 fixed_seed: ...
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.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Python 中的金融理论

Python 中的金融理论

Yves Hilpisch
Python for Finance

Python for Finance

Yves Hilpisch

Publisher Resources

ISBN: 9798341657397