Collection of scripts and utilities for stock market analysis, strategies etc
short-straddle-1-max-position-close-at-expiry short-straddle-5-max-position-30-profit-100-loss-close-at-expiry
$ make setup
$ make deps
All available scripts should provide a basic description and options to run appropriately
For eg.
$ ./venv/bin/python3 download_stocklist.py --help
I suggest setting up a quick alias to run the python version in the virtual environment. This will save you remembering
to activate the virtual environment. There are other options where you can override the cd
command, but I find this
simple and transparent.
alias py=./venv/bin/python3
Now you can run the same script as
$ py download_stocklist.py --help
As I usually run it over weekend, I've added a make command weekend
to download the latest stocks and data and run
analysis on it. You can run it as
$ make weekend
Once the analysis is complete, it'll open up DTale in your default browser.
Although it is possible to run queries in DTale, there is a way to generate report for a selected query. The generated report contains the chart along with useful links to third party websites for more information.
You do need to setup Pandoc to generate HTML reports. If you are unable to install
Pandoc, then run report_by_query.py
without -v
argument to generate report in Markdown
format.
Sample report for finding mean-reversion setups
$ py report_by_query.py -o monthly_gains_3 -c 20 -t "Short Term Mean Reversion" -q "(last_close < 100) and (last_close > ma_50) and (monthly_gains_3 > 0) and (rsi_2 < 10)"
Make sure you run make weekend
to download all pre-requisite data.
Generate Multiple Moving Average charts for different sectors
$ py report_sectors_mma.py
# Find Leaders/Laggards in the whole market against SPY
$ py report_relative_strength.py -b SPY
# Find Leaders/Laggards in the whole market against QQQ
$ py report_relative_strength.py -b QQQ
# Find Leaders/Laggards but only in large-cap (S&P 500)
# Requires downloading the list from BarChart https://www.barchart.com/stocks/indices/sp/sp500
# Save the csv file as 'large-cap.csv' in 'data' folder
$ py report_relative_strength.py -m large-cap -b SPY
Make sure you have the following variables set in environment.
export CHAT_ID = "<telegram-chat-where-the-messages-will-be-pushed>"
export BOT_TOKEN = "<telegram-bot-token>"
Read links from webpages.txt
and send over Telegram on a defined schedule.
See run()
in tele_links for changing schedule.
I use it to send me links like https://swingtradebot.com/equities/general-market-analysis
before market open.
py tele_links
Send quick analysis on SPY during market hours.
See outside_trading_hours()
in trading_hours for changing schedule.
py tele_spy_trade_bot.py
Requires setting up following environment variables.
export TWITTER_CONSUMER_KEY=
export TWITTER_CONSUMER_SECRET=
export TWITTER_ACCESS_TOKEN_KEY=
export TWITTER_ACCESS_TOKEN_SECRET=
Forward tweets from your followers to a telegram channel.
py tele_twitter.py
Get tweets from your favourite twitter furus in your own telegram channel 🚀. The notification includes the original tweet along with a chart 📈 and links to several websites 🌎. It also keeps the tweets in a database to hold them accountable 👺.
It requires setting up a file twitter_furus_accounts.txt
with a list of individual twitter handles on each line (See twitter_furus_accounts.txt.example
).
py twitter_furus.py
Make sure you define a few variables before starting up these bots
export EXCHANGE_API_KEY =
export EXCHANGE_API_SECRET =
export EXCHANGE = ""
See crypto_ma_trade_bot.py for an example.
Uses Tradier for fetching data.
Make sure you signup and have the following variables set in environment.
See .env.example
for more details.
export TRADIER_TOKEN=
Track prices for given underlyings every hour in the market session.
See inside_trading_hours()
in trading_hours for when it runs.
The data is stored in a sqlite database file sqlite:///{home_dir}/options_tracker.db
.
py options_price_tracker.py -t SPX,XHB,XLC,XLY,XLP,XLE,XLF,XLV,XLI,XLB,XLR,XLK,XME,XOP,GDX,IYR,XLU
Two tables are created for each symbol.
{ticker-name}_options
table contains options data.
{ticker-name}_stocks
table contains corresponding data for underlying along with the technical analysis.
I usually run this on a server so there is a task in the Makefile to copy the data from remote server to local home folder.
make syncoptionspricedata