Skip to main content

An algorithmic trading framework for PyData.

Project description

version python wheel license build Documentation Status

An algorithmic trading framework for pydata.

Margot is a library of two parts that may be used together or separately:

  • margot.data

  • margot.backtest

Margot Data

The first component is margot.data.

Margot manages data collection, cleaning and assemblance of time series into a nicely organised Pandas Dataframe using a clean, declarative API. If you’ve ever used Django you’ll find this approach very similar to the Django ORM.

Columns

Margot can retreive time series data from external sources, like AlphaVantage. To add a time series such as “closing_price” or “volume”, we declare a Column.

e.g. to get closing_price from AlphaVantage:

adj_close = av.Column(function='historical_daily_adjusted', column='adjusted_close')

Features

Columns are useful, but we usually want to derived another time series from them, such as “returns” or “SMA20”. Margot does this for you; we call them Features.

simple_returns = feature.SimpleReturns(column='adjusted_close')
log_returns = feature.LogReturns(column='adjusted_close')
sma20 = feature.SimpleMovingAverage(column='adjusted_close', window=20)

Margot Data includes many common financial Features, and it’s very easy to add more.

Symbols

Often, you want to make a dataframe combining a number of these columns and features. Margot makes this very easy. e.g.

class MyEquity(Symbol):

    adjusted_close = av.Column(function='historical_daily_adjusted', column='adjusted_close')
    log_returns = feature.LogReturns(column='adjusted_close')
    realised_vol = feature.RealisedVolatility(column='log_returns', window=30)
    upper_band = feature.UpperBollingerBand(column='adjusted_close', window=20, width=2.0)
    sma20 = feature.SimpleMovingAverage(column='adjusted_close', window=20)
    lower_band = feature.LowerBollingerBand(column='adjusted_close', window=20, width=2.0)

spy = MyEquity(symbol='SPY')

MargotDataFrames

In systematic trading, you usually you want to look at more than one symbol. That’s where ensembles come in. MargotDataFrame really brings power to margot.data.

class MyEnsemble(MargotDataFrame):
    spy = Equity(symbol='SPY')
    iwm = Equity(symbol='IWM')
    spy_iwm_ratio = Ratio(numerator=spy.adjusted_close,
                          denominator=iwm.adjusted_close,
                          label='spy_iwm_ratio')

my_df = MyEnsemble().to_pandas()

Margot backtest

margot.backtest isn’t yet included in this release.

Margot backtest provides a base class to inherit to define your trading algorithm, an implementation of a walk-forward backetesting algorithm that produced backtests of your algorithm using margot.data.

Results from margot backtest can be analysed with pyfolio.

Getting Started

pip install margot

Next you need to make sure you have a couple of environment variables set:

export ALPHAVANTAGE_API_KEY=YOUR_API_KEY
export DATA_CACHE=PATH_TO_FOLDER_TO_STORE_HDF5_FILES

Once you’ve done that, try running the code in the notebook.

Status

This is still an early stage software project, and should not be used for live trading.

Documentation

in progress - for examples see the notebook.

Contributing

Feel free to make a pull request or chat about your idea first using issues.

Dependencies are kept to a minimum. Generally if there’s a way to do something in the standard library (or numpy / Pandas), let’s do it that way rather than add another library.

License

Margot is licensed for use under Apache 2.0. For details see the License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

margot-0.3.6.tar.gz (20.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

margot-0.3.6-py2.py3-none-any.whl (4.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file margot-0.3.6.tar.gz.

File metadata

  • Download URL: margot-0.3.6.tar.gz
  • Upload date:
  • Size: 20.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.7

File hashes

Hashes for margot-0.3.6.tar.gz
Algorithm Hash digest
SHA256 b9f651d8ffda8d20a3a4d694cfd6d9600bc5ac70c3f43998574e63ba863230a0
MD5 721b96adedd598dddfbe687d75dc40c5
BLAKE2b-256 2b22e56e3877e80325f83d4a9d204ba0f4e2e823d4251c3d2f227054a800618c

See more details on using hashes here.

File details

Details for the file margot-0.3.6-py2.py3-none-any.whl.

File metadata

  • Download URL: margot-0.3.6-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.7

File hashes

Hashes for margot-0.3.6-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 703326c0395299ef417a13e1b19efd5da14675aa37efb9e57f10efb03ee07cd9
MD5 af5b20c125fed344138dcca4b6cdc8cb
BLAKE2b-256 965d1fa216d5dba36a2a304bd8c8d446b607ad1ef227210bc408d045edf699a0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page