Overview - Loren1166/NautilusTrader- GitHub Wiki

Overview

概述

NautilusTrader is an open-source, high-performance, production-grade algorithmic trading platform, providing quantitative traders with the ability to backtest portfolios of automated trading strategies on historical data with an event-driven engine, and also deploy those same strategies live, with no code changes.
NautilusTrader 是一个开源的高性能生产级算法交易平台,为量化交易者提供了在事件驱动引擎上基于历史数据回测自动化交易策略组合的能力,同时可以在不改变代码的情况下将这些策略实时部署。

The platform is 'AI-first', designed to develop and deploy algorithmic trading strategies within a highly performant and robust Python native environment. This helps to address the parity challenge of keeping the Python research/backtest environment consistent with the production live trading environment.
该平台是“以 AI 为先”,旨在在高性能和稳健的 Python 原生环境中开发和部署算法交易策略。这有助于解决保持 Python 研究/回测环境与生产实时交易环境一致性的平衡挑战。

NautilusTrader's design, architecture, and implementation philosophy holds software correctness and safety at the highest level, with the aim of supporting Python native, mission-critical, trading system backtesting and live deployment workloads.
NautilusTrader 的设计、架构和实现理念将软件的正确性和安全性视为最高原则,旨在支持 Python 原生、关键任务的交易系统回测和实时部署工作负载。

The platform is also universal and asset class agnostic - with any REST, WebSocket or FIX API able to be integrated via modular adapters. Thus, it can handle high-frequency trading operations for any asset classes including FX, Equities, Futures, Options, CFDs, Crypto, and Betting - across multiple venues simultaneously.
该平台也是通用的,与资产类别无关——可以通过模块化适配器集成任何 REST、WebSocket 或 FIX API。因此,它可以同时处理包括外汇、股票、期货、期权、差价合约、加密货币和博彩在内的任何资产类别的高频交易操作。

Features

特性

  • Fast: C-level speed through Rust and Cython. Asynchronous networking with uvloop
  • 可靠:通过 Rust 和 Cython 实现的 C 级速度。使用 uvloop 进行异步网络
  • Reliable: Type safety through Rust and Cython. Redis backed performant state persistence
  • 可靠:通过 Rust 和 Cython 实现类型安全。基于 Redis 的高性能状态持久化
  • Flexible: OS independent, runs on Linux, macOS, Windows. Deploy using Docker
  • 灵活:操作系统独立,支持在 Linux、macOS 和 Windows 上运行。可使用 Docker 部署
  • Integrated: Modular adapters mean any REST, WebSocket, or FIX API can be integrated
  • 集成:模块化适配器意味着可以集成任何 REST、WebSocket 或 FIX API
  • Advanced: Time in force IOC, FOK, GTD, AT_THE_OPEN, AT_THE_CLOSE, advanced order types and conditional triggers. Execution instructions post-only, reduce-only, and icebergs. Contingency order lists including OCO, OTO
  • 高级:时间有效性 IOC、FOK、GTD、开盘价、收盘价,先进的订单类型和条件触发器。执行指令为仅发布、仅减少和冰山单。应急订单列表,包括 OCO、OTO
  • Backtesting: Run with multiple venues, instruments and strategies simultaneously using historical quote tick, trade tick, bar, order book and custom data with nanosecond resolution
  • 回测:使用历史报价 tick、交易 tick、K线、订单簿和自定义数据以纳秒级分辨率同时运行多个平台、金融产品和策略
  • Live: Use identical strategy implementations between backtesting and live deployments
  • 实盘:在回测和实时部署之间使用相同的策略实现
  • Multi-venue: Multiple venue capabilities facilitate market making and statistical arbitrage strategies
  • 多平台:多平台能力有助于市场制作和统计套利策略
  • AI Training: Backtest engine fast enough to be used to train AI trading agents (RL/ES)
  • AI 训练:回测引擎足够快速,可以用于训练 AI 交易代理(强化学习/演示学习)

Nautilus

海螺

image

nautilus - from ancient Greek 'sailor' and naus 'ship'.
nautilus - 源自古希腊语的“水手”和“船”。

The nautilus shell consists of modular chambers with a growth factor which approximates a logarithmic spiral. The idea is that this can be translated to the aesthetics of design and architecture.
海螺的外壳由模块化的腔体组成,生长因子近似于对数螺旋。这一概念可以转化为设计和建筑的美学。

Why NautilusTrader?

为什么选择 NautilusTrader?

  • Highly performant event-driven Python: Native binary core components
  • 高性能事件驱动的 Python:原生二进制核心组件
  • Parity between backtesting and live trading: Identical strategy code
  • 回测和实时交易之间的一致性:相同的策略代码
  • Reduced operational risk: Risk management functionality, logical correctness and type safety
  • 降低操作风险:风险管理功能、逻辑正确性和类型安全
  • Highly extendable: Message bus, custom components and actors, custom data, custom adapters
  • 高度可扩展:消息总线、自定义组件和参与者、自定义数据、自定义适配器

Traditionally, trading strategy research and backtesting might be conducted in Python (or other suitable language) using vectorized methods, with the strategy then needing to be reimplemented in a more event-driven way using C++, C#, Java or other statically typed language(s). The reasoning here is that vectorized backtesting code cannot express the granular time and event dependent complexity of real-time trading, where compiled languages have proven to be more suitable due to their inherently higher performance and type safety.
传统上,交易策略研究和回测可能是在 Python(或其他合适的语言)中使用矢量化方法进行的,随后需要使用 C++、C#、Java 或其他静态类型语言以更事件驱动的方式重新实现策略。其原因在于矢量化回测代码无法表达实时交易的细粒度时间和事件依赖复杂性,而编译语言因其固有的更高性能和类型安全性已被证明更为适合。

One of the key advantages of NautilusTrader here is that this reimplementation step is now circumvented - as the critical core components of the platform have all been written entirely in Rust or Cython. This means we're using the right tools for the job, where systems programming languages compile performant binaries, with CPython C extension modules then able to offer a Python native environment, suitable for professional quantitative traders and trading firms.
NautilusTrader 的一个关键优势在于,现在可以避免这一重新实现步骤——因为该平台的核心组件都是用 Rust 或 Cython 完全编写的。这意味着我们正在使用合适的工具来完成任务,系统编程语言编译高性能的二进制文件,而 CPython C 扩展模块则能够提供一个适合专业量化交易者和交易公司的 Python 原生环境。

Use cases

使用案例

There are three main use cases for this software package:
该软件包的主要使用案例有三个:

  1. Backtesting trading systems with historical data (backtest)
    使用历史数据进行交易系统回测(回测)
  2. Testing trading systems with real-time data and simulated execution (sandbox)
    使用实时数据和模拟执行测试交易系统(沙盒)
  3. Deploying trading systems with real-time data and executing on venues with real (or paper) accounts (live)
    使用实时数据和在平台上用真实(或模拟)账户执行的交易系统部署(实盘)

The project’s codebase provides a framework for implementing the software layer of systems that achieve the above. You will find the default backtest and live system implementations in their respectively named subpackages. A sandbox environment can be built using the sandbox adapter.
该项目的代码库提供了一个框架,用于实现达到上述目标的系统软件层。您将在其各自命名的子包中找到默认的回测和实时系统实现。可以使用沙盒适配器构建沙盒环境。

Note
All examples will utilize these default system implementations.
所有示例将使用这些默认系统实现。

We consider trading strategies to be subcomponents of end-to-end trading systems; these systems include the application and infrastructure layers.
我们认为交易策略是端到端交易系统的子组件;这些系统包括应用层和基础设施层。

Distributed

分布式

The platform is designed to be easily integrated into a larger distributed system. To facilitate this, nearly all configuration and domain objects can be serialized using JSON, MessagePack, or Apache Arrow (Feather) for communication over the network.
该平台设计为能够轻松集成到更大的分布式系统中。为此,几乎所有配置和领域对象都可以使用 JSON、MessagePack 或 Apache Arrow(Feather)进行序列化,以便通过网络进行通信。

Common core

公共核心

The common system core is utilized by all node environment contexts (backtest, sandbox, and live). User-defined Actor, Strategy and ExecAlgorithm components are managed consistently across these environment contexts.
所有节点环境上下文(回测、沙盒和实盘)都使用公共系统核心。用户定义的 Actor、Strategy 和 ExecAlgorithm 组件在这些环境上下文中得到一致管理。

Backtesting

回测

Backtesting can be achieved by first making data available to a BacktestEngine either directly or via a higher level BacktestNode and ParquetDataCatalog, and then running the data through the system with nanosecond resolution.
回测可以通过首先将数据直接或通过更高层的 BacktestNode 和 ParquetDataCatalog 提供给 BacktestEngine 来实现,然后以纳秒级分辨率将数据运行通过系统。

Live trading

实盘交易

A TradingNode can ingest data and events from multiple data and execution clients. Live deployments can use both demo/paper trading accounts, or real accounts.
TradingNode 可以从多个数据和执行客户端接收数据和事件。实时部署可以使用模拟/纸质交易账户或真实账户。

For live trading, a TradingNode can ingest data and events from multiple data and execution clients. The platform supports both demo/paper trading accounts and real accounts. High performance can be achieved by running asynchronously on a single event loop, with the potential to further boost performance by leveraging the uvloop implementation (available for Linux and macOS).
在实盘交易中,TradingNode 可以从多个数据和执行客户端接收数据和事件。该平台支持模拟/纸质交易账户和真实账户。通过在单个事件循环上异步运行,可以实现高性能,并且可以通过利用 uvloop 实现(适用于 Linux 和 macOS)进一步提升性能。

Domain model

域模型

The platform features a comprehensive trading domain model that includes various value types such as Price and Quantity, as well as more complex entities such as Order and Position objects, which are used to aggregate multiple events to determine state.
该平台具有一个全面的交易领域模型,包括各种值类型,如价格和数量,以及更复杂的实体,如订单和持仓对象,这些对象用于聚合多个事件以确定状态。

Data types

数据类型

The following market data types can be requested historically, and also subscribed to as live streams when available from a venue/data provider, and implemented in an integrations adapter.
以下市场数据类型可以请求历史数据,并且在可用时也可以订阅为实时流,并在集成适配器中实现。

  • OrderBookDelta (L1/L2/L3)
  • OrderBookDeltas (container type)
  • OrderBookDepth10 (fixed depth of 10 levels per side)
  • QuoteTick
  • TradeTick
  • Bar
  • Instrument
  • InstrumentStatus
  • InstrumentClose

The following PriceType options can be used for bar aggregations:
以下 PriceType 选项可用于 K线聚合:

  • BID
  • ASK
  • MID
  • LAST

Bar aggregations

K线聚合

The following BarAggregation methods are available:
以下 K线聚合方法可用:

  • MILLISECOND
  • SECOND
  • MINUTE
  • HOUR
  • DAY
  • WEEK
  • MONTH
  • TICK
  • VOLUME
  • VALUE (a.k.a Dollar bars)
  • TICK_IMBALANCE
  • TICK_RUNS
  • VOLUME_IMBALANCE
  • VOLUME_RUNS
  • VALUE_IMBALANCE
  • VALUE_RUNS

The price types and bar aggregations can be combined with step sizes >= 1 in any way through a BarSpecification. This enables maximum flexibility and now allows alternative bars to be aggregated for live trading.
价格类型和 K线聚合可以通过 BarSpecification 以任意方式组合,步长 >= 1。这提供了最大的灵活性,并允许在实盘交易中聚合替代 K线。

Account Types

账户类型

The following account types are available for both live and backtest environments:
以下账户类型可用于实盘和回测环境:

  • Cash single-currency (base currency)
  • 现金单一货币(基础货币)
  • Cash multi-currency
  • 现金多货币
  • Margin single-currency (base currency)
  • 保证金单一货币(基础货币)
  • Margin multi-currency
  • 保证金多货币
  • Betting single-currency
  • 博彩单一货币

Order Types

订单类型

The following order types are available (when possible on a venue):
以下订单类型可用(在平台可行时):

  • MARKET
  • 限价单
  • LIMIT
  • 限价单
  • STOP_MARKET
  • 止损市价单
  • STOP_LIMIT
  • 止损限价单
  • MARKET_TO_LIMIT
  • 市价转限价单
  • MARKET_IF_TOUCHED
  • 触及市价单
  • LIMIT_IF_TOUCHED
  • 触及限价单
  • TRAILING_STOP_MARKET
  • 跟踪止损市价单
  • TRAILING_STOP_LIMIT
  • 跟踪止损限价单