Git Product home page Git Product logo

terrace's Introduction

drawing

terrace: an open source algorithmic trading engine optimized for a great developer experience

GitHub Repo stars Deploy Unit Test


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

You can also install from source:

git clone https://github.com/carterjfulcher/terrace.git
cd terrace
python3 -m pip install -e . # or `py3 -m pip install -e .` if you are on windows

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

terrace's People

Contributors

carterjfulcher avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.