Skip to main content

Python based algo trading platform for IB.

Project description

alpyen

https://img.shields.io/pypi/v/alpyen.svg Documentation Status https://pepy.tech/badge/alpyen GitHub repo size

A lite-weight backtesting and live-trading algo engine for IB (Interactive Brokers) and other brokers.

Features

Providing a trading platform for IB that includes the functions of

  • Data gathering

  • Algo signal calculation

  • Automatic trading

  • Book management

Current Version

Able to perform backtesting. Live trading support in development.

Next Release

Live trading support.

Support This Project

  • Use and discuss us

  • Report a bug

  • Submit a bug fix

Installation

pip install alpyen

Example

from alpyen import datacontainer
from alpyen import backtesting

# Read data (assuming that BBH.csv from Yahoo Finance is in the Data folder)
data_folder_path = 'Data\\'
ticker_name = 'BBH'
short_lookback = 5
long_lookback = 200
ticker_names = [ticker_name]
all_input = datacontainer.DataUtils.aggregate_yahoo_data(ticker_names, data_folder_path)

# Subscribe to signals
signal_info_dict = {}
signal_info_dict[ticker_name + '_MA_' + str(short_lookback)]\
    = backtesting.SignalInfo(ticker_names, [short_lookback], 'MA')
signal_info_dict[ticker_name + '_MA_' + str(long_lookback)]\
    = backtesting.SignalInfo(ticker_names, [long_lookback], 'MA')

# Subscribe to strategies
strategy_info_dict = {}
strategy_name = ticker_name + '_MACrossing_01'
strategy_info_dict[strategy_name] = backtesting.StrategyInfo(
    [ticker_name + '_MA_' + str(short_lookback), ticker_name + '_MA_' + str(long_lookback)],
    [1], [ticker_name], 'MACrossing')

# Create backtester and run backtest
number_path = 1000
my_backtester = backtesting.Backtester(all_input, ticker_names, signal_info_dict, strategy_info_dict,
                                       number_path)
my_backtester.run_backtest()
backtest_results = my_backtester.get_results()

The moving average signal and the MA-crossing trading strategy are intended to serve as examples. Users can use them as references and create their custom signals/strategies by deriving from the SignalBase class within the signal module, and the StrategyBase class within the strategy module. Note that the package needs a unique signature string for each derived signals/strategies for reflective object creation, so for example:

class MASignal(SignalBase):
    """
    Moving average signal.
    """

    _signal_signature = 'MA'

class MACrossingStrategy(StrategyBase):
    """
    MA Crossing Strategy
    """

    _strategy_signature = 'MACrossing'

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

History

0.1.0 (2021-09-12)

  • First release on PyPI.

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

alpyen-0.1.3.tar.gz (495.3 kB view hashes)

Uploaded Source

Built Distribution

alpyen-0.1.3-py2.py3-none-any.whl (23.5 kB view hashes)

Uploaded Python 2 Python 3

Supported by

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