How I built a Stock Options Scanner in F#

Date: 2024-04-26 | create | tech | projects | options-scanner | fsharp |

A few times a year I look up a stock's options chain and think I've found a gem of a deal. It gets me thinking - what other deals have I been missing? So I go scour some option chains for several hours to come up with a few decent-looking trades but I'm always left wondering whether they were good or not.

This is a waste of time and it never really ends up with an amazing deal even though it's probable there are some good deals out there. So I figured I could save myself time and get a more confident read on deal goodness by simply building an Options Screener myself.

Why buy when you can build, amirite???

So I built myself a rudimentary Options Screener in F# (my favorite programming language) and here I'll share a bit about how I did it.

Want to build fullstack apps with F#? I start all my web projects with CloudSeed - the fullstack F# project boilerplate.

Project Hypothesis

The hypothesis is simple - I spend too much time on Options and get terrible results. If I can at least save myself time and cover more trades then I improve my ROI.

  • Context: Options is a form of gambling. We can potentially win out by making better guesses than others (this is never really true but we do it for science!)
  • Problem: Manually searching for Options takes too much time and gets poor results
  • Solution: Do the scanning automatically to save myself time / cover more ground.

How it works

Full source code is available in the HAMY LABS Example repo available to HAMINIONs members.

Options Scanner is a simple CLI tool that pulls the latest data for stocks I'm interested in, calculates some derivative values, and then filters to the best ones based on some heuristics I provide.

Inputs:

  • Stocks you're interested in
  • Filters for what a "good" trade is

Processing:

  • Pulls latest Options Chain data from market APIs
  • Enriches this data with extra calculations - ReturnOnRisk, AbsoluteReturn, etc
  • Filters the enriched trade data based on "good" trades

Outputs:

  • The "good" trades

How it's built

Some of these links are affiliates.

I built this very simply so I could iterate more on the data / analysis side instead of wasting time with infra / niceties that I may never need.

I chose F# as it's simple, familiar, and has a good scripting / cli story.

APIs for stock data (especially Options Chains) are actually kinda hard to find and most are pretty expensive to work with - at least for side projects (~$30 / month for the low tiers). This makes sense cause most users of these APIs will theoretically be making money off of these but that's not really true for an indie experimenter like me w a bad P+L track record.

I ended up going with MarketData because:

  • It had the Options Chain data I wanted (available for low tier, trial usage)
  • Had an easy way to test (unlimited API hits for AAPL)
  • Had decent docs

I'm not married to them but it served its purpose pretty well. My one gripe is that sometimes the Options Chain data lags by a few days when theoretically it should always be previous market open but doesn't really matter for this experiment.

Next

This was a fun little project but I probably won't build too much more with it. I mostly consider stock options to be glorified gambling and I think my current strategy for wealth building is far easier, more probable, and has greater returns.

Want to get access to the full project source code? Full source code is available in the HAMY LABS Example repo available to HAMINIONs members.

Let me know if there's anything specific you're interested in learning more about around this project. I've got a few deep dives I could do if there's interest.

If you liked this post you might also like:

Want more like this?

The best / easiest way to support my work is by subscribing for future updates and sharing with your network.