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算法交易
掌握向量化回测
|
103
In [17]: a.mean(axis=0)
Out[17]: array([4.5, 5.5, 6.5])
In [18]: np.mean(a, axis=1)
Out[18]: array([ 1., 4., 7., 10.])
通过方法调用计算所有元素的平均值。
通过通用函数计算所有元素的平均值。
计算沿第一个轴的平均值。
计算沿第二个轴的平均值。
作为金融方面的示例,请考虑“
Python
脚本”中的函数
generate_sample_data()
,
该函数使用欧拉离散化生成几何布朗运动的样本路线。该实现利用了多个向量化操
作,这些操作被组合到一行代码中。
有关使用
NumPy
进行向量化的更多详细信息,请参见附录。请参阅
Hilpisch
(
2018
),
以了解金融环境中向量化的众多应用。
Python
的标准指令集和数据模型通常不允许进行向量化数值运算。
NumPy
引入了基于常规数组类
ndarray
的强大向量化技术,这些技术带
来了接近数学符号的简洁代码,例如关于向量和矩阵的线性代数。
4.1.2
使用
pandas
进行向量化
pandas
包和
DataFrame
类大量使用了
NumPy
和
ndarray
类。因此,在
NumPy
上下文
中看到的大多数向量化原理都可以延续到
pandas
身上。这个机制可以通过具体的示
例很好的解释。我们首先定义一个二维
ndarray
对象来开始这个示例:
In [19]: a = np.arange(15).reshape(5, 3)
In [20]: ...
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