An application that allows you to design and test your own stock trading algorithms in an attempt to beat the market.

Overview

Author: Ryan Cullen

StockBot

StockBot is a Python application for designing and testing your own daily stock trading algorithms.

Installation

Use the package manager pip to install matplotlib and yfinance from your command line.

pip install matplotlib
pip install yfinance

Usage

You will be asked to enter a ticker for the stock that you want to test the algorithm on.

If you want to modify the algorithm and design your own, you only need to change the Decide() method. That method takes three functions, and you can decide what those are or design your own inputs. My implementation uses moving averages and their derivatives/concavity (the class for which is set up for you to use in your own algorithm).

Example Output

Here are a couple images depicting the output from an algorithm I developed.

PEN

BABA

IBM

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

The goal for this script is of course for it to be as robust and generalized as possible in terms of the data available for the user to use to design an algorithm. Add features according to whatever that means to you and submit a pull request to the feature-test branch. If if adds value to the project it will be accepted and merged.

Please make sure to update tests as appropriate.

Thanks! :)

You might also like...
This project is an Algorithm Visualizer where a user can visualize algorithms like Bubble Sort, Merge Sort, Quick Sort, Selection Sort, Linear Search and Binary Search.
This project is an Algorithm Visualizer where a user can visualize algorithms like Bubble Sort, Merge Sort, Quick Sort, Selection Sort, Linear Search and Binary Search.

Algo_Visualizer This project is an Algorithm Visualizer where a user can visualize common algorithms like "Bubble Sort", "Merge Sort", "Quick Sort", "

Lumen provides a framework for visual analytics, which allows users to build data-driven dashboards from a simple yaml specification
Lumen provides a framework for visual analytics, which allows users to build data-driven dashboards from a simple yaml specification

Lumen project provides a framework for visual analytics, which allows users to build data-driven dashboards from a simple yaml specification

Data-FX is an addon for Blender (2.9) that allows for the visualization of data with different charts
Data-FX is an addon for Blender (2.9) that allows for the visualization of data with different charts

Data-FX Data-FX is an addon for Blender (2.9) that allows for the visualization of data with different charts Currently, there are only 2 chart option

Python script to generate a visualization of various sorting algorithms, image or video.
Python script to generate a visualization of various sorting algorithms, image or video.

sorting_algo_visualizer Python script to generate a visualization of various sorting algorithms, image or video.

Visualizations of linear algebra algorithms for people who want a deep understanding
Visualizations of linear algebra algorithms for people who want a deep understanding

Visualising algorithms on symmetric matrices Examples QR algorithm and LR algorithm Here, we have a GIF animation of an interactive visualisation of t

A visualization tool made in Pygame for various pathfinding algorithms.
A visualization tool made in Pygame for various pathfinding algorithms.

Pathfinding-Visualizer 🚀 A visualization tool made in Pygame for various pathfinding algorithms. Pathfinding is closely related to the shortest path

Decision Border Visualizer for Classification Algorithms
Decision Border Visualizer for Classification Algorithms

dbv Decision Border Visualizer for Classification Algorithms Project description A python package for Machine Learning Engineers who want to visualize

This is  a web application to visualize various famous technical indicators and stocks tickers from user
This is a web application to visualize various famous technical indicators and stocks tickers from user

Visualizing Technical Indicators Using Python and Plotly. Currently facing issues hosting the application on heroku. As soon as I am able to I'll like

It's an application to calculate I from v and r. It can also plot a graph between V vs I.
It's an application to calculate I from v and r. It can also plot a graph between V vs I.

Ohm-s-Law-Visualizer It's an application to calculate I from v and r using Ohm's Law. It can also plot a graph between V vs I. Story I'm doing my Unde

Comments
  • Added feature (Shows the latest orders from stocks ran on the algorithm through a watchlist)

    Added feature (Shows the latest orders from stocks ran on the algorithm through a watchlist)

    I have added this new feature to iterate through a watchlist of stocks and return the latest order (which is on the latest date of the given stock history) for each of the stocks. Entering 'today' when asked for a ticket prints this list of orders. The 'Current performance' that is printed with the order is simply a percentage change between the entry price and the latest value of the portfolio that followed the algorithm.

    Code:

    watchlist = ['BABA', 'IBM', 'PEN', 'GOOG', 'SPCE', 'AMD', 'NIO', 'ARKG', 'PENN', 'MRNA', 'WMT', 'AAPL', 'SBUX', 'NKE', 'SNE']
    for ticker in watchlist:
            portfolio, entry_price, control_value, algo_value, prices, days = run_algo(ticker, starting_capital, starting_shares)
            order_today = portfolio.Orders[days-1]
            highlight_color = order_today['Type'] == "Buy" and 'green' or order_today['Type'] == "Sell" and 'red' or 'white'
            performance = math.floor( (algo_value-entry_price)/entry_price*100 )
            print(ticker,colored( order_today, highlight_color), "Current performance: "+ (algo_value >= entry_price and "+%" or algo_value < entry_price and "-%")+ str(performance))
    

    Output:

    BABA {'Type': 'Buy', 'Day': Timestamp('2020-12-23 00:00:00')} Current performance: +%183
    IBM {'Type': 'Hold', 'Day': Timestamp('2020-12-23 00:00:00')} Current performance: +%9
    PEN {'Type': 'Hold', 'Day': Timestamp('2020-12-23 00:00:00')} Current performance: +%270
    GOOG {'Type': 'Sell', 'Day': Timestamp('2020-12-23 00:00:00')} Current performance: +%77
    SPCE {'Type': 'Hold', 'Day': Timestamp('2020-12-23 00:00:00')} Current performance: +%230
    AMD {'Type': 'Hold', 'Day': Timestamp('2020-12-23 00:00:00')} Current performance: +%1020
    NIO {'Type': 'Sell', 'Day': Timestamp('2020-12-23 00:00:00')} Current performance: +%573
    ARKG {'Type': 'Hold', 'Day': Timestamp('2020-12-23 00:00:00')} Current performance: +%141
    PENN {'Type': 'Hold', 'Day': Timestamp('2020-12-23 00:00:00')} Current performance: +%501
    MRNA {'Type': 'Hold', 'Day': Timestamp('2020-12-23 00:00:00')} Current performance: +%460
    WMT {'Type': 'Sell', 'Day': Timestamp('2020-12-23 00:00:00')} Current performance: +%103
    AAPL {'Type': 'Hold', 'Day': Timestamp('2020-12-23 00:00:00')} Current performance: +%389
    SBUX {'Type': 'Hold', 'Day': Timestamp('2020-12-23 00:00:00')} Current performance: +%141
    NKE {'Type': 'Hold', 'Day': Timestamp('2020-12-23 00:00:00')} Current performance: +%148
    SNE {'Type': 'Hold', 'Day': Timestamp('2020-12-23 00:00:00')} Current performance: +%292
    
    opened by uatemycookie22 4
  • Runtime error

    Runtime error

    ** On entry to DGEBAL parameter number 3 had an illegal value ** On entry to DGEHRD parameter number 2 had an illegal value ** On entry to DORGHR DORGQR parameter number 2 had an illegal value ** On entry to DHSEQR parameter number 4 had an illegal value Traceback (most recent call last): File "stockbot.py", line 1, in import yfinance as yf File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\yfinance_init_.py", line 25, in from .ticker import Ticker File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\yfinance\ticker.py", line 27, in import pandas as pd File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pandas_init.py", line 11, in import(dependency) File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\numpy_init_.py", line 305, in win_os_check() File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\numpy_init.py", line 302, in _win_os_check raise RuntimeError(msg.format(file)) from None RuntimeError: The current Numpy installation ('C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\numpy\init.py') fails to pass a sanity check due to a bug in the windows runtime. See this issue for more information: https://tinyurl.com/y3dm3h86

    opened by subevilx 2
  • Feature test push

    Feature test push

    Hi, Ryan.

    So I did your 5 steps:

    1. Make changes in a new branch (Made new branch 'test' in my local repository)
    2. Commit changes
    3. Fetched your repository (git fetch ryancullen/stock-bot), then fetched your feature-test branch (git fetch origin feature-test)
    4. Merged it with my 'test' branch (git merge origin/feature-test)
    5. Can't push it with git push since I don't have access to your repository so I'm making a pull request here with the merged branch (it's also named feature-test).
    opened by uatemycookie22 1
  • Update stockbot.py

    Update stockbot.py

    Make numbers more readable: round to 2 decimal places and commas as thousands separators. f-strings are supported starting Python3.6 which makes it available pretty much in all environments.

    opened by dbond4r 1
Owner
Ryan Cullen
I am a physics major with a passion for coding and software. Please visit my LinkedIn profile below for my contact info.
Ryan Cullen
BrowZen correlates your emotional states with the web sites you visit to give you actionable insights about how you spend your time browsing the web.

BrowZen BrowZen correlates your emotional states with the web sites you visit to give you actionable insights about how you spend your time browsing t

Nick Bild 36 Sep 28, 2022
AB-test-analyzer - Python class to perform AB test analysis

AB-test-analyzer Python class to perform AB test analysis Overview This repo con

null 13 Jul 16, 2022
Eulera Dashboard is an easy and intuitive way to get a quick feel of what’s happening on the world’s market.

an easy and intuitive way to get a quick feel of what’s happening on the world’s market ! Eulera dashboard is a tool allows you to monitor historical

Salah Eddine LABIAD 4 Nov 25, 2022
A gui application to visualize various sorting algorithms using pure python.

Sorting Algorithm Visualizer A gui application to visualize various sorting algorithms using pure python. Language : Python 3 Libraries required Tkint

Rajarshi Banerjee 19 Nov 30, 2022
The implementation of the paper "HIST: A Graph-based Framework for Stock Trend Forecasting via Mining Concept-Oriented Shared Information".

The HIST framework for stock trend forecasting The implementation of the paper "HIST: A Graph-based Framework for Stock Trend Forecasting via Mining C

Wentao Xu 111 Jan 3, 2023
🐍PyNode Next allows you to easily create beautiful graph visualisations and animations

PyNode Next A complete rewrite of PyNode for the modern era. Up to five times faster than the original PyNode. PyNode Next allows you to easily create

ehne 3 Feb 12, 2022
Drug design and development team HackBio internship is a virtual bioinformatics program that introduces students and professional to advanced practical bioinformatics and its applications globally.

-Nyokong. Drug design and development team HackBio internship is a virtual bioinformatics program that introduces students and professional to advance

null 4 Aug 4, 2022
Profile and test to gain insights into the performance of your beautiful Python code

Profile and test to gain insights into the performance of your beautiful Python code View Demo - Report Bug - Request Feature QuickPotato in a nutshel

Joey Hendricks 138 Dec 6, 2022
Focus on Algorithm Design, Not on Data Wrangling

The dataTap Python library is the primary interface for using dataTap's rich data management tools. Create datasets, stream annotations, and analyze model performance all with one library.

Zensors 37 Nov 25, 2022
Here I plotted data for the average test scores across schools and class sizes across school districts.

HW_02 Here I plotted data for the average test scores across schools and class sizes across school districts. Average Test Score by Race This graph re

null 7 Oct 27, 2021