Skip to content

Instantly share code, notes, and snippets.

@affixalex
Created September 22, 2023 04:58
Show Gist options
  • Select an option

  • Save affixalex/92c1c38592b594543de7fa598a8e27b3 to your computer and use it in GitHub Desktop.

Select an option

Save affixalex/92c1c38592b594543de7fa598a8e27b3 to your computer and use it in GitHub Desktop.
This is a strategy intended to be executed at around 8AM ET through the first
hour of trading (10:30AM ET). It's a refinement of my previous approach aimed
at generating automated buy signals at market open. Note that I didn't actually
write the machine learning model for sentiment analysis, it's a black box to me,
but it performed very well on the training dataset. I'm sure there are better
proprietary sentiment models floating around.
1. Find after hours gappers, big movers from previous close to current open
2. Only select gappers priced from $10-20 with a float of 1M+ shares
3. The top 50 gapping symbols form the watch list for this period
4. Use the newsfilter.io streaming API to filter for news on these symbols
5. Scrape source URL (separate async queue) to perform sentiment analysis
6. Average of sentiment over 5+ articles forms strong signal for scalp entry
7. Consider 20% equity stake on stop 5 gappers with 75+% positive sentiment
8. Stop loss and take profit at 2:1 ratio, risking $2500 to make $5000
A single trade entry and exit is a somewhat naive approach, as it doesn't give
any chance to catch heroic runs. Selling 25% of the position at 2:1 target
price is probably preferable here. The Alpaca bracket order API doesn't seem to
facilitate this in one request, so it'd probably require selling the whole
position and buying back with the proceeds. This would get a little complex in
terms of the implementation, probably recursing into the same code path to just
place new bracket orders on the way up with some decay model.
Also, this approach will require running on some cloud provider both to fetch
the articles and perform the sentiment inference. AWS Data Pipeline?
References:
https://newsfilter.io/api-plans
https://developers.newsfilter.io/
https://huggingface.co/mrm8488/distilroberta-finetuned-financial-news-sentiment-analysis/tree/main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment