/r/WallStreetBets Programatic Sentiment Trading

Kyle Rose
4 min readNov 5, 2023

--

“Insanity in individuals is something rare — but in groups, parties, nations and epochs, it is the rule.” — Nietzsche

And with that, I give you — /r/wallstreetbets

If you don’t know, which I bet you do—Wall Street Bets is an online community of self-described gamblers that yolo their life savings into stocks and options.

Looking at the growth of the subreddit, I don’t know how much favor a quote from Bill Gates garners nowadays but he once was quoted saying

If you want to be successful in business figure out what train is coming and stand in front of it

Looking at that graph you can certainly infer that they had a lot of power over a couple names in the market.

In this case the train is 10m monthly/daily active users which act on groupthink and are highly motivated.

So how do you get in front of it?

It’s a three step process consisting of infiltrating, classifying, and acting.

Infiltration

There’s an awesome little package called snoowrap — it’s effectively a wrapper around Reddit’s API.

With just some credentials you can get the hottest posts which are the ones that are rising the fastest and extract the internal comments and put them in a database.

npm i snoowrap
// sudo code, view my GitHub for the actual implementation; 
// https://github.com/anonrose

import snoowrap from 'snoowrap';

const r = new snoowrap({...credentials});

const subreddit = r.getSubreddit('wallstreetbets');

const posts = subreddit.hot();

const comments = r.getSubmission('post_id').comments;

// insert into DB..

Classification

Once we have the comments available to us we’ll want to see what these degens are talking about and how they’re feeling. To do so we’ll send the comments over to GCP’s NLP API.

const language = require('@google-cloud/language');
const credentials = require('./creds.json');
(async () => (
const client = new language.LanguageServiceClient({ credentials });

const [{ documentSentiment }] = await client.analyzeSentiment({
document: {
content: 'BB to the MOON',
type: 'PLAIN_TEXT'
}
})

console.table(documentSentiment);
))()

We get two values from this service from each request for scoring comments, a “score” and “magnitude”. The score is if it’s a positive or negative sentiment, and the magnitude is how much of that thing the comment is exerting

Then if you cross-reference that with the Nasdaq’s ftp server that they put out every day you can get a graph that looks like this.

Which shows the positive and negative sentiment across all the tickers that the subreddit is discussing.

Act

There’s a company out there called Alpaca. They allow an API to a self-directed brokerage accounts. Which means you can programatically write code to purchase on your behalf. A friend of mine maintains an open source version wrapper for them.

await alpacaClient.placeOrder({
symbol: 'AMZN',
qty: 1,
...
})

Fin

So at the end we can create this architecture that will run every market day, pull from Reddit’s API run it through GCP’s NLP library to classify it and finally send over to alpaca for orders which i think is kind of cool.

I want to leave you with this.

--

--