The repository for freeCodeCamp's YouTube course, Algorithmic Trading in Python

Overview

Algorithmic Trading in Python

This repository

Course Outline

  • Section 1: Algorithmic Trading Fundamentals
    • What is Algorithmic Trading?
    • The Differences Between Real-World Algorithmic Trading and This Course
  • Section 2: Course Configuration & API Basics
    • How to Install Python
    • Cloning The Repository & Installing Our Dependencies
    • Jupyter Notebook Basics
    • The Basics of API Requests
  • Section 3: Building An Equal-Weight S&P 500 Index Fund
    • Theory & Concepts
    • Importing our Constituents
    • Pulling Data For Our Constituents
    • Calculating Weights
    • Generating Our Output File
    • Additional Project Ideas
  • Section 4: Building A Quantitative Momentum Investing Strategy
    • Theory & Concepts
    • Pulling Data For Our Constituents
    • Calculating Weights
    • Generating Our Output File
    • Additional Project Ideas
  • Section 5: Building A Quantitative Value Investing Strategy
    • Theory & Concepts
    • Importing our Constituents
    • Pulling Data For Our Constituents
    • Calculating Weights
    • Generating Our Output File
    • Additional Project Ideas
Comments
  • KeyError: 'WLTW'

    KeyError: 'WLTW'

    Here is my code:

    def chunks(lst, n): for i in range(0, len(lst), n): yield lst[i:i + n]

    symbol_groups = list(chunks(stocks['Ticker'],100)) symbol_strings = [] for i in range(0, len(symbol_groups)): symbol_strings.append(','.join(symbol_groups[i])) #print(symbol_strings[i]) final_dataframe = pd.DataFrame(columns = my_columns)

    for symbol_string in symbol_strings: batch_api_call_url = f'https://sandbox.iexapis.com/stable/stock/market/batch?symbols={symbol_string}&types=quote&token={IEX_CLOUD_API_TOKEN}' data = requests.get(batch_api_call_url).json() for symbol in symbol_string.split(','): final_dataframe = final_dataframe.append( pd.Series( [ symbol, data[symbol]['quote']['latestPrice'], data[symbol]['quote']['marketCap'], 'N/A' ], index = my_columns), ignore_index = True ) final_dataframe

    Here is the error code:

    (Cannot paste the pic here for some reason)

    But i get a KeyError: 'WLTW'

    I have no idea how to fix this, and i can't find any result on google. Please help.

    opened by dekacypher 15
  • Problem with 'None' values in One-Year, Six-Month, Three-Month, One-Month Price Returns

    Problem with 'None' values in One-Year, Six-Month, Three-Month, One-Month Price Returns

    If any of the values in the One-Year, Six-Month, Three-Month, One-Month Price Returns is 'None' then the 'percentileofscore' function will error because it cannot match a float against a NoneType.

    To fix this I added the following in the creation of the data series for each price return column. xxx is the time period:

    float(0 if data[symbol]['stats']['xxxChangePercent'] is None else data[symbol]['stats']['xxxChangePercent'])

    I am not sure if there is a better solution.

    opened by brucemontegani 4
  • Loading file to Jupyter Error

    Loading file to Jupyter Error

    Hi Nick,

    First of all, thank you for the Youtube video, it is really AWESOME.

    I was try to follow your steps but get stuck to load the equal weighted S&P 500 file into Jupyter. The error shows as below:

    "Unreadable Notebook: C:\Users****\Notebooks\001_equal_weight_S&P_500.ipynb NotJSONError("Notebook does not appear to be JSON: '\n\n\n\n\n\n\n<html lang...")"

    Any idea what is wrong with the file? or if its my Jupyter issue?

    Thanks, Steven

    opened by Handanview 3
  • Key Error: DISCA

    Key Error: DISCA

    I think there is something wrong with pulling the DISCA ticker data. When I remove the [:1] limit for looping to take all tickers at a time, it shows error with Key Error : DISCA.

    opened by SidBehal 1
  • Help, issue with request I believe.

    Help, issue with request I believe.

    https://forum.freecodecamp.org/t/issue-with-algorithmic-trading-python-course/541335/3

    in that link it tells what I have done with the versions of python and packages. I loaded the requirements.txt.

    opened by lacekim 1
  •  S&P 500 stocks: getting 600 stocks after the batch_api_call_url instead of 505 and last stock is CME and not ZTS

    S&P 500 stocks: getting 600 stocks after the batch_api_call_url instead of 505 and last stock is CME and not ZTS

    Hi, after executing the piece of code where we use the batch_api_call_url my final_dataframe contains only the first 100 stocks, but repeats them 6 times so i end up with 600 stocks with the last one being CME. It seems as if the final_dataframe.append function is not doing a proper job.

    `for symbol_string in symbol_strings: batch_api_call_url = f'https://sandbox.iexapis.com/stable/stock/market/batch?symbols={symbol_string}&types=quote&token={IEX_CLOUD_API_TOKEN}'
    data = requests.get(batch_api_call_url).json() for symbol in symbol_string.split(','): final_dataframe = final_dataframe.append( pd.Series([symbol, data[symbol]['quote']['latestPrice'], data[symbol]['quote']['marketCap'], 'N/A'], index = my_columns), ignore_index = True)

    final_dataframe`

    Please advise,

    Best, Stefan

    opened by Avitohol17 1
  • I keep getting JSONDecodeError

    I keep getting JSONDecodeError

    My code from the section "Looping Through The Tickers in Our List of Stocks": Screen Shot 2022-01-19 at 21 15 14

    The error: Screen Shot 2022-01-19 at 21 15 49

    I don't understand what is wrong with my code, i wrote exactly like code from the Algorithmic Trading in Python Course.

    And when i print the final_dataframe, the output only shows 484 stocks, and not 505 as in the .csv document? Why is that?

    Screen Shot 2022-01-19 at 21 20 05
    opened by dekacypher 1
  • Bump numpy from 1.17.4 to 1.22.0

    Bump numpy from 1.17.4 to 1.22.0

    opened by RickyLam11 0
  • Error in batch API call section

    Error in batch API call section

    I'm getting this error--the finished code is throwing a different error when I C&P it in. Any ideas? Thanks everyone and apologies if this is a noob question! The course is great and I'm a former code writer jumping in the deep end to learn some Python.

    data_error_msg

    opened by rodneyholloway 1
  • Looping Through The Tickers in Our List of Stocks doesn't work

    Looping Through The Tickers in Our List of Stocks doesn't work

    I got this error when running the code: image I have tried several things but doesn't work. Anyone help me pls! P/S: this loop can only create 134 tickers, does this mean something happened with the 135th?

    opened by mpquochung 1
  • append method is deprecated

    append method is deprecated

    I get this error

    FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead. final_dataframe = final_dataframe.append(

    Have tried several things now with the pd.concat without luck. It's in "Looping Through The Tickers in Our List of Stocks"

    final_dataframe = pd.DataFrame(columns = my_columns) for stock in stocks["Ticker"][:4]: api_url = f"https://sandbox.iexapis.com/stable/stock/{stock}/quote/?token={IEX_CLOUD_API_TOKEN}" data = requests.get(api_url).json() final_dataframe = final_dataframe.append( pd.Series([symbol, data['latestPrice'], data['marketCap'], 'N/A'], index = my_columns), ignore_index = True)

    opened by solareklips 2
  • Bump numpy from 1.17.4 to 1.22.0

    Bump numpy from 1.17.4 to 1.22.0

    Bumps numpy from 1.17.4 to 1.22.0.

    Release notes

    Sourced from numpy's releases.

    v1.22.0

    NumPy 1.22.0 Release Notes

    NumPy 1.22.0 is a big release featuring the work of 153 contributors spread over 609 pull requests. There have been many improvements, highlights are:

    • Annotations of the main namespace are essentially complete. Upstream is a moving target, so there will likely be further improvements, but the major work is done. This is probably the most user visible enhancement in this release.
    • A preliminary version of the proposed Array-API is provided. This is a step in creating a standard collection of functions that can be used across application such as CuPy and JAX.
    • NumPy now has a DLPack backend. DLPack provides a common interchange format for array (tensor) data.
    • New methods for quantile, percentile, and related functions. The new methods provide a complete set of the methods commonly found in the literature.
    • A new configurable allocator for use by downstream projects.

    These are in addition to the ongoing work to provide SIMD support for commonly used functions, improvements to F2PY, and better documentation.

    The Python versions supported in this release are 3.8-3.10, Python 3.7 has been dropped. Note that 32 bit wheels are only provided for Python 3.8 and 3.9 on Windows, all other wheels are 64 bits on account of Ubuntu, Fedora, and other Linux distributions dropping 32 bit support. All 64 bit wheels are also linked with 64 bit integer OpenBLAS, which should fix the occasional problems encountered by folks using truly huge arrays.

    Expired deprecations

    Deprecated numeric style dtype strings have been removed

    Using the strings "Bytes0", "Datetime64", "Str0", "Uint32", and "Uint64" as a dtype will now raise a TypeError.

    (gh-19539)

    Expired deprecations for loads, ndfromtxt, and mafromtxt in npyio

    numpy.loads was deprecated in v1.15, with the recommendation that users use pickle.loads instead. ndfromtxt and mafromtxt were both deprecated in v1.17 - users should use numpy.genfromtxt instead with the appropriate value for the usemask parameter.

    (gh-19615)

    ... (truncated)

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
Owner
Nick McCullum
I run tech at @SureDividend & teach software engineering, machine learning, and data science on my website at nickmccullum.com.
Nick McCullum
A resource for learning about deep learning techniques from regression to LSTM and Reinforcement Learning using financial data and the fitness functions of algorithmic trading

A tour through tensorflow with financial data I present several models ranging in complexity from simple regression to LSTM and policy networks. The s

null 195 Dec 7, 2022
Algorithmic trading with deep learning experiments

Deep-Trading Algorithmic trading with deep learning experiments. Now released part one - simple time series forecasting. I plan to implement more soph

Alex Honchar 1.4k Jan 2, 2023
Algorithmic Trading using RNN

Deep-Trading This an implementation adapted from Rachnog Neural networks for algorithmic trading. Part One — Simple time series forecasting and this c

Hazem Nomer 29 Sep 4, 2022
This project is a loose implementation of paper "Algorithmic Financial Trading with Deep Convolutional Neural Networks: Time Series to Image Conversion Approach"

Stock Market Buy/Sell/Hold prediction Using convolutional Neural Network This repo is an attempt to implement the research paper titled "Algorithmic F

Asutosh Nayak 136 Dec 28, 2022
Trading Gym is an open source project for the development of reinforcement learning algorithms in the context of trading.

Trading Gym Trading Gym is an open-source project for the development of reinforcement learning algorithms in the context of trading. It is currently

Dimitry Foures 535 Nov 15, 2022
This is a simple backtesting framework to help you test your crypto currency trading. It includes a way to download and store historical crypto data and to execute a trading strategy.

You can use this simple crypto backtesting script to ensure your trading strategy is successful Minimal setup required and works well with static TP a

Andrei 154 Sep 12, 2022
A general-purpose, flexible, and easy-to-use simulator alongside an OpenAI Gym trading environment for MetaTrader 5 trading platform (Approved by OpenAI Gym)

gym-mtsim: OpenAI Gym - MetaTrader 5 Simulator MtSim is a simulator for the MetaTrader 5 trading platform alongside an OpenAI Gym environment for rein

Mohammad Amin Haghpanah 184 Dec 31, 2022
All course materials for the Zero to Mastery Deep Learning with TensorFlow course.

All course materials for the Zero to Mastery Deep Learning with TensorFlow course.

Daniel Bourke 3.4k Jan 7, 2023
CARLA: A Python Library to Benchmark Algorithmic Recourse and Counterfactual Explanation Algorithms

CARLA - Counterfactual And Recourse Library CARLA is a python library to benchmark counterfactual explanation and recourse models. It comes out-of-the

Carla Recourse 200 Dec 28, 2022
Submission to Twitter's algorithmic bias bounty challenge

Twitter Ethics Challenge: Pixel Perfect Submission to Twitter's algorithmic bias bounty challenge, by Travis Hoppe (@metasemantic). Abstract We build

Travis Hoppe 4 Aug 19, 2022
The CLRS Algorithmic Reasoning Benchmark

Learning representations of algorithms is an emerging area of machine learning, seeking to bridge concepts from neural networks with classical algorithms.

DeepMind 251 Jan 5, 2023
Re-implementation of 'Grokking: Generalization beyond overfitting on small algorithmic datasets'

Re-implementation of the paper 'Grokking: Generalization beyond overfitting on small algorithmic datasets' Paper Original paper can be found here Data

Tom Lieberum 38 Aug 9, 2022
PyTorch implementation of Grokking: Generalization Beyond Overfitting on Small Algorithmic Datasets

Simple PyTorch Implementation of "Grokking" Implementation of Grokking: Generalization Beyond Overfitting on Small Algorithmic Datasets Usage Running

Teddy Koker 15 Sep 29, 2022
Repository of Jupyter notebook tutorials for teaching the Deep Learning Course at the University of Amsterdam (MSc AI), Fall 2020

Repository of Jupyter notebook tutorials for teaching the Deep Learning Course at the University of Amsterdam (MSc AI), Fall 2020

Phillip Lippe 1.1k Jan 7, 2023
Reinforcement-learning - Repository of the class assignment questions for the course on reinforcement learning

DSE 314/614: Reinforcement Learning This repository containing reinforcement lea

Manav Mishra 4 Apr 15, 2022
Technical Indicators implemented in Python only using Numpy-Pandas as Magic - Very Very Fast! Very tiny! Stock Market Financial Technical Analysis Python library . Quant Trading automation or cryptocoin exchange

MyTT Technical Indicators implemented in Python only using Numpy-Pandas as Magic - Very Very Fast! to Stock Market Financial Technical Analysis Python

dev 34 Dec 27, 2022
Code for How To Create A Fully Automated AI Based Trading System With Python

AI Based Trading System This code works as a boilerplate for an AI based trading system with yfinance as data source and RobinHood or Alpaca as broker

Rubén 196 Jan 5, 2023
A Python-based development platform for automated trading systems - from backtesting to optimisation to livetrading.

AutoTrader AutoTrader is Python-based platform intended to help in the development, optimisation and deployment of automated trading systems. From sim

Kieran Mackle 485 Jan 9, 2023
Trading Strategies for Freqtrade

Freqtrade Strategies Strategies for Freqtrade, developed primarily in a partnership between @werkkrew and @JimmyNixx from the Freqtrade Discord. Use t

Bryan Chain 242 Jan 7, 2023