Python based algo trading platform for IB.
Project description
.. raw:: html
====== alpyen
.. image:: https://img.shields.io/pypi/v/alpyen.svg
:target: https://pypi.python.org/pypi/alpyen
.. image:: https://readthedocs.org/projects/alpyen/badge/?version=latest
:target: https://alpyen.readthedocs.io/en/latest/?version=latest
:alt: Documentation Status
.. image:: https://pepy.tech/badge/alpyen
:target: https://pepy.tech/project/alpyen
.. image:: https://img.shields.io/github/repo-size/peeeffchang/alpyen
:alt: GitHub repo size
.. image:: https://img.shields.io/pypi/pyversions/alpyen
.. image:: https://img.shields.io/github/commit-activity/m/peeeffchang/alpyen
A lite-weight backtesting and live-trading algo engine for multiple brokers:
- Interactive Brokers (IB)
- Gemini
License: GNU General Public License v3 Documentation: https://alpyen.readthedocs.io.
Features
Providing a trading platform for IB that includes the functions of
- Data gathering
- Algo signal calculation
- Automatic trading
- Book monitoring and portfolio management
Current Version
Able to perform backtesting and live trading.
Support This Project
- Use and discuss us
- Report a bug
- Submit a bug fix
Installation
::
pip install alpyen
"Hello World"/Quick Start
For a quick demo, do the following:
- Install alpyen
- Create a py file that perform either backtesting (use the test_backtesting_macrossing_reshuffle test as an example) or live trading (use the test_live_trading test as an example)
- For live trading, create a yml control file (use the test_control.yml file as an example)
Example
.. code-block:: python
from alpyen import datacontainer
from alpyen import backtesting
from alpyen import utils
# Read data (assuming that BBH.csv from Yahoo Finance is in the Data folder)
data_folder = 'Data\\'
ticker_name = 'BBH'
file_path = os.path.join(os.path.dirname(__file__), data_folder)
short_lookback = 5
long_lookback = 200
short_lookback_name = ticker_name + '_MA_' + str(short_lookback)
long_lookback_name = ticker_name + '_MA_' + str(long_lookback)
ticker_names = [ticker_name]
all_input = datacontainer.DataUtils.aggregate_yahoo_data(ticker_names, file_path)
# Subscribe to signals
signal_info_dict = {}
signal_info_dict[short_lookback_name]\
= utils.SignalInfo('MA', ticker_names, [], [], short_lookback, {})
signal_info_dict[long_lookback_name]\
= utils.SignalInfo('MA', ticker_names, [], [], long_lookback, {})
# Subscribe to strategies
strategy_info_dict = {}
strategy_name = ticker_name + '_MACrossing_01'
strategy_info_dict[strategy_name] = utils.StrategyInfo(
'MACrossing',
[short_lookback_name, long_lookback_name],
1, {}, ticker_names, combo_definition={'combo1': [1.0]})
# 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 / MA-crossing trading strategy; and
- weighted momentum signal / VAA strategy
are built-in in the package, and 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:
.. code-block:: python
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.
.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _audreyr/cookiecutter-pypackage
: https://github.com/audreyr/cookiecutter-pypackage
======= History
0.1.0 (2021-09-12)
- First release on PyPI.
0.1.1 (2021-10-12)
0.1.2 (2021-10-17)
0.1.3 (2021-11-12)
0.1.4 (2021-11-19)
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
Built Distribution
File details
Details for the file alpyen-1.2.0.tar.gz
.
File metadata
- Download URL: alpyen-1.2.0.tar.gz
- Upload date:
- Size: 534.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/30.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.42.1 importlib-metadata/1.5.0 keyring/21.1.0 rfc3986/1.5.0 colorama/0.4.4 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 950bf77e8d82fd1821309ef35d89f094836fa272929a603b27adeafd6b107fdf |
|
MD5 | 672e79018a9067124f1dd9e1df247d39 |
|
BLAKE2b-256 | d49d0db92bd01fbb0ffe792a765062acee4ff8986de8696f3091a37116df2d28 |
File details
Details for the file alpyen-1.2.0-py2.py3-none-any.whl
.
File metadata
- Download URL: alpyen-1.2.0-py2.py3-none-any.whl
- Upload date:
- Size: 34.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/30.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.42.1 importlib-metadata/1.5.0 keyring/21.1.0 rfc3986/1.5.0 colorama/0.4.4 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc9849874a2ede05354e1851d641f6ae91647faff68fa8407965f996f2233543 |
|
MD5 | 812978b7ce917d4c339891e08f557277 |
|
BLAKE2b-256 | 71f361250f31f9e97163c14f366ee749dae2ec08ee82b42b2cfe1c5130bb3d90 |