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.
- Clone the repo
- Install the requirements with
pip install -r requirements.txt
- Run
pip install ibapi
to install the Interactive Brokers API - Run the streamlit app with
streamlit run main.py
- Enjoy!
- Cloud Deployment
- Shell Scripting
- Python
- Pandas for technical indicators
- Streamlit
- Selenium
- IBKR API
- FinanceToolkit
- Yahoo Finance API
- AlphaVantage API
- RapidAPI
- NewsAPI
- OOP
- State Management
- Web scraping
- User Authentication
- IBKR API usage (trade execution)
- Automated trading
- Stock valuation, screening
- Stock market analysis
- Options trading
- Financial data analysis
- Intrinsic value calculation
- Discount rate calculation
- Options trading strategies
- Portfolio Optimization e.g. Efficient Frontier, Kelly Criterion
- Black-Scholes model
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.
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)
Limit 1000 requests per day
- docs link: https://newsapi.org/docs/get-started
- pricing link: https://newsapi.org/pricing
(Starter Plan @ $305SGD/yr) Limit 300 requests per minute and uses FinancialModelingPrep under the hood (only US stocks)
- provider link: https://financialmodelingprep.com
- docs link: https://www.jeroenbouma.com/projects/financetoolkit/docs
- pypi link: https://pypi.org/project/financetoolkit/
Limit 1000 requests per day, max 50 per hour
Limit 25 requests per day
- docs link: https://www.alphavantage.co/documentation/
| Term | Description | | DTE | Days to Expiry |
- 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
- 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.
13 Aug:
- Improve trade selection on options contract scanner engine (OCSE)
9 Aug:
- Added check for adverse operational cashflow patterns
8 Aug:
- Codifying Bad quarterly operational cashflow where it penalizes the score of a stock.
7 Aug:
- Minor bug fixes where price data was returning None when yahoo data fails to download
4 Aug:
- Added Stock undervalued calculation, supporting a new neutral-bearish strategy.
- Stocks sorted by Score
3 Aug:
- Add trade selection option
Late Jul - Aug:
- Building Options Scanning Engine -> Pulling Options Chain from IBKR API
- Filter and sort tradeable options
- Calculate cashoutlay, kelly %, ROI for tradeable options
17 Jul:
- Added company sector to the table of results.
- Added business summary for each company.
- Bug fix for Yahoo Finance reporting in different currency.
13 Jul:
- Improved data pulling and calculation clarity with secondary data source.
- Added Go to Stock's Yahoo Finance page link.
12 Jul:
- Usage of TTM Operational Cashflow instead of the last year's data for Intrinsic Value calculation.
- Draws financial data from yahoo finance as a comparison to FinancialModelingPrep.
7 Jul:
- Enable single ticker lookup with FinancialModellingPrep. Was previously using AlphaVantage.
- Option to disable technical analysis checks.
- Range selection of top X to top Y stocks.
5 Jul:
- Implemented Back up discount rate provider should financetoolkit fail.
3 Jul:
- Fixed bugs in individual intrinsic value calculation
- Used paid API key!
- Default Kelly's loss amount to 2.5%.
30 Jun:
- Ensure varying currencies used in FS reporting is accounted for in calculating Intrinsic Value.
23 Jun:
- State Management, saving time from making API calls repeatedly. ~60% speedup on load times.
- Implemented Kelly Criterion for user.
- General UI improvements, making sliders into number inputs instead.
18 Jun:
- Improve Kelly Criterion calculation by agreeing on a standard way to decide how to determine "loss" amount.
- Add points system to list of top stocks to trade
- Pull options chain from IBKR
- Move to Fly.io
14 Jun:
- Implemented latest news API for growth rate estimation for individual stock analysis.
- Used gpt-4o with strict format restrictions for growth rate estimation with news articles.
- Integrate TWs
- Calculate Kelly Criterion
10 Jun:
- Improved sortable tables and information organisation (UI updates)
6 Jun:
- User Authentication
- Bug fixes
4 Jun:
- Proper API Key handling using .env file
- Filter for only undervalued stocks
- Changed URL to pull best ROI per day instead.
- Added Technical Analysis module for the 3 checks
- Added the 3 check results to table of results
- Display price, SMAs and stochastic oscillator values in the table
29 May:
- Webscrape with selenium from a website for highest ROI options.
- Run intrinsic value calculation on this basket of stocks
- Error handling of missing values from financial reports
23 May:
- Added auto pulling of discount rate.
22 May:
- Fixed to Annual report data for Cashflow
- Changed API provider with a higher API limit (AlphaVantage to Tiingo, from 25 req/day to 1000 req/day free)
- Changed away from Tiingo after realising that their fundamental data is free only for DOW30 stocks. Trying Yahoo finance via Rapid API
- Changed to FinanceToolkit: an open source toolkit gathering financial data with transparent methods of calculations.
- Use YahooFinance API through RapidAPI to get current stock price
- financialmodelingprep.com
- https://github.com/JerBouma/FinanceToolkit
- https://www.alphavantage.co/documentation/
- https://www.tiingo.com/documentation/fundamentals
- https://rapidapi.com/apidojo/api/yahoo-finance1
$pipreqs . --encoding=iso-8859-1 --ignore optionstrader/ --force
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
ps -ef|grep python kill -9