Skip to Content
Python算法交易
book

Python算法交易

by Yves Hilpisch
November 2022
Intermediate to advanced
392 pages
10h 8m
Chinese
China Electric Power Press Ltd.
Content preview from Python算法交易
Python
和算法交易
|
13
些任务又可能需要在一定期限内完成数百万次模拟,通常几乎是实时或者至少是近
实时的。而
Python
作为一种解释性的高级编程语言,并没有被设计为能以足够快的
速度处理这样的计算任务的。
1.1.2 NumPy
和向量化
在
2006
年,
Travis Oliphant
发行了
NumPy
Python
软件包的
1.0
版(
http://numpy.
org
)。
NumPy
的意思是数值
Python
,表明它是专门针对有严格数值要求应用场景的。
基本的
Python
解释器试图在许多方面尽可能地通用,这通常会在运行时导致相当多
的开销。
注
3
另一方面,
NumPy
主要使用专门的方式作为其避免开销并尽可能在某些
应用程序场景中让自己又快又好。
NumPy
的主要类是常规数组对象,称为
n
维数组的
ndarray
对象。它是不可变的,
这意味着它的大小无法更改,并且只能容纳称为
dtype
的一个数据类型。这种专门
的优化可以让代码更简洁而快速。在这种情况下,一种主要方法是矢量化。基本上,
这种方法避免了在
Python
级别的循环,而将循环委托给专用的
NumPy
代码,通常以
C
语言实现,因此速度相当快。
考虑使用纯
Python
根据式(
1-1
)模拟
1000000
个周期末值
S
T
。以下代码的主要部
分是具有
1000000
次迭代的
for
循环。
In [1]: %%time
import random
from math import exp, sqrt
S0 = 100
r = 0.05 ...
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

人工智能技术与大数据

人工智能技术与大数据

Posts & Telecom Press, Anand Deshpande, Manish Kumar
图解大模型 : 生成式AI 原理与实战

图解大模型 : 生成式AI 原理与实战

Jay Alammar, Maarten Grootendorst

Publisher Resources

ISBN: 9787519869694