Skip to content

Commit

Permalink
migrating to rust
Browse files Browse the repository at this point in the history
  • Loading branch information
theocean154 committed Sep 19, 2022
1 parent ae046db commit 7543941
Show file tree
Hide file tree
Showing 306 changed files with 3,738 additions and 221 deletions.
16 changes: 16 additions & 0 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[bumpversion]
current_version = 0.1.0
commit = True
tag = False

[bumpversion:file:python/aat/aat/__init__.py]
search = __version__ = "{current_version}"
replace = __version__ = "{new_version}"

[bumpversion:file:python/aat/setup.py]
search = version = "{current_version}"
replace = version = "{new_version}"

# [bumpversion:file:js/package.json]
# search = "version": "{current_version}"
# replace = "version": "{new_version}"
82 changes: 42 additions & 40 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ on:
push:
branches:
- main
tags:
- v*
paths-ignore:
- LICENSE
- README.md
pull_request:

concurrency:
Expand All @@ -24,64 +29,61 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
components: clippy
override: true

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
cache-dependency-path: 'setup.py'

- name: Install system dependencies
run: |
sudo apt-get install libboost-dev
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
if: ${{ matrix.os == 'ubuntu-latest' }}

- name: Install system dependencies
run: |
brew install boost cmake pybind11
if: ${{ matrix.os == 'macos-latest' }}

- name: Install dependencies
run: |
python -m pip install -U cpplint numpy pip pyarrow pyEX setuptools tqdm twine wheel
python -m pip install -e .[dev]
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
cache-dependency-path: js/yarn.lock

- name: Lint Python
run: |
make lintpy
- name: Install yarn
run: npm install -g yarn

- name: Lint C++
run: |
make lintcpp
- uses: actions-rs/cargo@v1
with:
command: check

- name: Type Annotate
- name: Install dependencies
run: |
make annotate
make develop
- name: Test
- name: Build
run: |
make tests
if: ${{ github.event_name == matrix.event-name || matrix.os == 'ubuntu-latest' }}
make build
- name: Test C++
- name: Lint
run: |
make testpycpp
if: ${{ github.event_name == matrix.event-name || matrix.os == 'ubuntu-latest' }}
make lint
- name: Live tests
- name: Checks
run: |
make testruns
make checks
if: ${{ github.event_name == matrix.event-name || matrix.os == 'ubuntu-latest' }}

- name: Twine check
- name: Test
run: |
make dist
make tests-ci-gha
if: ${{ matrix.os == 'ubuntu-latest' }}

- name: Upload test results
uses: actions/upload-artifact@v3
uses: EnricoMi/publish-unit-test-result-action@v1
with:
name: pytest-results-${{ matrix.os }}-${{ matrix.python-version }}
path: python_junit.xml
if: ${{ always() }}

- name: Upload coverage
uses: codecov/codecov-action@v3
check_name: Test Results
github_token: ${{ secrets.GITHUB_TOKEN }}
files: results.xml
if: ${{ matrix.os == 'ubuntu-latest' }}
41 changes: 18 additions & 23 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,18 @@ pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
coverage
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
cover
results.xml
python_junit.xml
.mypy_cache
venv/

# Translations
*.mo
Expand All @@ -52,47 +57,37 @@ cover

# Sphinx documentation
docs/_build/
docs/api
docs/index.md

# PyBuilder
target/

*_keys
horizon

# Mac files
*.DS_Store

# JS Files
js/node_modules/
js/build/
aat/ui/assets/static/
notes.txt
ref
node_modules

# Keys
coinbase.sh
coinbase_sandbox.sh
keys
old

# Notebooks
.ipynb_checkpoints
*.pkl
notebooks/BTC_*

# IDE
.idea
.vscode

# Other
custom_strategies

node_modules
package-lock.json
yarn.lock
logo.ai
logo.png
coverage
experiments
aat_test
docs/api
docs/index.md
tornado_sqlalchemy_login
aat.db
python_junit.xml
.mypy_cache
.vscode
private_config
_aat_BACKTEST*

venv/
110 changes: 8 additions & 102 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,108 +1,14 @@
PYTHON=python
CONFIG=./config/synthetic.cfg


run: ## Clean and make target, run target
$(PYTHON) -m aat --config $(CONFIG)

runcpp: build ## Clean and make target, run target
AAT_USE_CPP=1 $(PYTHON) -m aat --config $(CONFIG)

rundebug: debug ## Clean and make debug target, run target
$(PYTHON) -m aat --config $(CONFIG)

stratres: ## View strategy results offline
$(PYTHON) -m aat.strategy.calculations

buildextf: ## build the package extensions
$(PYTHON) setup.py build_ext -j8 --inplace -f

buildext: ## build the package extensions
$(PYTHON) setup.py build_ext -j8 --inplace

build: buildext ## build the package
$(PYTHON) setup.py build

debug: ## build debug build of the package
DEBUG=1 $(PYTHON) setup.py build

install: ## install the package
$(PYTHON) -m pip install .

tests: build testpy ## Make unit tests

testpy: ## Make unit tests
$(PYTHON) -m pytest -vvv ./aat/tests --cov=aat --junitxml=python_junit.xml --cov-report=xml --cov-branch

testpycpp: ## Make unit tests
# AAT_USE_CPP=1 $(PYTHON) -m pytest -vvv ./aat/tests --cov=aat --junitxml=python_junit.xml --cov-report=xml --cov-branch --capture=no
AAT_USE_CPP=1 $(PYTHON) -m pytest -vs ./aat/tests

testruns: testrunscsv testrunsiex ## Run a few examples as a live end-to-end test

testrunscsv:
$(PYTHON) -m aat.strategy.sample.csv.readonly
$(PYTHON) -m aat.strategy.sample.csv.readonly_periodic
$(PYTHON) -m aat.strategy.sample.csv.received

testrunsiex:
$(PYTHON) -m aat.strategy.sample.iex.readonly
TESTING=1 $(PYTHON) -m aat.strategy.sample.iex.buy_and_hold
TESTING=1 $(PYTHON) -m aat.strategy.sample.iex.momentum
TESTING=1 $(PYTHON) -m aat.strategy.sample.iex.golden_death

lint: lintpy lintcpp ## run all linters

lintpy: ## run python linter
$(PYTHON) -m flake8 aat setup.py

lintcpp: ## run cpp linter
cpplint --linelength=120 --recursive aat/cpp/{src,include}

fix: fixpy fixcpp ## run all fixers

fixpy: ## run autopep8 fix
$(PYTHON) -m black aat/ setup.py

fixcpp: ## run clang-format
clang-format -i -style=file `find ./aat/cpp/{src,include} -name "*.*pp"`

annotate: ## MyPy type annotation check
$(PYTHON) -m mypy aat

type_ignore: ## Count type ignores
grep -rin "type: ignore" ./aat | wc -l

type_ignore_list: ## List all type ignores
grep -rin "type: ignore" ./aat

docs: ## Build the sphinx docs
make -C docs html
open ./docs/_build/html/index.html

dist: ## create dists
rm -rf dist build
python setup.py sdist bdist_wheel
python -m twine check dist/*
.DEFAULT_GOAL := help
.PHONY: develop build lint checks tests tests-ci-gha

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

clean: ## clean the repository
find . -name "__pycache__" | xargs rm -rf
find . -name "*.pyc" | xargs rm -rf
rm -rf .coverage coverage cover htmlcov logs build dist *.egg-info coverage.xml .mypy_cache
find . -name "*.so" | xargs rm -rf
make -C ./docs clean
rm -rf _aat_BACKTEST_*
build: ## Build the project

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

print-%:
@echo '$*=$($*)'
checks: ## Run any other checks

.PHONY: run buildext build install tests lint fix docs dist clean help fixcpp
tests: ## Run the tests

tests-ci-gha:
50 changes: 1 addition & 49 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

<img src="https://raw.githubusercontent.com/AsyncAlgoTrading/aat/main/docs/img/icon.png" width="200px"></img>

[![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)
Expand All @@ -7,55 +6,8 @@
[![PyPI](https://img.shields.io/pypi/v/aat.svg)](https://pypi.python.org/pypi/aat)
[![Docs](https://img.shields.io/readthedocs/aat.svg)](http://aat.readthedocs.io/en/latest/)

`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.
`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.

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.

`aat` is in active use for live algorithmic trading on equities, commodity futures contracts, and commodity futures spreads by undisclosed funds.

## Overview
A complete overview of the core components of `aat` is provided in the [GETTING_STARTED](GETTING_STARTED.md) file.

### Internals
`aat`'s engine is composed of 4 major parts.

- trading engine
- risk management engine
- execution engine
- backtest engine


#### Trading Engine
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

#### Risk Management Engine
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.

#### Execution engine
The execution engine is a simple passthrough to the underlying exchanges. It provides a unified interface for creating various types of orders.

#### Backtest engine
The backtest engine provides the ability to run the same stragegy offline against historical data.

### Core Components
`aat` has a variety of core classes and data structures, the most important of which are the `Strategy` and `Exchange` classes.

#### Trading Strategy
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.

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).


#### Other Components
`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.


## Support / Contributors
Thanks to the following organizations for providing code or financial support.

<a href="https://nemoulous.com"><img src="https://raw.githubusercontent.com/asyncalgotrading/aat/main/docs/img/nem.png" width="50"></a>

<a href="https://nemoulous.com">Nemoulous</a>

## License
This software is licensed under the Apache 2.0 license. See the [LICENSE](LICENSE) file for details.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 7543941

Please sign in to comment.