Giter VIP home page Giter VIP logo

ai-investibot's Introduction

AI-InvestiBot

Table of Contents

Introduction

This repository is currently under active development. The project aims to be more accurate than other projects by providing innovative features not often found in other stock bots.

Contact Us

Discord: https://dsc.gg/ai-investibot/ (Uses a dsc link in order to get a custom link)

Features

  • Unique Indicators: The project uses unique indicators.
  • Non-Daily Indicators: Unlike most bots, AI-InvestiBot uses indicators that are not limited to daily data, such as earnings.
  • Flexible:
    • Flexible Model Creation Users have the freedom to create their own models using the information_keys feature.
    • Fexible AI: A callback function can be passed to the train function(traning the model) that creates the custom model. This allows you do use any type of model you want
  • ResourceManager Class: The ResourceManager class is implemented to manage and direct financial resources effectively.
  • Predictions for Multiple Companies: This project offers predictions for multiple companies per day, rather than just one.
  • Holding Stocks: The stock bot has the capability to hold stocks.
  • Lambda Version: Allows the bot to be run without keeping a laptop open(It is also very, very cheap to use).
  • AI Techniques such as:
    • Price AND Percentage Models
    • Data Augmentation
    • Transfer learning
    • Early Stopping
    • Etc
  • Active Development Planned: Taking a small break from the project.

Planned Additions

The following features are planned to be added in the future:

  • Getting the model to learn on the data.
  • Easy way to add many models using call backs
  • Reach Library standards such as:
    • Bug Fixes
    • More Documentation
    • More Flexibility
    • More verification of a high accuracy rate.
  • Fix Issues added by PercentageModel Refactor

How To Start

WARNING: It looks like the Model is currently off by a few days of something. Do NOT use to make money yet.

  1. Get data using get_info.py
  2. Train and save the models, look at the end of models.py for an example of how to do this. You have to train and save it yourself since I have removed everything in the Stocks folder.
  3. Look at the current implementations in implementation.py.
  4. Use them if you like them or add more if you want to customize it(lamda version does not work)

P.S: Remember to change the api key in secret key.

How It Works

Information Retrieval and Caching

The project retrieves and caches information in the following manner:

  • The get_info.py file processes all data obtained from yfinance.
  • The information is stored as a dictionary in a JSON file.
  • The information_keys feature retrieves values from each key in the JSON.

Unique Indicators in Models

The models in this project incorporate unique indicators as follows:

  • Models utilize the information_keys attribute.
  • These keys correspond to the names of indicators created from get_info.py.
  • The model retrieves a dictionary from the JSON file and extracts the list associated with the key.
  • Features in the form of NumPy arrays are then fed into the Sequential model.
  • Use different Features by inputing a list of information_keys into either PriceModel or PercentageModel

Stock Bot Functionality

The stock bot operates based on the following principles:

  • The AI is implemented into the childclasses of BaseModel.
  • Base Model: This is the parent class for all other models and has no data of its own unless specified. Holds functionality for bot NOT AI.
  • Price Model: This is the base child class that uses data scaled btw high and low of company data and outputs the predicted price
  • Percentage Model: This is the base child class that uses data scaled btw high and low of a window of data(the past num days) and outputs the predicted % change in price
  • Training, testing, saving, and loading are handled by separate functions(Ensuring quality code).
  • Training can be a test, using only the first 80% of data
  • Information for each day is obtained through two methods:
    • Method 1: Offline (past data only)
      • Relies on data from get_info.py.
      • In this case, model.cached_info is always a dictionary or None.
    • Method 2: Online
      • Utilizes data from yfinance.
      • Once 280 days of past data are obtained, the oldest day is removed, and a new day is added at the end.
      • In this case, model.cached_info is always a pandas DataFrame or None.

How the Bot Runs

  • The bot identifies the most promising stocks.
  • It utilizes your available funds, following the rules set by the ResourceManager class.
  • Stocks are held if their performance exceeds a certain threshold (MAX_HOLD_INDEX).
  • Stocks are bought if specific conditions are met, including:
    • All models' profit ratios are above PREDICTION_THRESHOLD.
    • The average profit ratio exceeds the RISK_REWARD_RATIO.
  • The lambda and loop implemenations use the same base functions.
    • Therefore, more implementations can easily be added

Earnings Processing

The project processes earnings in the following manner:

  • All earnings are obtained and separated into two lists: dates and the difference between actual and estimated values.
  • During runtime, earnings outside of a specific range are removed.
  • The processed earnings are transformed into a continuous list:
    • Earnings are represented as 0 if no earnings occurred on a specific day.
    • The difference between the expected and actual values is used when earnings occur.
  • Certain limitations prevent the stock bot from detecting earnings in some cases, which is an issue currently being addressed.

RESULTS(FOR Price Model only)

This project offers various models to choose from, including:

  • Base Model: This is the parent class for all other models and has no data of its own unless specified.

  • Price Model: This is the base class that uses data scaled btw high and low of company data and outputs the predicted price

  • Percentage Model: This is the base class that uses data scaled btw high and low of the window data and outputs the predicted % change in price

  • Day Trade Model:

    • Directional Test: 97.88732394366197

    • Spatial Test: 95.07042253521126

    • Test RMSE: 1.3360315740699096

    • Test RMSSE: 24.995202143966043

  • Impulse MACD Model:

    • Directional Test: 96.47887323943662
    • Spatial Test: 95.07042253521126
    • Test RMSE: 0.6948929238336506
    • Test RMSSE: 7.995023009594582
  • Reversal Model:

    • Directional Test: 97.1830985915493
    • Spatial Test: 95.07042253521126
    • Test RMSE: 1.1254591884267255
    • Test RMSSE: 24.42872924716995
  • Earnings Model:

    • Directional Test: 98.59154929577466
    • Spatial Test: 96.47887323943662
    • Test RMSE: 0.8682655262847199
    • Test RMSSE: 15.578685178744083
  • RSI Model:

    • Directional Test: 97.14285714285714
    • Spatial Test: 95.71428571428572
    • Test RMSE: 0.5837482545772584
    • Test RMSSE: 22.226485198086568
  • Breakout Model:

    • Directional Test: 97.88732394366197
    • Spatial Test: 93.66197183098592
    • Test RMSE: 1.0865094554480963
    • Test RMSSE: 21.424078134818295
  • Super Trends Model:

    • Directional Test: 97.88732394366197
    • Spatial Test: 92.25352112676056
    • Test RMSE: 1.6947722097944153
    • Test RMSSE: 78.60191098762428

model.test(show_graph=True) Figure_1

How to interpret

  • You can have have confidence becuase:

    • The model has never seen the data
    • Not over fitted becuase Model used Early stopping
    • NO Transfer learning applied. Once transfer is applied, it will become even more accuracte(hopefully).
    • It has been tested on other similar stocks(on PercentageModel only) and has shown equally promising results
    • The only thing that may be wrong is that the model may accedently get future data.
  • Directional Test is how often the predicted and test moved together.

    • Directional Test: 93.26530612244898
    • Means 93% accuracy
  • Spatial is what sees if the predicted is correctly positioned in relation to the real data. So if it goes up, the predicted should be over, but if it goes down, the predicted should go down

    • Spatial Test: 94.26530612244898
    • Means 94% accuracy
  • RMSE and RMSSE shows how incorrect the bot is. RMSSE is more impacted by larger differences. Remember that the lower the value of these metrics, the better the performance.

ai-investibot's People

Contributors

alexpvpmindustry avatar caidol avatar dependabot[bot] avatar gran4 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ai-investibot's Issues

Add more Data Augmentation

BY:

  • Shifting the timeframe
    This will simulate different timeframes(I like this idea the least).
  • Scaling data
    To simulate different magnitudes and make the model become more robust to different stock price ranges.
  • Injecting noise
    This will mimic real-world fluctuations.

Through multiple trains on each piece of changed data.

Fix pylint issues

None worked so far. It broke after I made pylint only scan changed files.

cant run implementation.py

Describe the bug
i ran the implementation.py after installing requirements.txt.

(.venv) C:\Users\aatan\Documents\Github\AI-InvestiBot>c:/Users/aatan/Documents/Github/AI-InvestiBot/.venv/Scripts/python.exe c:/Users/aatan/Documents/Github/AI-InvestiBot/AI-InvestiBot/implementation.py
Traceback (most recent call last):
  File "c:\Users\aatan\Documents\Github\AI-InvestiBot\AI-InvestiBot\implementation.py", line 300, in <module>
    models, total_info_keys = load_models(strategys=[RSI_indicators])
  File "c:\Users\aatan\Documents\Github\AI-InvestiBot\AI-InvestiBot\implementation.py", line 91, in load_models
    model = model_class(stock_symbol=company, information_keys=strategy)
  File "c:\Users\aatan\Documents\Github\AI-InvestiBot\AI-InvestiBot\models.py", line 842, in __init__
    super().__init__(start_date=start_date,
  File "c:\Users\aatan\Documents\Github\AI-InvestiBot\AI-InvestiBot\models.py", line 88, in __init__
    with open(f'Stocks/{stock_symbol}/dynamic_tuning.json', 'r') as file:
FileNotFoundError: [Errno 2] No such file or directory: 'Stocks/AAPL/dynamic_tuning.json'

To Reproduce

Expected behavior
it should work.....??

What version of this library is it?
latest

OS/Device + version
windows 11, python3.10, vscode with venv installed with requirements.txt.

Higher close prices are far less accurate

Describe the bug
Higher close prices are predicted far lower then they should. This is because the stock data has less high data since stocks tend to move in an upwards trend.

To Reproduce
Test model

Expected behavior
Equal accuracy

What version of this library is it?
Latest

OS/Device + version
Mac 2020, but it will obviously happen on all versions

specify which versions of modules used.

Is your feature request related to a problem? Please describe.

specify which versions of tensorflow used....
and also for other modules.

Describe the solution you'd like
image
use pip freeze> requirements.txt to save the versions of modules that was used.
and upload that requirements.txt file

Refactor Model

Is your feature request related to a problem? Please describe.
Live trading is not working.

Describe the solution you'd like
Change the way the models, especially PriceModel. It should not use 4d data.

Describe alternatives you've considered
I attempted to fix lave trading with 4d data, but it seems impossible.

Additional context
None

save figures instead of showing them in browser.

Is your feature request related to a problem? Please describe.
most times, I don't want to just view the figures.
i like to save them instead, or at least the code have to have an option to do so.

Describe the solution you'd like
maybe add a save_graph attribute? to the basic model class?

Describe alternatives you've considered
IMO, models class should be purely models, and plotting should have been another completely separate module.

Additional context
maybe we can use mplfinance to do part of the plottings.

Add a quick start guide

Is your feature request related to a problem? Please describe.
how to start using this?

Describe the solution you'd like
A quick start guide

Describe alternatives you've considered
A reading the code, but I don't see an entry point

Additional context
using google colab would be a great start

invite link is dead

Why does it not fit into the other categories

in the README.md, discord link is dead.

Describe your problem

image

OVER FITTING

Is this a bug?

P.S: Chatgpt says it is because overfitting and I think that is the most likely case

Verify high accuracy rate

Why does it not fit into the other categories
It is not a bug or an enhancement or bad structure. It is a possible bug.

Describe your problem
There is very little chance the model is 95% accurate.

Which api to use(Choose)

Leaning towards Alpaca.
Pro's and Con's of Each

Alpaca (https://alpaca.markets/): Alpaca is a commission-free stock trading platform that offers a developer-friendly API for algorithmic trading. While they do have a free tier with limited functionality, you may need to upgrade to a paid plan for full trading capabilities.

TD Ameritrade (https://developer.tdameritrade.com/): TD Ameritrade provides a comprehensive API for accessing account data, placing trades, and retrieving market data. While their API is free to use, it requires an active TD Ameritrade brokerage account.

Robinhood API (unofficial): Robinhood is a commission-free brokerage platform, but they do not provide an official API for trading. However, there are unofficial third-party libraries and APIs available that allow limited access to Robinhood's trading functionality.

Add XGBoost

Is your feature request related to a problem? Please describe.
The ai is not as accurate as one would hope.

Describe the solution you'd like
Add XGBoost and mix it with tensorflow. This would increase accuracy by build multiple models one after the other. Each new model tries to correct the mistakes made by the previous models.

make api keys a separate file, (its easier for others to contribute code as well)

Is your feature request related to a problem? Please describe.
API keys and secrets should not be hard coded onto github. one way is the following:

Describe the solution you'd like
create a text file with keys inside as json.
image
then load the keys within the script.
(after import json)
image

use .gitignore to ignore the file, so that it doesn't get pushed into the public repo for everyone to see.
image

Describe alternatives you've considered
other libraries/methods are available, but this is the simplest solution imo.

Transfer Learning

Describe the solution you'd like
Models learn off diff stocks. Should be easy since it is already scaled between 0 and 1. Just a bool into the train function.
This will make the model more generalized with more information.
It has to be trained on the actual stock last so it is fined tuned to it.

Add a new model base

Is your feature request related to a problem? Please describe.
The accuracy on higher features is low. Look at: #77
Will partial fix it

Describe the solution you'd like
I would like the model to min-max scale per time frame(like past num_days) and the output as accuracy. This would make the model more stable. A way to add this to the existing model would be even better.

Describe alternatives you've considered
More methods to increase original one.

Make the project more friendly to being a library

What is wrong and why is it wrong
The project can not really be used as a library currently. It is structured solely for the bot. However, it should be easy to change it so it can be used for any stock related thing. Like getting the relevant years, etc.

Where is it wrong?
Just everywhere

Check List

  • Update type hints and docstrings
  • Return values
  • Option to not download the heavy Stocks Folder
  • Add a read the docs
  • Update Readme
  • Add tests
  • Finish Alpha version project
  • Add a way to pip install
  • Update requirements.txt

Improve some of the model's performance(How correct it is, not speed)

DayTradeModel is wrong more then it is right on the direction of the stock(like 48% correct).
ImpulseMACDModel is slightly more accurate then 50%(like 50-55% correct).

Problems/enhancements:

  • Stopping overfitting(early stop):
  • Getting better architecture(currently LSTM):
  • Specific stock training period for each stock
  • Add more Data Augmentation
  • Transfer learning

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.