Topview Logo
  • Create viral videos with
    GPT-4o + Ads library
    Use GPT-4o to edit video empowered by Youtube & Tiktok & Facebook ads library. Turns your links or media assets into viral videos in one click.
    Try it free
    gpt video

    I Built a Trading Bot with ChatGPT

    blog thumbnail

    Introduction

    In a recent video, Siraj showcases how he built a trading bot using ChatGPT. He starts by explaining that he gave the bot $ 2,000 to trade with and uses the Alpaca dashboard for testing. He also mentions that ChatGPT assisted him in building this bot. He demonstrates how to use the bot for paper trading and later shows how to use it for live trading.

    The video begins with Siraj asking ChatGPT about the best techniques for stock prediction. ChatGPT provides a list of 10 machine learning techniques, including neural networks, random forests, and time series analysis. Siraj selects neural networks as the primary technique.

    Moving forward, Siraj asks ChatGPT to show him a Python web example for predicting the price of Yahoo stock using neural networks. ChatGPT generates the required code using libraries like scikit-learn and Keras. Siraj copies this code to his local machine and uses it to create a Python file.

    Upon running the code, Siraj encounters a missing dependency for TensorFlow. ChatGPT suggests installing TensorFlow with a specific command. Siraj follows the instructions and successfully installs the missing dependency.

    Siraj then realizes that the provided stock data is not legitimate and asks ChatGPT for a better data source. ChatGPT recommends using the Alpaca trading API, which allows real-time data access for stocks and crypto. Siraj signs up for Alpaca and obtains the necessary API keys.

    Next, Siraj asks ChatGPT to provide an example of using the Alpaca API in Python. ChatGPT provides a code snippet that fetches real-time stock data with the API. Siraj copies this code and integrates it into his existing script.

    Now comes the most critical part – selecting an advanced technique for the trading bot. Siraj asks ChatGPT about the most advanced neural network techniques for stock trading. ChatGPT suggests using deep reinforcement learning (DRL) and provides an explanation of how it works. It also offers a Python code example using the stable-baselines library for DRL.

    Since the provided example does not directly use Alpaca API, Siraj takes a small detour and explores the "finrl" library on GitHub. This library showcases how to use DRL on real-time data for stock trading. Siraj opens an example notebook from the library and explores its contents.

    The notebook explains the installation process, data retrieval using the Yahoo downloader, adding technical indicators to the data, and creating a Markov decision process (MDP). The MDP is used to train a proximal policy optimization (PPO) agent, which is the DRL agent responsible for making trading decisions.

    After training the agent, the notebook performs a backtest to evaluate how well the bot performed against the market. Finally, Siraj adds a threshold to determine when the bot should make a trade based on its predicted sharp ratio.

    To integrate the trained bot with the Alpaca API, Siraj refers to the provided code that demonstrates how to execute trades programmatically. With this function, the bot can make trades based on the agent's predictions.

    Siraj then mentions that he will deploy the bot on Versal, his preferred hosting platform, using terminal commands. The bot will run once a day and make trades automatically if the predicted sharp ratio exceeds the threshold.

    After 24 hours of running the bot, Siraj reveals that the bot made a total profit of $ 1.62 after four trades, starting with the initial $ 2,000 investment.

    Keywords

    trading bot, ChatGPT, machine learning techniques, stock prediction, Python web example, Yahoo stock price prediction, Alpaca trading API, TensorFlow, real-time stock data, deep reinforcement learning, stable-baselines library, proximal policy optimization, proximal policy algorithm, Markov decision process, backtest, sharp ratio, live trading.

    FAQ

    Q: How much money did Siraj give to the trading bot for trading?

    • Siraj provided $ 2,000 to the trading bot for trading.

    Q: What libraries did ChatGPT suggest for stock prediction?

    • ChatGPT recommended using scikit-learn and Keras for neural network-based stock prediction.

    Q: Which API did ChatGPT recommend for accessing real-time stock data?

    • ChatGPT suggested using the Alpaca trading API to fetch real-time stock data.

    Q: Did Siraj encounter any issues during code execution?

    • Yes, Siraj faced a missing dependency issue for TensorFlow but resolved it by following ChatGPT's suggestion.

    Q: What advanced technique did ChatGPT recommend for the trading bot?

    • ChatGPT suggested using deep reinforcement learning (DRL) for building a robust trading bot.

    Q: Which library did Siraj choose for implementing DRL-based trading?

    • Siraj opted to use the "finrl" library from the AI for Finance Foundation, which showcases DRL on real-time stock data.

    Q: How did Siraj integrate the trading bot with the Alpaca API?

    • Siraj used the provided code to execute trades programmatically using the Alpaca API.

    Q: How much profit did the trading bot make after 24 hours of running?

    • The trading bot made a total profit of $ 1.62 after four trades within 24 hours.

    One more thing

    In addition to the incredible tools mentioned above, for those looking to elevate their video creation process even further, Topview.ai stands out as a revolutionary online AI video editor.

    TopView.ai provides two powerful tools to help you make ads video in one click.

    Materials to Video: you can upload your raw footage or pictures, TopView.ai will edit video based on media you uploaded for you.

    Link to Video: you can paste an E-Commerce product link, TopView.ai will generate a video for you.

    You may also like