Giter VIP home page Giter VIP logo

alpyne's Introduction

alpyen

right-aligned logo in README

Documentation Status https://pepy.tech/badge/alpyen

GitHub repo size

https://img.shields.io/pypi/pyversions/alpyen

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:

  1. Install alpyen
  2. 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)
  3. For live trading, create a yml control file (use the test_control.yml file as an example)

Example

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:

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.

alpyne's People

Contributors

peeeffchang avatar

Stargazers

 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.