Austin | Oct 15, 2022

Algorithms built with Python for live stock trading. Uses Alpaca Trade API for live trading and stock information. Incorporates Redis for persisting data and is ran as a Docker image in the Cloud.

How it started

In late 2019 I began getting into the stock market and more specifically options trading. After learning about it and the fascinating complexity that surrounded trading options, I was quickly hooked. I watched many hours of YouTube videos learning everything I could about options trading. Once the Covid-19 pandemic hit in 2019, I was looking for ways to involve my newfound programming skills with my interest in the market. I stumbled across a website for creating algorithmic trading strategies called Quantopian .


Quantopian allowed me to play around within their website generating algorithms written in Python and backtest them to see how the algorithm would’ve done over any period of time starting from early 2000 to today. There was an active community that would share their successful algorithms and then I would take those and implement tweaks to try to get even more success. Eventually, I decided enough backtesting and deployed some of my algorithms on Alpaca .

Sadly, Quantopian shut down the free community offering in November 2020. You can read more about that on the wiki.


Alpaca made it very easy with their documentation and their own programming libraries for different languages. With their Python library it was easy to move my code from Quantopian over to use with Alpaca and their API. There were 4 or 5 different algorithms that I moved from Quantopian and wanted to start doing live paper trading on Alpaca with.

Live Trading

After a few months of paper trading I decided that one of the algorithms was fit enough for live trading. So, I sent in some money and let it run. The image at the top is from that algorithm while it ran in 2021. Toward the end of 2021 I pulled the money out as I needed it for other things and I had an overall uncertainty about the economy.


From the time I began (07/30/2020) to the time I pulled my money out of the live trading (01/20/2021) the S&P 500 rose 17.5%. The money in my account that was live trading with the algorithm rose 45.2%. The return from my algorithm was more than 2.5X the return of the S&P 500.


I still plan to put money back into the algorithms but have yet to do so considering the volatility and uncertainty in the economy right now. Once things cool off, I have every intention to put money back in to see what the algorithm can do. It also seems Alpaca has improved their API and brokerage as a whole since I built the algorithm. Alpaca now has offered partial shares, which means don’t have to purchase an entire share of a company and instead can just put in the amount of money that you want to. I believe this will help the algorithm tremendously considering the ability to equally distribute the money with no constraints with the costs per share of certain equities.

comments powered by Disqus