Skip to content

Commit 7543941

Browse files
committed
migrating to rust
1 parent ae046db commit 7543941

File tree

306 files changed

+3738
-221
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

306 files changed

+3738
-221
lines changed

.bumpversion.cfg

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[bumpversion]
2+
current_version = 0.1.0
3+
commit = True
4+
tag = False
5+
6+
[bumpversion:file:python/aat/aat/__init__.py]
7+
search = __version__ = "{current_version}"
8+
replace = __version__ = "{new_version}"
9+
10+
[bumpversion:file:python/aat/setup.py]
11+
search = version = "{current_version}"
12+
replace = version = "{new_version}"
13+
14+
# [bumpversion:file:js/package.json]
15+
# search = "version": "{current_version}"
16+
# replace = "version": "{new_version}"

.github/workflows/build.yml

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ on:
44
push:
55
branches:
66
- main
7+
tags:
8+
- v*
9+
paths-ignore:
10+
- LICENSE
11+
- README.md
712
pull_request:
813

914
concurrency:
@@ -24,64 +29,61 @@ jobs:
2429
steps:
2530
- uses: actions/checkout@v3
2631

32+
- name: Set up Rust
33+
uses: actions-rs/toolchain@v1
34+
with:
35+
profile: minimal
36+
toolchain: nightly
37+
components: clippy
38+
override: true
39+
2740
- name: Set up Python ${{ matrix.python-version }}
2841
uses: actions/setup-python@v4
2942
with:
3043
python-version: ${{ matrix.python-version }}
44+
cache: "pip"
45+
cache-dependency-path: 'setup.py'
3146

32-
- name: Install system dependencies
33-
run: |
34-
sudo apt-get install libboost-dev
35-
wget https://github.com/pybind/pybind11/archive/v2.5.0.tar.gz && tar xfz v2.5.0.tar.gz && cd pybind11-2.5.0 && mkdir build && cd build && cmake .. -DPYBIND11_TEST=OFF && sudo make -j4 install
36-
if: ${{ matrix.os == 'ubuntu-latest' }}
37-
38-
- name: Install system dependencies
39-
run: |
40-
brew install boost cmake pybind11
41-
if: ${{ matrix.os == 'macos-latest' }}
42-
43-
- name: Install dependencies
44-
run: |
45-
python -m pip install -U cpplint numpy pip pyarrow pyEX setuptools tqdm twine wheel
46-
python -m pip install -e .[dev]
47+
- name: Use Node.js ${{ matrix.node-version }}
48+
uses: actions/setup-node@v3
49+
with:
50+
node-version: ${{ matrix.node-version }}
51+
cache: 'yarn'
52+
cache-dependency-path: js/yarn.lock
4753

48-
- name: Lint Python
49-
run: |
50-
make lintpy
54+
- name: Install yarn
55+
run: npm install -g yarn
5156

52-
- name: Lint C++
53-
run: |
54-
make lintcpp
57+
- uses: actions-rs/cargo@v1
58+
with:
59+
command: check
5560

56-
- name: Type Annotate
61+
- name: Install dependencies
5762
run: |
58-
make annotate
63+
make develop
5964
60-
- name: Test
65+
- name: Build
6166
run: |
62-
make tests
63-
if: ${{ github.event_name == matrix.event-name || matrix.os == 'ubuntu-latest' }}
67+
make build
6468
65-
- name: Test C++
69+
- name: Lint
6670
run: |
67-
make testpycpp
68-
if: ${{ github.event_name == matrix.event-name || matrix.os == 'ubuntu-latest' }}
71+
make lint
6972
70-
- name: Live tests
73+
- name: Checks
7174
run: |
72-
make testruns
75+
make checks
7376
if: ${{ github.event_name == matrix.event-name || matrix.os == 'ubuntu-latest' }}
7477

75-
- name: Twine check
78+
- name: Test
7679
run: |
77-
make dist
80+
make tests-ci-gha
81+
if: ${{ matrix.os == 'ubuntu-latest' }}
7882

7983
- name: Upload test results
80-
uses: actions/upload-artifact@v3
84+
uses: EnricoMi/publish-unit-test-result-action@v1
8185
with:
82-
name: pytest-results-${{ matrix.os }}-${{ matrix.python-version }}
83-
path: python_junit.xml
84-
if: ${{ always() }}
85-
86-
- name: Upload coverage
87-
uses: codecov/codecov-action@v3
86+
check_name: Test Results
87+
github_token: ${{ secrets.GITHUB_TOKEN }}
88+
files: results.xml
89+
if: ${{ matrix.os == 'ubuntu-latest' }}

.gitignore

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,18 @@ pip-delete-this-directory.txt
3535
# Unit test / coverage reports
3636
htmlcov/
3737
.tox/
38+
coverage
3839
.coverage
3940
.coverage.*
4041
.cache
4142
nosetests.xml
4243
coverage.xml
4344
*,cover
4445
cover
46+
results.xml
47+
python_junit.xml
48+
.mypy_cache
49+
venv/
4550

4651
# Translations
4752
*.mo
@@ -52,47 +57,37 @@ cover
5257

5358
# Sphinx documentation
5459
docs/_build/
60+
docs/api
61+
docs/index.md
5562

5663
# PyBuilder
5764
target/
5865

5966
*_keys
6067
horizon
6168

69+
# Mac files
6270
*.DS_Store
71+
72+
# JS Files
6373
js/node_modules/
6474
js/build/
6575
aat/ui/assets/static/
66-
notes.txt
67-
ref
76+
node_modules
77+
78+
# Keys
6879
coinbase.sh
6980
coinbase_sandbox.sh
7081
keys
71-
old
7282

83+
# Notebooks
7384
.ipynb_checkpoints
74-
*.pkl
7585
notebooks/BTC_*
86+
87+
# IDE
7688
.idea
89+
.vscode
7790

91+
# Other
7892
custom_strategies
7993

80-
node_modules
81-
package-lock.json
82-
yarn.lock
83-
logo.ai
84-
logo.png
85-
coverage
86-
experiments
87-
aat_test
88-
docs/api
89-
docs/index.md
90-
tornado_sqlalchemy_login
91-
aat.db
92-
python_junit.xml
93-
.mypy_cache
94-
.vscode
95-
private_config
96-
_aat_BACKTEST*
97-
98-
venv/

Makefile

Lines changed: 8 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,14 @@
1-
PYTHON=python
2-
CONFIG=./config/synthetic.cfg
3-
4-
5-
run: ## Clean and make target, run target
6-
$(PYTHON) -m aat --config $(CONFIG)
7-
8-
runcpp: build ## Clean and make target, run target
9-
AAT_USE_CPP=1 $(PYTHON) -m aat --config $(CONFIG)
10-
11-
rundebug: debug ## Clean and make debug target, run target
12-
$(PYTHON) -m aat --config $(CONFIG)
13-
14-
stratres: ## View strategy results offline
15-
$(PYTHON) -m aat.strategy.calculations
16-
17-
buildextf: ## build the package extensions
18-
$(PYTHON) setup.py build_ext -j8 --inplace -f
19-
20-
buildext: ## build the package extensions
21-
$(PYTHON) setup.py build_ext -j8 --inplace
22-
23-
build: buildext ## build the package
24-
$(PYTHON) setup.py build
25-
26-
debug: ## build debug build of the package
27-
DEBUG=1 $(PYTHON) setup.py build
28-
29-
install: ## install the package
30-
$(PYTHON) -m pip install .
31-
32-
tests: build testpy ## Make unit tests
33-
34-
testpy: ## Make unit tests
35-
$(PYTHON) -m pytest -vvv ./aat/tests --cov=aat --junitxml=python_junit.xml --cov-report=xml --cov-branch
36-
37-
testpycpp: ## Make unit tests
38-
# AAT_USE_CPP=1 $(PYTHON) -m pytest -vvv ./aat/tests --cov=aat --junitxml=python_junit.xml --cov-report=xml --cov-branch --capture=no
39-
AAT_USE_CPP=1 $(PYTHON) -m pytest -vs ./aat/tests
40-
41-
testruns: testrunscsv testrunsiex ## Run a few examples as a live end-to-end test
42-
43-
testrunscsv:
44-
$(PYTHON) -m aat.strategy.sample.csv.readonly
45-
$(PYTHON) -m aat.strategy.sample.csv.readonly_periodic
46-
$(PYTHON) -m aat.strategy.sample.csv.received
47-
48-
testrunsiex:
49-
$(PYTHON) -m aat.strategy.sample.iex.readonly
50-
TESTING=1 $(PYTHON) -m aat.strategy.sample.iex.buy_and_hold
51-
TESTING=1 $(PYTHON) -m aat.strategy.sample.iex.momentum
52-
TESTING=1 $(PYTHON) -m aat.strategy.sample.iex.golden_death
53-
54-
lint: lintpy lintcpp ## run all linters
55-
56-
lintpy: ## run python linter
57-
$(PYTHON) -m flake8 aat setup.py
58-
59-
lintcpp: ## run cpp linter
60-
cpplint --linelength=120 --recursive aat/cpp/{src,include}
61-
62-
fix: fixpy fixcpp ## run all fixers
63-
64-
fixpy: ## run autopep8 fix
65-
$(PYTHON) -m black aat/ setup.py
66-
67-
fixcpp: ## run clang-format
68-
clang-format -i -style=file `find ./aat/cpp/{src,include} -name "*.*pp"`
69-
70-
annotate: ## MyPy type annotation check
71-
$(PYTHON) -m mypy aat
72-
73-
type_ignore: ## Count type ignores
74-
grep -rin "type: ignore" ./aat | wc -l
75-
76-
type_ignore_list: ## List all type ignores
77-
grep -rin "type: ignore" ./aat
78-
79-
docs: ## Build the sphinx docs
80-
make -C docs html
81-
open ./docs/_build/html/index.html
82-
83-
dist: ## create dists
84-
rm -rf dist build
85-
python setup.py sdist bdist_wheel
86-
python -m twine check dist/*
1+
.DEFAULT_GOAL := help
2+
.PHONY: develop build lint checks tests tests-ci-gha
873

88-
publish: dist ## dist to pypi and npm
89-
python -m twine upload dist/* --skip-existing
4+
develop: ## Setup project for development
905

91-
clean: ## clean the repository
92-
find . -name "__pycache__" | xargs rm -rf
93-
find . -name "*.pyc" | xargs rm -rf
94-
rm -rf .coverage coverage cover htmlcov logs build dist *.egg-info coverage.xml .mypy_cache
95-
find . -name "*.so" | xargs rm -rf
96-
make -C ./docs clean
97-
rm -rf _aat_BACKTEST_*
6+
build: ## Build the project
987

99-
# Thanks to Francoise at marmelab.com for this
100-
.DEFAULT_GOAL := help
101-
help:
102-
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
8+
lint: ## Run project linters
1039

104-
print-%:
105-
@echo '$*=$($*)'
10+
checks: ## Run any other checks
10611

107-
.PHONY: run buildext build install tests lint fix docs dist clean help fixcpp
12+
tests: ## Run the tests
10813

14+
tests-ci-gha:

README.md

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
<img src="https://raw.githubusercontent.com/AsyncAlgoTrading/aat/main/docs/img/icon.png" width="200px"></img>
32

43
[![Build Status](https://github.com/AsyncAlgoTrading/aat/workflows/Build%20Status/badge.svg?branch=main)](https://github.com/AsyncAlgoTrading/aat/actions?query=workflow%3A%22Build+Status%22)
@@ -7,55 +6,8 @@
76
[![PyPI](https://img.shields.io/pypi/v/aat.svg)](https://pypi.python.org/pypi/aat)
87
[![Docs](https://img.shields.io/readthedocs/aat.svg)](http://aat.readthedocs.io/en/latest/)
98

10-
`aat` is an asynchronous, event-driven framework for writing algorithmic trading strategies in python with optional acceleration in C++. It is designed to be modular and extensible, with support for a wide variety of instruments and strategies, live trading across (and between) multiple exchanges, fully integrated backtesting support, slippage and transaction cost modeling, and robust reporting and risk mitigation through manual and programatic algorithm controls.
9+
`aat` is an asynchronous, event-driven framework for writing algorithmic trading strategies in python with optional acceleration in rust. It is designed to be modular and extensible, with support for a wide variety of instruments and strategies, live trading across (and between) multiple exchanges, fully integrated backtesting support, slippage and transaction cost modeling, and robust reporting and risk mitigation through manual and programatic algorithm controls.
1110

1211
Like [Zipline](https://github.com/quantopian/zipline) and [Lean](https://github.com/QuantConnect/Lean), `aat` exposes a single strategy class which is utilized for both live trading and backtesting. The strategy class is simple enough to write and test algorithms quickly, but extensible enough to allow for complex slippage and transaction cost modeling, as well as mid- and post- trade analysis.
1312

1413
`aat` is in active use for live algorithmic trading on equities, commodity futures contracts, and commodity futures spreads by undisclosed funds.
15-
16-
## Overview
17-
A complete overview of the core components of `aat` is provided in the [GETTING_STARTED](GETTING_STARTED.md) file.
18-
19-
### Internals
20-
`aat`'s engine is composed of 4 major parts.
21-
22-
- trading engine
23-
- risk management engine
24-
- execution engine
25-
- backtest engine
26-
27-
28-
#### Trading Engine
29-
The trading engine initializes all exchanges and strategies, then martials data, trade requests, and trade responses between the strategy, risk, execution, and exchange objects, while keeping track of high-level statistics on the system
30-
31-
#### Risk Management Engine
32-
The risk management engine enforces trading limits, making sure that stategies are limited to certain risk profiles. It can modify or remove trade requests prior to execution depending on user preferences and outstanding positions and orders.
33-
34-
#### Execution engine
35-
The execution engine is a simple passthrough to the underlying exchanges. It provides a unified interface for creating various types of orders.
36-
37-
#### Backtest engine
38-
The backtest engine provides the ability to run the same stragegy offline against historical data.
39-
40-
### Core Components
41-
`aat` has a variety of core classes and data structures, the most important of which are the `Strategy` and `Exchange` classes.
42-
43-
#### Trading Strategy
44-
The core element of `aat` is the trading strategy interface. It includes both data processing and order management functionality. Users subclass this class in order to implement their strategies. Methods of the form `onNoun` are used to handle market data events, while methods of the form `onVerb` are used to handle order entry events. There are also a variety of order management and data subscription methods available.
45-
46-
The only method that is required to be implemented is the `onTrade` method. The full specification of a strategy is given in [GETTING_STARTED](GETTING_STARTED.md).
47-
48-
49-
#### Other Components
50-
`aat` also provides a complete limit-order book implementation, including flags like `fill-or-kill` and `all-or-nothing`, which is used to power the synthetic testing exchange.
51-
52-
53-
## Support / Contributors
54-
Thanks to the following organizations for providing code or financial support.
55-
56-
<a href="https://nemoulous.com"><img src="https://raw.githubusercontent.com/asyncalgotrading/aat/main/docs/img/nem.png" width="50"></a>
57-
58-
<a href="https://nemoulous.com">Nemoulous</a>
59-
60-
## License
61-
This software is licensed under the Apache 2.0 license. See the [LICENSE](LICENSE) file for details.

aat/tests/strategy/_aat_BACKTEST_test/MomentumStrategy-0.portfolio.active_by_inst.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

aat/tests/strategy/_aat_BACKTEST_test/MomentumStrategy-0.portfolio.active_by_strat.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)