Skip to content

S$30K funded project to develop an automated options trading program for two semi-retired engineers-turned-traders. The proprietary strategy generates an estimated 20% annually on a 7 figure portfolio.

Notifications You must be signed in to change notification settings

belligerentbeagle/QuietQuant-public

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 

Repository files navigation

QuietQuant

wakatime

A S$30K funded project to develop an automated options trading program for two semi-retired engineers-turned-traders. The proprietary strategy generates an estimated 20% annually on a 7 figure portfolio.

QuietQuant

Get started

  1. Clone the repo
  2. Install the requirements with pip install -r requirements.txt
  3. Run pip install ibapi to install the Interactive Brokers API
  4. Run the streamlit app with streamlit run main.py
  5. Enjoy!

Topics touched on in this project:

Software Development

Tech Stack

  1. Cloud Deployment
  2. Shell Scripting
  3. Python
  4. Pandas for technical indicators
  5. Streamlit
  6. Selenium
  7. IBKR API
  8. FinanceToolkit
  9. Yahoo Finance API
  10. AlphaVantage API
  11. RapidAPI
  12. NewsAPI

Data Structures and Algorithms

  1. OOP
  2. State Management
  3. Web scraping
  4. User Authentication
  5. IBKR API usage (trade execution)
  6. Automated trading
  7. Stock valuation, screening
  8. Stock market analysis

Math/Finance

  1. Options trading
  2. Financial data analysis
  3. Intrinsic value calculation
  4. Discount rate calculation
  5. Options trading strategies
  6. Portfolio Optimization e.g. Efficient Frontier, Kelly Criterion
  7. Black-Scholes model

Architecture

Phase 1: Gathering data, calculate intrinsic value of assets

Architecture

Phase 2: Gather top stock tickers from proprietary website ranked based on ROI of options.

ArchitectureP2

Phase 3: Execute trades through IBKR that meet criteria for proprietary columns

ArchitectureP2

Phase 4: Use ML (NLP) to estimate 3-tier growth rates for companies

For this project, my original plan was to use FinBERT, a pre-trained NLP model to analyze sentiment of financial text. It is built by further training the BERT language model in the finance domain, using a large financial corpus and thereby fine-tuning it for financial sentiment classification.

I then switched to using GPT-4 with strict format restrictions for growth rate estimation with news articles.

Phase 5: Kelly Criterion for portfolio optimization

KellyCalculator

Phase 6: Options Contracts Scanner Engine (OCSE)

OCSE1 OCSE2

Additional Features:

While some companies can have a good intrinsic value, their operational cashflow might tell a deeper story. This is a red flag for the company's future prospects, and hence, a penalty is applied to the stock's score, if such patterns are recognized! (Was interesting codifying these patterns) BadQuarterlyCashflow

Data APIs

NewsAPI.org use:

Limit 1000 requests per day

FinanceToolkit (opensource)

(Starter Plan @ $305SGD/yr) Limit 300 requests per minute and uses FinancialModelingPrep under the hood (only US stocks)

No longer using:

Tiingo

Limit 1000 requests per day, max 50 per hour

AlphaVantage API use:

Limit 25 requests per day

Regularly used terminologies

| Term | Description | | DTE | Days to Expiry |

Improvements and Optimizations:

  • Handled missing financial data case
  • Fail safe: Fetch financial data from 2 sources - Tiingo and Yahoo Finance to compare 3FS discrepency. (5% tolerance)
  • Automate finding of discount rate as well.
  • Add current stock price comparison
  • Error handling -> if data not available. Write error message as well.
  • State Management, saving time from making API calls repeatedly. ~60% speedup on load times.
  • Scrape Options data from online source
  • Add and apply Technical Analysis module
  • Implement Kelly-Criterion for portfolio optimization
  • User authentication
  • AI sentiment analysis for growth rate estimation
  • Pull Options Chain from IBKR API
  • Score system for top options to trade
  • Efficient finding of household name stocks against list of undervalued stocks.
  • Sort, Rank and calculate Kelly and no. of contracts to trade on Options Chain from IBKR API
  • Execute trades through IBKR API
  • How often does the intrinsic value change? How often should we re-calculate it? -> Can store the intrinsic value in a database and update it every 3 months.
  • Concurrent fetching of data
  • Average growth rates for 3-tier growth rate estimation
  • Google Authenticaiton
  • Bot checks all possible before deciding which ones to go for based on available portfolio. and best options ranked out of all those, considering buying power use.
  • Bot make sure its not bank
  • Shift forexrate API

Requested features (Active Log to be changed and cleared)

  • Use yahoofinance for additional FS data to obtain an average, more accurate intrinsic value.
  • Cashflow to use TTM
  • Add 1 point for household name
  • View stock's sector
  • Improve trade selection on options contract scanner engine (OCSE)
  • Improve SMA criterias to be 50, 150, 200
  • Use yfinance's cache function to speed up data fetching
  • More accurate growth rate prediction: If bad quarterly OCF recently, then 0.0 ST, MT growth. Else we calculate average annual growth rate of past 3 years, if no past 3 years, then 1% growth rate. Long term by default is 3% (GDP).
  • do sth related to getting more stocks?
  • Leave sources unfilitered for shorting as well?
  • Avoiding shorting stocks w shortterm uptrend breakout. -> Mean that there're believers wthat stock will turn around soon.

Change log:

13 Aug:

  1. Improve trade selection on options contract scanner engine (OCSE)

9 Aug:

  1. Added check for adverse operational cashflow patterns

8 Aug:

  1. Codifying Bad quarterly operational cashflow where it penalizes the score of a stock.

7 Aug:

  1. Minor bug fixes where price data was returning None when yahoo data fails to download

4 Aug:

  1. Added Stock undervalued calculation, supporting a new neutral-bearish strategy.
  2. Stocks sorted by Score

3 Aug:

  1. Add trade selection option

Late Jul - Aug:

  1. Building Options Scanning Engine -> Pulling Options Chain from IBKR API
  2. Filter and sort tradeable options
  3. Calculate cashoutlay, kelly %, ROI for tradeable options

17 Jul:

  1. Added company sector to the table of results.
  2. Added business summary for each company.
  3. Bug fix for Yahoo Finance reporting in different currency.

13 Jul:

  1. Improved data pulling and calculation clarity with secondary data source.
  2. Added Go to Stock's Yahoo Finance page link.

12 Jul:

  1. Usage of TTM Operational Cashflow instead of the last year's data for Intrinsic Value calculation.
  2. Draws financial data from yahoo finance as a comparison to FinancialModelingPrep.

7 Jul:

  1. Enable single ticker lookup with FinancialModellingPrep. Was previously using AlphaVantage.
  2. Option to disable technical analysis checks.
  3. Range selection of top X to top Y stocks.

5 Jul:

  1. Implemented Back up discount rate provider should financetoolkit fail.

3 Jul:

  1. Fixed bugs in individual intrinsic value calculation
  2. Used paid API key!
  3. Default Kelly's loss amount to 2.5%.

30 Jun:

  1. Ensure varying currencies used in FS reporting is accounted for in calculating Intrinsic Value.

23 Jun:

  1. State Management, saving time from making API calls repeatedly. ~60% speedup on load times.
  2. Implemented Kelly Criterion for user.
  3. General UI improvements, making sliders into number inputs instead.

18 Jun:

  1. Improve Kelly Criterion calculation by agreeing on a standard way to decide how to determine "loss" amount.
  2. Add points system to list of top stocks to trade
  3. Pull options chain from IBKR
  4. Move to Fly.io

14 Jun:

  1. Implemented latest news API for growth rate estimation for individual stock analysis.
  2. Used gpt-4o with strict format restrictions for growth rate estimation with news articles.
  3. Integrate TWs
  4. Calculate Kelly Criterion

10 Jun:

  1. Improved sortable tables and information organisation (UI updates)

6 Jun:

  1. User Authentication
  2. Bug fixes

4 Jun:

  1. Proper API Key handling using .env file
  2. Filter for only undervalued stocks
  3. Changed URL to pull best ROI per day instead.
  4. Added Technical Analysis module for the 3 checks
  5. Added the 3 check results to table of results
  6. Display price, SMAs and stochastic oscillator values in the table

29 May:

  1. Webscrape with selenium from a website for highest ROI options.
  2. Run intrinsic value calculation on this basket of stocks
  3. Error handling of missing values from financial reports

23 May:

  1. Added auto pulling of discount rate.

22 May:

  1. Fixed to Annual report data for Cashflow
  2. Changed API provider with a higher API limit (AlphaVantage to Tiingo, from 25 req/day to 1000 req/day free)
  3. Changed away from Tiingo after realising that their fundamental data is free only for DOW30 stocks. Trying Yahoo finance via Rapid API
  4. Changed to FinanceToolkit: an open source toolkit gathering financial data with transparent methods of calculations.
  5. Use YahooFinance API through RapidAPI to get current stock price

Archive

Public Financial data sources

  1. financialmodelingprep.com
  2. https://github.com/JerBouma/FinanceToolkit
  3. https://www.alphavantage.co/documentation/
  4. https://www.tiingo.com/documentation/fundamentals
  5. https://rapidapi.com/apidojo/api/yahoo-finance1

Dev Notes

Creating requirements.txt with pipreqs:

$pipreqs . --encoding=iso-8859-1 --ignore optionstrader/ --force

After deploying to Fly, to install chrome driver to support selenium

fly ssh console -s -a app-name apt-get update apt-get install -y wget gnupg wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | apt-key add - sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list' apt-get update apt-get install -y google-chrome-stable

Killing python process blocking new IBKR client connection:

ps -ef|grep python kill -9

About

S$30K funded project to develop an automated options trading program for two semi-retired engineers-turned-traders. The proprietary strategy generates an estimated 20% annually on a 7 figure portfolio.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published