LiuAlgoTrader — Part I — Power up!

Who needs a trading platform?

@amor71
5 min readJun 9, 2021
Photo by Hamza Bounaim on Unsplash

I am a retail trader/investor. In other words, I’m an amateur — I am not a “quant,” never worked for a Hedge fund, spent time on the trading floor, or even studied economics. However, I am a trained software developer with a decent background in math and a disruptive approach to post-postmodernism. If you are like-minded, you might want to read the rest of this post, and if you’re a pro, you might be interested to see how we amateurs roll.

This post is a high-level brief explaining the background of my endeavor, trading platform setup, and some basic concepts to get you going.

Part II will include concepts of developing strategies with the framework and provide a line-by-line sample strategy.

Until a year and a half ago, I didn’t trade a single asset on any market, didn’t know the jargon or market dynamics. Today I think of it as a self-employed gig economy. It’s far from easy money; in fact, it’s pretty hard, but it’s up to you—total independence. The markets are fascinating phenomena: purely manufactured chaos (yes, it’s more Fractal than Stochastic), psychology induced yet dominated by machine-based trading.

About two years ago, I ran into an audiobook on day-trading. The first thing that I noticed is the manual approach pattern identification and the complexities of day-trader psychology. I’m old enough to realize this won’t work for me. Shortly after that, I came across Alpaca Markets and a Python example of day-trading based on MACD. They are an excellent company: it’s a start-up company trying to make a name for themselves, rough around the edges, but they have just the poison I needed: APIs for trading, data feeds, account management, and a vibrant community. A big shout-out to the Alpaca team; thank you guys for making this available free of charge and help me take my baby steps into this fascinating world.

I noticed several things:

  1. Back-testing is essential, but it’s not the end-game.
  2. There are no complete out-of-the-box back-testing platforms for day trading. For successful day-trading, the platform has to scan thousands of signals concurrently and act near-real-time. The platform also must provide tools to review, improve and benchmark model performance.
  3. Trading services are dynamic eco-systems with brokers and data providers coming and going and constantly changing APIS. The platform must have an abstraction layer on top data providers and brokers, letting developers focus on strategies rather than infrastructure.
  4. I need an “ML friendly” platform where I can start tinkering with machine learning (I am aware this point is a bit vague but super important, we’ll dwell on it in a later post).

Oh, and I want it to be completely free. Forever.

I decided to take on the challenge and wrote LiuAlgoTrader.

Sample Tear-Sheet w/ Liu

The rest of the post will walk you thru the setup of the framework and some basic concepts. The follow-up post will focus on how to develop and execute strategies using the platform. While I try to make it all sounds nifty swiftly, a word of warning before you go down the rabbit hole: this is not for everyone. LiuAlgoTrader is for developers, by developers. It does not have fancy-schmancy UI, it is not a “no-code” environment, and you need to be a solid Python developer to make the most of it. There is no money for the grab here, and unless you’re truly committed and willing to invests the many hours (heck, months! years!) required to create algo trading strategies that will float, you better look somewhere else.

With that said, let’s fire up the engines!

The platform executes trades on Alpaca: you will need an account (=API keys) to get started. The second step is to figure what kind of data you need for your trades. Currently, the platform supports both Polygon.io and Alpaca native data-APIs. Polygon.io is pricier than Alpaca Data API but has been around longer. A “free” version exists for both, but it’s pretty limited.

LiuAlgoTrader is developed in Python 3.9 and tested on Python 3.8 (though switching to 3.9 is highly recommended).

LiuAlgoTrader requires a database to store trading results and details of the executed strategies for future analysis. The platform uses PostgreSQL. There is no heavy-lifting here : liu, the installation wizard will download a Docker container and pre-populate the database with the required schema and sample data. You do need to make sure you have Docker Engine & Docker Compose installed.

I do my development and testing locally on macOS. My “production” environment is running on the Google Cloud Platform (GCP). It includes a 4-CPU “Virtual Compute Instance” running Debian Linux and a GCP hosted PostgreSQL. The instance is automatically fired up at 9 AM EST on trading days and automatically shut down shortly after the trading day. Logs are always viewable on the GCP logs viewer, as well as the data in the database. The total cost of the environment is ~$120/month.

The platform has several executable components, all written in Python:traderfor executing trades on live or paper-account, backtester replaying trading sessions, or testing strategies on past data and market_miner intended for off-hours calculations for speeding up trading sessions. The platform comes equipped with an installation & configuration wizard called. liu .

LiuAlgoTrader is installed by

pip install liualgotrader

While I do my development on macOS and my production setup is Linux-based, the platform runs just fine on Windows.

Before running the installation Wizard, you need to make sure you correctly set up the environment variables required by Alpaca SDK. You could find further reading on configuration here (Note you need just the first four to start with). Once done, all you have to do is type:

liu quickstart

And follow the instructions of the installation wizard (which would typically mean just pressing the return/enter a key a couple of times and the setup unavailing).

Once installed, the wizard will provide instruction on how to view a pre-recorded day-trading session.

After the framework is fully installed, read the Getting Started page to understand the platform's basic concept.

Part II presents an end-to-end example of creating and running strategies using the Platform. For now, if you run into issues during your installation or setup, feel free to post a question on the LiuAlgoTrader Gitter page or open an issue on GitHub or email me directly.

--

--

@amor71
@amor71

Written by @amor71

Software as a form of Art, Father, Cat Herder & Algo-Trader

Responses (1)