Algorithmic Trading with Python

Overview

Algorithmic Trading with Python

Source code for Algorithmic Trading with Python (2020) by Chris Conlan.

Paperback available for purchase on Amazon.


Useful resources

These stand-alone resources can be useful to researchers with or without the accompanying book. The rest of the material in this repository depends on explanation and context given in the book.

  • Performance metrics used to evaluate trading strategies: metrics.py
  • Common technical indicators in pure Pandas: indicators.py
  • Converting common technical indicators into ternary signals: signals.py
  • Generic grid search wrapper for numeric optimization: optimization.py
  • Object-oriented building blocks for portfolio simulation: portfolio.py
  • Generic wrapper for multi-core repeated K fold cross-validation: model.py
  • Free-to-use simulated EOD stock data and alternative data streams: data

Comments
  • pypm error

    pypm error

    I've started following the code examples, especially the simulator experiments in Chapter 4.3, and found that pypm is installed as: pip install pypm2 https://pypi.org/project/pypm2/

    Error after pypm installation:


    ImportError Traceback (most recent call last) in 1 ### pypm/simulate_portfolio.py ----> 2 from pypm import metrics, signals, data_io, simulation 3 import pandas as pd 4 5 def simulate_portfolio():

    ImportError: cannot import name 'metrics' from 'pypm' (.\anaconda3\envs\algotrading\lib\site-packages\pypm_init_.py)

    opened by joe-wojniak 3
  • Listing 4.7

    Listing 4.7

    Hello, I'm trying to run the simulator example usage in listing 4.7 but I get a "Value error: Lenghts must match"

    When I print the lengths of the variables c_series and p_series in _compute_equity_series (within the PortfolioHistory class) I indeed find out that they are different (1280 vs 2495).

    I think I have all set up correctly, my example usage of PortfolioHistory runs correctly.

    Do you have any advice?

    Thank you. The book is great.

    opened by jobquiroz 2
  • 7_2_computing_triple_barrier_labels.py

    7_2_computing_triple_barrier_labels.py

    Hello Chris I bought your book sometime last year.

    You didn't give us you example on how to use the triple barrier based on the codes you provided. I can see there are two functions if you can just explain what they are for. I know the "calculate_labels" requires the " compute_triple_barrier_labels" but the output from the two look alike when I ran them one by one.

    I have read de Prado's works and compared to his codes yours were simpler to run and test.

    Thanks

    opened by theAfricanQuant 1
  • No such file or directory: ...\\ml_model.joblib

    No such file or directory: ...\\ml_model.joblib

    When trying to run fit_alternative_data_model.py and simulate_alternative_data_portfolio.py getting the error as, No such file or directory in ml_model.joblib

    opened by VishnuVVR-369 0
  • get_years_past() clarification

    get_years_past() clarification

    trying to unpack this. pd.Series.index returns integers when I pass a log return series to this function and thus (end_date - start_date) evaluates to a single element tuple

    def get_years_past(series: pd.Series) -> float:
        """
        Calculate the years past according to the index of the series for use with
        functions that require annualization   
        """
        start_date = series.index[0]
        end_date = series.index[-1]
        return (end_date - start_date).days / 365.25
        ```
    opened by kmcminn 1
  • Clarification of where pypm package is located

    Clarification of where pypm package is located

    Recently saw this Amazon review that highlighted some confusion about where the pypm package is located: https://www.amazon.com/review/R1MBCECGQGIXL7/ref=cm_cr_srp_d_rdp_perm?ie=UTF8&ASIN=B086Y6H6YG

    The pypm package is local to the GitHub repository, as can be seen here: https://github.com/chrisconlan/algorithmic-trading-with-python/tree/master/src/pypm, and has nothing to do with this proprietary package listed on PyPI by the same name: https://pypi.org/project/PyPM/

    If you clone the GitHub repo and run the scripts from their location within the repo, you should be fine.

    documentation 
    opened by chrisconlan 0
  • 4.7 simple_simulator_usage.py: assert error

    4.7 simple_simulator_usage.py: assert error

    I bought the book.

    trying to reproduce all the simulator results.

    everything looked good with position class & portfolio class, until I encountered the below assertion error, when running the simple_simulator_usage.py.

    using all of the csv files you provided. can't continue with this error. I have not even tried my own portfolio simulation yet. Is this a known issue? thanks in advance,

    in _compute_equity_series(self) 64 c_series = self.cash_series 65 p_series = self.portfolio_value_series ---> 66 assert all(c_series.index == p_series.index), 'portfolio_series has dates not in cash_series' 67 self._equity_series = c_series + p_series

    ValueError: Lengths must match.,

    opened by Kerberos007 5
Owner
Chris Conlan
Financial Data Scientist. President @ Conlan Scientific. Author of Algorithmic Trading with Python and Fast Python
Chris Conlan
Algorithmic trading backtest and optimization examples using order book imbalances. (bitcoin, cryptocurrency, bitmex)

Algorithmic trading backtest and optimization examples using order book imbalances. (bitcoin, cryptocurrency, bitmex)

null 172 Dec 21, 2022
Gnat - GNAT is NOT Algorithmic Trading

GNAT GNAT is NOT Algorithmic Trading! GNAT is a financial tool with two goals in

Sher Shah 2 Jan 9, 2022
Algorithms-in-Python - Programs related to DSA in Python for placement practice

Algorithms-in-Python Programs related to DSA in Python for placement practice CO

MAINAK CHAUDHURI 2 Feb 2, 2022
Minimal examples of data structures and algorithms in Python

Pythonic Data Structures and Algorithms Minimal and clean example implementations of data structures and algorithms in Python 3. Contributing Thanks f

Keon 22k Jan 9, 2023
Repository for data structure and algorithms in Python for coding interviews

Python Data Structures and Algorithms This repository contains questions requiring implementation of data structures and algorithms concepts. It is us

Prabhu Pant 1.9k Jan 1, 2023
Python Sorted Container Types: Sorted List, Sorted Dict, and Sorted Set

Python Sorted Containers Sorted Containers is an Apache2 licensed sorted collections library, written in pure-Python, and fast as C-extensions. Python

Grant Jenks 2.8k Jan 4, 2023
All Algorithms implemented in Python

The Algorithms - Python All algorithms implemented in Python (for education) These implementations are for learning purposes only. Therefore they may

The Algorithms 150.6k Jan 3, 2023
A collection of design patterns/idioms in Python

python-patterns A collection of design patterns and idioms in Python. Current Patterns Creational Patterns: Pattern Description abstract_factory use a

Sakis Kasampalis 36.2k Jan 5, 2023
A lightweight, object-oriented finite state machine implementation in Python with many extensions

transitions A lightweight, object-oriented state machine implementation in Python with many extensions. Compatible with Python 2.7+ and 3.0+. Installa

null 4.7k Jan 1, 2023
:computer: Data Structures and Algorithms in Python

Algorithms in Python Implementations of a few algorithms and datastructures for fun and profit! Completed Karatsuba Multiplication Basic Sorting Rabin

Prakhar Srivastav 2.9k Jan 1, 2023
Algorithms implemented in Python

Python Algorithms Library Laurent Luce Description The purpose of this library is to help you with common algorithms like: A* path finding. String Mat

Laurent Luce 264 Dec 6, 2022
A fast python implementation of the SimHash algorithm.

This Python package provides hashing algorithms for computing cohort ids of users based on their browsing history. As such, it may be used to compute cohort ids of users following Google's Federated Learning of Cohorts (FLoC) proposal.

Hybrid Theory 19 Dec 15, 2022
A command line tool for memorizing algorithms in Python by typing them.

Algo Drills A command line tool for memorizing algorithms in Python by typing them. In alpha and things will change. How it works Type out an algorith

Travis Jungroth 43 Dec 2, 2022
A genetic algorithm written in Python for educational purposes.

Genea: A Genetic Algorithm in Python Genea is a Genetic Algorithm written in Python, for educational purposes. I started writing it for fun, while lea

Dom De Felice 20 Jul 6, 2022
Python sample codes for robotics algorithms.

PythonRobotics Python codes for robotics algorithm. Table of Contents What is this? Requirements Documentation How to use Localization Extended Kalman

Atsushi Sakai 17.2k Jan 1, 2023
An implementation of ordered dithering algorithm in python as multimedia course project

One way of minimizing the size of an image is to simply reduce the number of bits you use to represent each pixel.

null 7 Dec 2, 2022
zoofs is a Python library for performing feature selection using an variety of nature inspired wrapper algorithms. The algorithms range from swarm-intelligence to physics based to Evolutionary. It's easy to use ,flexible and powerful tool to reduce your feature size.

zoofs is a Python library for performing feature selection using a variety of nature-inspired wrapper algorithms. The algorithms range from swarm-intelligence to physics-based to Evolutionary. It's easy to use , flexible and powerful tool to reduce your feature size.

Jaswinder Singh 168 Dec 30, 2022
A Python Package for Portfolio Optimization using the Critical Line Algorithm

A Python Package for Portfolio Optimization using the Critical Line Algorithm

null 19 Oct 11, 2022
The DarkRift2 networking framework written in Python 3

DarkRiftPy is Darkrift2 written in Python 3. The implementation is fully compatible with the original version. So you can write a client side on Python that connects to a Darkrift2 server written in C# using the original Darkrift2 library, and vice versa.

Anton Dobryakov 6 May 23, 2022