an open source algorithmic trading engine optimized for a great developer experience
Project description
terrace: an open source algorithmic trading engine optimized for a great developer experience
Terrace aims to remain near 1000 lines at the core, provide a flexible API, and great developer expereince.
Easily research, test, and deploy a variety of trading strategies across all asset classes.
Core
- Strategy - Strategies are ambiguous to time and the asset they are trading against. They contain the rules for managing a portfolio
- Data Engine - The data engine is responsible for collecting data and supplying it to the strategy via the trading engine
- Trading Engine - The trading engine manages state and connects the data engine to the strategy, as well as enforces risk management rules.
- Execution Engine - The execution of trades is handled by the execution engine. The execution engine can send orders to exchanges asynchrnously in realtime.
- Back Testing Engine - The back testing engine is a wrapper around the data engine and execution engine, simulating trades over historical data.
Install
The current recommended way to install Terrace is using pip:
pip install terrace-engine
Demo
Creating a strategy is easy:
from terrace.strategy import Strategy
from terrace.helpers import ta
class TAStrategy(Strategy):
def step(self, ctx):
sma = ta.sma(ctx.close, 20)
if ctx.close > sma:
self.long()
elif ctx.close < sma:
self.short()
Implementing data is easy too, either from a paid vendor or your own sources:
from terrace.data import Context
from terrace.data import Intrinio, IEX, Polygon, CSV
custom_data = CSV('mydata.csv', columns=['price', 'change', 'bid', 'ask', 'customfield'])
context = Context(Intrinio(), IEX(), Polygon(), custom_data)
"""
>> print(context)
=== [ Providers ] ===
Intrinio, IEX, Polygon, CSV
=== [ Available Fields ] ===
(intrinio) close -> float*
(intrinio) open -> float*
(intrinio) high -> float*
...
(CSV) price -> float*
(CSV) change -> float*
(CSV) bid -> float*
(CSV) ask -> float*
(CSV) customfield -> string*
* indicates historical data is available
"""
With a Strategy, and data, back testing and live trading is possible:
""" Back Testing """
from terrace.trading import Backtest
from terrace.helpers import sp500constituents
engine = Backtest(strategy, context)
engine.run(frequency='1m', period='1mo', target=sp500contstuents)
#engine.plot()
#print(engine.stats())
""" Trade Live """
from terrace.trading import Engine
from terrace.execute import Alpaca
engine = Engine(strategy, context)
exchange = Alpaca(api_key=..., api_secret=...)
engine.run(frequency='1m', exchange=exchange, target='AAPL')
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
terrace-engine-0.0.1.tar.gz
(7.1 kB
view details)
Built Distribution
File details
Details for the file terrace-engine-0.0.1.tar.gz
.
File metadata
- Download URL: terrace-engine-0.0.1.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41d64e662c673a3a01a7206187c121579f675dff9329460475bc77f4e4855ced |
|
MD5 | 03afc76df15516ddf18feafd685b600b |
|
BLAKE2b-256 | b08dce94c8e84cd3b54629a14f88d9bece0d76c46d8f2efc02703b279b1103ec |
File details
Details for the file terrace_engine-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: terrace_engine-0.0.1-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 278b28ddb9cfcfc9c6df014dc25edcd30faa4c6b44f09a0b8d59c5f7aa993ca0 |
|
MD5 | f64f8c73baad2f7d7588c5f35b001bfd |
|
BLAKE2b-256 | d04a64693f076b9436e908d2a6f4d42bf689064312001831e4505a99a3fbfa49 |