Skip to Content
金融人工智能:用Python实现AI量化交易
book

金融人工智能:用Python实现AI量化交易

by Yves Hilpisch
August 2022
Intermediate to advanced
394 pages
12h 32m
Chinese
Posts & Telecom Press
Content preview from 金融人工智能:用Python实现AI量化交易
风险管理
253
11.2
 向量化回测
向量化回测不能直接应用于交易机器人。第
10
章使用
DNN
说明过该方法。在这种情况
下,首先准备好具有特征和标签子集的数据,然后将其输入
DNN
模型以立即生成所有预
测。在强化学习环境中,数据是通过一步一步地与环境交互来生成和收集的。
为此,下面的
Python
代码定义了
backtest
函数,该函数将
TradingBot
实例和
Finance
例作为输入。它在
Finance
环境列的原始
Data Frame
对象中生成了交易机器人所持有的头
寸和最终策略收益。
In [14]: def reshape(s):
return np.reshape(s, [1, learn_env.lags,
learn_env.n_features])
In [15]: def backtest(agent, env):
env.min_accuracy = 0.0
env.min_performance = 0.0
done = False
env.data['p'] = 0
state = env.reset()
while not done:
action = np.argmax(
agent.model.predict(reshape(state))[0, 0])
position = 1 if action == 1 else -1
env.data.loc[:, 'p'].iloc[env.bar] = position
state, reward, ...
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机器学习案例精解

Posts & Telecom Press, Yuxi (Hayden) Liu
解密金融数据

解密金融数据

Justin Pauley
Python3.0科学计算指南

Python3.0科学计算指南

Posts & Telecom Press, Claus Führer, Jan Erik Solem, Olivier Verdier
scikit-learn机器学习(第2版)

scikit-learn机器学习(第2版)

Posts & Telecom Press, Gavin Hackeling

Publisher Resources

ISBN: 9787115594556