Skip to main content

Pandas and SciKit Learn compatible open source interface for algorithmic trading functions.

Project description

InferTrade

InferTrade

infertrade is an open source trading and investment strategy library designed for accessibility and compatibility.

The infertrade package seeks to achieve four objectives:

  • Simplicity: a simple pandas to pandas interface that those experienced in trading but new to Python can easily use.

  • Gateway to data science: classes that allow rules created for the infertrade simple interface to be used with scikit-learn functionality for prediction and calibration. (fit, transform, predict, pipelines, gridsearch) and scikit-learn compatible libraries, like feature-engine.

  • The best open source trading strategies: wrapping functionality to allow strategies from any open source Python libraries with compatible licences, such as ta and ta-lib to be used with the infertrade interface.

The project is licenced under the Apache 2.0 licence.

Connection to InferTrade.com

Many thanks for looking into the infertrade package!

I created InferTrade.com to provide cutting edge statistical analysis in an accessible free interface. The intention was to help individuals and small firms have access to the same quality of analysis as large institutions for systematic trading and to allow more time to be spent on creating good signals rather than backtesting and strategy verification. If someone has done the hard work of gaining insights into markets I wanted them to be able to compete in a landscape of increasingly automated statistically-driven market participants. A huge amount of effort has been made by the trading and AI/ML communities to create open source packages with powerful diagnostic functionality, which means you do not need to build a large and complex in-house analytics library to be able to support your investment decisions with solid statistical machine learning. However there remain educational and technical barriers to using this community-created wealth if you are not an experience programmer or do not have mathematical training. I want InferTrade.com to allow everyone trading in markets to have access without barriers - cost, training or time - to be competitive, with an easy to use interface that both provides direct analysis and education insights to support your trading.

The initial impetus for the creation of this open source package, infertrade was to ensure any of our users finding an attractive strategy on InferTrade.com could easily implement the rule in Python and have full access to the code to fully understand every aspect of how it works. By adding wrapper for existing libraries we hope to support further independent backtesting by users with their own preferred choice of trading libraries. We at InferStat heavily use open source in delivering InferTrade.com's functionality and we also wanted to give something back to the trading and data science community. The Apache 2.0 licence is a permissive licence, so that you can use or build upon infertrade for your personal, community or commercial projects.

The infertrade package and InferTrade.com will be adding functionality each week, and we are continually seeking to improve the experience and support the package and website provides for traders, portfolio managers and other users. Gaining feedback on new features is extremely helpful for us to improve our UX and design, as are any ideas for enhancements that would help you to trade better. If you would like to assist me in turning InferTrade into the leading open source trading platform we can offer participation in our Beta Testing programme (sign up link). You can also fork this repository and make direct improvements to the package.

Best, Tom Oliver

InferStat Founder and CEO

Contact Us

This was InferStat's first open source project and we welcome your thoughts for improvements to code structure, documentation or any changes that would support your use of the library.

If you would like assistance with using the infertrade you can email us at support@infertrade.com or book a video call

If you would like to contribute to the package, e.g. to add support for an additional package or library, please see our contributing information.

Quickstart

Please note the project requires Python 3.7 or higher due to dependent libraries used.

Linux installation steps:

sem-version python 3.7
wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz
tar -xzf ta-lib-0.4.0-src.tar.gz
cd ta-lib/
./configure --prefix=/usr
make
sudo make install
cd ..
pip install -r requirements.txt
pip install -r requirements-dev.txt

My First InferTrade Rule

import pandas as pd
import matplotlib.pyplot as plt

def my_first_infertrade_rule(df: pd.DataFrame) -> pd.DataFrame:
    df["allocation"] = 0.0
    df["allocation"][df.pct_change() > 0.02] = 0.5     
    return df

my_dataframe = pd.read_csv("example_market_data.csv")    
my_dataframe_with_allocations = my_first_infertrade_rule(my_dataframe)
my_dataframe_with_allocations.plot(["close"], ["allocation"])
plt.show()

image

Basic usage with community functions

"Community" functions are those declared in this repository, not retrieved from an external package. They are all exposed at infertrade.example_one.algos.community.

from infertrade.algos.community import normalised_close, scikit_signal_factory
from infertrade.data.simulate_data import simulated_market_data_4_years_gen
signal_transformer = scikit_signal_factory(normalised_close)
signal_transformer.fit_transform(simulated_market_data_4_years_gen())

Usage with TA

from infertrade.algos.community import scikit_signal_factory
from infertrade.data.simulate_data import simulated_market_data_4_years_gen
from infertrade.algos import ta_adaptor
from ta.trend import AroonIndicator
adapted_aroon = ta_adaptor(AroonIndicator, "aroon_down", window=1)
signal_transformer = scikit_signal_factory(adapted_aroon)
signal_transformer.fit_transform(simulated_market_data_4_years_gen())

Calculate positions with simple position function

from infertrade.algos.community import cps, scikit_allocation_factory
from infertrade.data.simulate_data import simulated_market_data_4_years_gen

position_transformer = scikit_allocation_factory(cps)
position_transformer.fit_transform(simulated_market_data_4_years_gen())
# TODO add example with parameters

Example of position calculation via kelly just based on signal generation

from infertrade.algos.community import scikit_signal_factory
from infertrade.data.simulate_data import simulated_market_data_4_years_gen
from infertrade.utilities.operations import PositionsFromPricePrediction, PricePredictionFromSignalRegression
from sklearn.pipeline import make_pipeline
from infertrade.algos import ta_adaptor
from ta.trend import AroonIndicator

adapted_aroon = ta_adaptor(AroonIndicator, "aroon_down", window=1)

pipeline = make_pipeline(scikit_signal_factory(adapted_aroon),
                         PricePredictionFromSignalRegression(),
                         PositionsFromPricePrediction()
                         )

pipeline.fit_transform(simulated_market_data_4_years_gen())

Creating simulated data for testing

For convenience, the infertrade.data module contains some basic functions for simulating market data.

import matplotlib.pyplot as plt
from infertrade.data.simulate_data import simulated_market_data_4_years_gen
simulated_market_data_4_years_gen().plot(y=["open", "close", "high", "low", "last"])
plt.show()

image

import matplotlib.pyplot as plt
from infertrade.data.simulate_data import simulated_correlated_equities_4_years_gen
simulated_correlated_equities_4_years_gen().plot(y=["price", "signal"])
plt.show()

image

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

infertrade-0.0.18.tar.gz (27.4 kB view details)

Uploaded Source

Built Distribution

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

infertrade-0.0.18-py3-none-any.whl (39.2 kB view details)

Uploaded Python 3

File details

Details for the file infertrade-0.0.18.tar.gz.

File metadata

  • Download URL: infertrade-0.0.18.tar.gz
  • Upload date:
  • Size: 27.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.10

File hashes

Hashes for infertrade-0.0.18.tar.gz
Algorithm Hash digest
SHA256 a54959e64894671e280a79487a5204f512af9f785112a24bc71af97bee1e32ce
MD5 31843b8e48890c35997db3bb958090ad
BLAKE2b-256 b4d59da665e7aa534b9a8b0b8a3845ca1813ef107ec9dfff208dc318f93732c1

See more details on using hashes here.

File details

Details for the file infertrade-0.0.18-py3-none-any.whl.

File metadata

  • Download URL: infertrade-0.0.18-py3-none-any.whl
  • Upload date:
  • Size: 39.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.10

File hashes

Hashes for infertrade-0.0.18-py3-none-any.whl
Algorithm Hash digest
SHA256 13493618e092790d15fe06fafd578938671a1d281415775cbd81701918cb0d76
MD5 8a59fdca7d2acc868f0f3ee405e9e812
BLAKE2b-256 4a6969d759fbfe487ef0226c43cfb5cfb53e9949dc5d7c6add3fa11b53a639b9

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