Algorithm – Financial Trading FAQ

I get a lot of questions about Financial Trading algos, building black boxes, which is the best trading API, the list goes on. Not to sound to pretentious, but I try to help people, even when I possible, but I don’t always have time. So I’m just post some of the questions here in random order.

what is the preferred language for algorithmic trading? I wanted to use Java but I am not sure if that is the best language.

I used to use PHP. Now I use Python. I think Python is a good reasonable solution. If you are on Wall Street doing High Frequency trading you would probably use C# or C++ as it is supposedly the fastest.


Also, have you heard of finnhub.io and alpaca? If yes, which one in your opinion has a better API? I trade Futures, stocks and options. I don’t think either of those can do what I need.


Do you build trading algorithms for futures, stocks, options?

Based on my blog post I think the answer would be yes.

Hey, I read your blog on which api is the best and I have been doing research on TD Ameritrade for 2 days now and I have not made much progress. I am new to this and also was wondering If Interactive brokers is free to use for stocks and options?

You can start paper trading, this would allow you access to API paper trading account without putting money into the account. I think you have to $2000k to get really started. From my recollection, (but not perfect) but you can open an account, with no money and use the API and paper trading account. When you are ready to get started, I think 2000k is the min and they charge $10 service fee every month.

I would not recommend TD ameritrade and I think you have validated with your research. IB is for the most part free, well documented, python SDK and plenty of support groups. (Stocks, Options, Futures)

I need to up date this but here is starting point… https://github.com/chadhumphrey/stock_options_api

Hi I read a comment in which you mentioned that you wrote your own python code for options trading. That is currently my goal. I am very new to programming and am seeking some help in setting up my own backtesting environment. Would you mind helping me a little? I have access to historical stock data for as well as historical options data. All my options strategies are based on the underlying price and time. My stock data for one symbol is in one CSV file, while I have hundreds of CSV file each for a different option strike with different strike prices. How can I translate my simple option strategies into a python backtesting environment? For example, once XXXX reaches $XXX, buy a call that is +XX dollars ITM that expires in XX days?
I’ve been fairly successful in stock,options and futures trading and have done manual backtests looking at historical charts and such but python backtesting will bring me to a whole new level at a much faster rate.
Any tips or suggestions will be really appreciated.

I have written 3 algos (options, stocks, futures) For stock and futures I do use backtesting data. As for options I’m far to lazy and cheap to find option historical data. So I have developed my own strategy and write my code. Then I just paper test it on Interactive Brokers. Basically, forward testings and since my options algo can find trades in thousands of stocks I feel like I’m getting some good data to analyze. http://thebennyshow.us-east-1.elasticbeanstalk.com/spreads It’s still a work in progress, but this algo ran while I was at my day job. I would argue that with options you can save a lot of time just forward testing. Hope that helps…
not sure if you saw this as well… https://www.strategic-options.com/insight/2020/05/17/update-2020-the-best-and-worst-stock-futures-and-option-trading-apis/
Sorry I can’t write your algorithm for you, but will happy to do so if you want to pay me. 🙂

Many years ago I could have gone the NinjaTrader route, but I was to cheap. So I learned to code. Now I don’t have any problems that I can’t fix. 😉

Hello,
Interested in developing algorithms that will ingest data/analyze and make trades with options. Are these services something you provide?
Regards…….

So you want to build a financial trading algorithm?

It all starts with an idea… or a little bit of anger. 

Chances are pretty good your algorithm strategy wasn’t developed because your bank account is filled with fiat currency or because you really like your day job. Just like blogging, all you need is an internet connection and resentment. 

Usually the strategy or algorithm comes from losing a lot of money when making trades from your gut feeling or listening to the advice of a taxi driver. Hopefully this isn’t the case, but possibly you were taking trade ideas from Wall Street Bets or it could come from everybody’s favorite Wall Street clown. More often than not great algorithmic trade strategies don’t just happen because you were clicking around on charts and nothing better to do.  

Recently, I was approached by someone to program their algorithm. The idea seemed a little half baked, but possibly could work. Since I have experience in this area and know some of the in and outs of this type of work, I usually put together a brief scope of work. In the end I didn’t get the job but my scope of work turned out to be a pretty good blog post on the basis of build a algorithm. I didn’t get the job because I was probably too expensive and I ask lot of questions, well cause I like to think things thru. 

Phase 1: “Let’s see what sticks”

Build a “Scrubber” that would take stocks/options and process them thru your algorithm. The result would be placed in a database / excel sheet for your further analysis. 

The goal would be to use significant amounts of stocks/options and data attempting to confirm your algorithm thesis and find any significant trends and capitalize on them. The more stock/options that you can run thru the “scrubber” the stronger your algorithm will be. My current  stock algorithm runs over 500 stocks. 

What I need to get the project started: Bullet point description of the algorithm. Need a control method, to ensure the algorithm identifies the correct trades. 

Cost: MP

Phase 2: “What worked, what didn’t and what worked surprisingly well”

Continued development of the algorithm, making changes to the algorithm based on the findings from the data. Such as adding a volatility filter? As this case with most algorithms, and which I believe is the exciting part is discovery. Analysing the data and finding new ways to increase profitability. These would be small changes in the code to “tweak” the algorithm.  

Cost: ~hourly basis

Phase 3: “4 weeks of NFL preseason”

I don’t believe in NFL preseason games! Okay, maybe not 4 weeks. But it’s important to set up a paper trading account at Interactive broker. Make sure that slippage isn’t an issue and there are no other execution issues. Do market orders work better than limit orders? Do you have restrictions on your account (margin limits)  Are orders backing up in the queue? Slippage? Account limitations… meaning you might not have enough money in the account to make 10 trades, but can make 9 trades?

User requirements: server (AWS or computer connected to the internet)

Cost: MP

Phase 4: “Make it Rain”

Live trading and making $$. Set up, training and maintenance. Paper trading will be the major hurdle, but there might be a few unknown items moving into the final phase. From my experience, the difference of paper trading to live trading is pretty much a flick of the switch. 

Cost: MP


The unknown: Human emotion is the biggest hurdle that I have run across. Currently, my algorithm runs 24 hours a day 5.5 days a week. I only know it is working when I check in on my account or I get the IB reset alert on slack. Otherwise, the algo is just turn out trades, regardless of what the president tweets or what wars or civil war we are currently in. It takes a little bit of time to accept the algo is working and all your hard work is doing what it’s supposed to be and you can kick back a relax.  

Most people generally accept that when flying and at a cruising altitude, the pilot has the plane on auto pilot and he is just monitoring controls, not flying the plane. We have a certain faith that the pilot and the autopilot feature are doing what they need to do. The same goes with a financial algorithm, you have to trust that it’s working and that isn’t an easy thing to do at first when money is on the line. 
So that is the basic layout of putting an algorithm together, I’m sure I missed a few things and maybe over exaggerated others. Just because one has made a few successful trades on Robinhood, doesn’t mean you are ready for an automated trading. So with that it takes a lot of work and if you want to work with me the starting price is at a minimum $7,000. In the event you are still interested, start the conversation off with my payment of 7,000 M&Ms and make sure they are all green!

Recommended Books for building trading algorithms

Notice I didn’t write 10 books you have to read to make millions of dollars in the market. That just seems a little click-bait/Buzz Feedy. Unfortunately, from a data scientist/ SEO perspective that would have been the more profitable. 

As we all suffer through covid-lockdown I just put together a list of books that I have read that I believe have shaped my understanding of markets and have molded my investment philosophy. I think bigger-picture books such a The Big Short and Black Swan are far more important than technical books.

Creating algorithms and or trading strategies is something that I believe starts with the creative process, maybe just staring at charts for hours or losing a lot of money. I’m lucky, I’m a self-taught coder and I can implement my strategies without getting caught up in whether my code is object-oriented and if I have the correct classes etc. I always say that the code is the easy part, it’s finding a good strategy that is hard part.

So these are some books that I have enjoyed and maybe you will too as well. If you have any recommendation, please leave them in the comments as I’m always looking for something to read / listen to. 

Books that shaped my investment philosophy or possible continue to shape my philosophy strategy.

The Creature from Jekyll Island: A Second Look at the Federal Reserve by G. Edward Griffin
The Warren Buffet Way by Robert G. Hagstrom, jr.
How Technical Analysis Works by Bruce m. Kamich
The Black Swan By Nassim Nicholas Taleb
Beating The Street By Peter Lynch
The Big Short by Micheal Lewis
Flash Boys by Micheal Lewis
Confession of an Economic Hit Man by John Perkins
A mathematician plays the stock market by John Allen Paulos

Here are some other books, that I have read that but am not giving an a full endorsement. I especially disliked “Random Walk”, but that seems to be Wall Street favorite.



Malcolm Gladwell and Freaknomics books are good audio books and generally pretty easy to consume quickly:
The Tipping Point by Malcolm Gladwell
Blink by Malcolm Gladwell
Outliers by Malcolm Gladwell
What the Dog Saw: and Other Adventures by Malcolm Gladwell
Boomerang by Micheal Lewis
Freakonomics by Steven D. Leviit and Stephan J Dubner

The Intelligent Investor: The Definitive Book on Value Investing by Benjamin Graham

Academic / Text Books
Option Volatility & pricing by Sheldon Natenberg
The Complete Guide to Option Pricing Formulas By Espen Gaarden Haug (This book is great for the formulas)

High-Frequency Trading by Irene Aldridge (Probably outdated and really that good.)

Music Books