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(第二版)

第 6 章 面向对象编程 面向对象编程

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

软件工程的目的是控制复杂性,而不是创造复杂性。

帕梅拉-扎夫

面向对象编程(OOP) 是当今最流行的编程范式之一。与程序化编程等相比,以正确的方式使用面向对象编程具有许多优势。在许多情况下,OOP 似乎特别适用于金融建模和金融算法的实施。然而,也有许多批评者对OOP的某些方面甚至整个范式表示怀疑。本章采取中立的立场,认为OOP是一种重要的工具,它可能不是解决每一个问题的最佳工具,但却是从事金融工作的程序员和经济学家应该掌握的工具。

OOP,一些新的语言也随之出现。就本书和本章而言,最重要的术语是(稍后将详细介绍):

班级

对某类对象的抽象 定义。例如,人。

对象

一个类的 实例。例如,Sandra.

属性

类(类属性)或类的实例(实例属性)的特征。例如,哺乳动物、男性或女性或眼睛的颜色。

方法

类或类的实例可以实现的 操作。例如,行走。

参数

输入 ,由方法影响其行为。例如,三个步骤。

实例化

基于抽象类创建特定对象的过程。

将 转换成 Python 代码,一个实现人类示例的简单类可能如下所示:

In [1]: class HumanBeing(object):  1
            def __init__(self, first_name, eye_color):  2
                self.first_name = first_name  3
                self.eye_color = eye_color  4
                self.position = 0  5
            def walk_steps(self, steps):  6
                self.position += steps  7

类定义语句;self 指类的当前实例。

在实例化过程中调用的特殊方法。 ...

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