I built three trading bots to trade stock
with $10,000 of my own money. One safe, one risky,
and one just absolutely insane. In today's video, I'm going to show you
the process of how I build these bots. All the technology I used
and the results of giving it $10,000. Well,
if you're new here, my name is Lewis, and I'm on a mission to inspire developers
and tech enthusiasts. Let's go. Oh, okay. So I would never consider myself
a finance guy, but, I mean, come on, How hard can it be? Buy high, sell low. But surprise, surprise,
it's a lot more complicated than that. So I read up on Trading Strategies
in a short period of time. How could I possibly make more money
than I put in? And from my initial research,
no one really knows. So you just kind of make it up on the spot
until you get so rich you can wear a suit to work. But here's
how I'm going to make my fortune. I'm going to create three trading bots
that all have different strategies going from fairly safe all the way
to basically burning my money away. The first one is a mix of momentum
trading and value trading. It makes decisions
on a preset amount of safe stocks and buys or sells, depending on how the stock
is moving on average. The second bot scans
for news articles on a company. If the news is good,
we buy or of a spot and we own that stock, we immediately sell the third buy. I can't even believe I'm doing this. Selects
a random stock out of every stock listed. Grabs the latest news article
about the stock that was picked and uses AI to determine what Taylor Swift
lyric is the most related. If the lyric is happy,
we put half the money in. When we hold that stock, we continue
grabbing news articles about the stock and if the lyrics match
a negative sentiment, we sell everything. Swift Trade 1.0. This is what I do for a living. You're probably wondering
who would be so stupid to do such a thing. While the sponsor of today's video
data stocks is thinking the same thing. I'm using data stocks Astro
DB to power this application, and when it comes to speed,
it's 100% needed When working with databases with vector values
built on top of Cassandra Astra. DB helps you scale your application without the worries of scaling,
slowing you down with global scale, with serverless architecture, enterprise
level security, and no vendor lock in. You can literally create a database and just a couple of clicks
and it has a bunch of SDK supported for Python Node Go or even just a C ally. So if you're familiar with Cassandra,
then no explanation needed. But if you're like me and don't understand
Cassandra, it's still so simple to connect your application
and get something up and running. In minutes. I create a Chrome extension
that lets you talk to YouTube videos easily with data stacks
primarily powering the entire thing. And it was so easy to just
build an application quickly that require complex components
like a vector database. It's also easy to include
in your existing projects. Create a Cassandra vector search for a small business in your area
and have a for facing chat. It's actually shockingly simple. Leaders in every industry are using data
stacks with Astra DB to power their A.I. applications, and you can too
with their extremely generous free tier. Thanks data stacks for enabling my reckless behavior
by being the sponsor of today's video. If you're building an AI app
or want to build an AI app, please click the link in the description below to learn more about how you can use
data stacks in your next project. So here's how the first trading bot works
in detail. Every minute the bot looks at a predefined set of safe
stocks, then looks at the current price. The average price
within the last 15 minutes and the p e ratio, which is the companies
earnings to stock price ratio. If a stock is above the average price and
the p e ratio is lower than the average, we buy, we then check to see
if the moving average is on the way down. If it is, we sell
and then rinse and repeat. I'm of course
using Python for all three of these bots and unfortunately
I'm using interactive brokers, which is the only option I have
as a Canadian. Like really? Also,
the interactive brokers API is really bad, but thanks to the magic of open source, someone made a package
that makes it a little bit more bearable. What's funny
is that the least exciting bot to make is actually the hardest to make. There's a lot of technical
mathematical finance jargon that I just don't really care about, so
I have to look it up, how to implement it. You know, so when you're building one of these bots, the first thing that you do
is you back test. Backtesting
is where you take your strategy and see how it performs
on historical data. In Python,
there's a framework I'm using called Back Trader that lets me implement my strategy
and then use it against historical data. And since this is only going to be less
than a week, I'm going to only get the last couple of months of data
from a set of stocks that I spent so long on this at. Seriously ridiculous. So let's test it. Okay. Looks like we need some improvements. Sometimes it's
just the numbers that need altered. So a lot of these backtesting libraries
let you optimize these numbers by running them all in different combinations
and then picking out the best. So let's optimize 25 different periods. 30 different overbought thresholds
and three different oversold thresholds. That means that we're testing over 22,500
different combinations. Let's get started. So for reference, I have 24 different cores on my computer and use them all in parallel
to get this running as fast as possible. It was seriously so long and it took over
25 minutes to run with all of these. So insane. And the worst part is that the best return I got was like $23,
but that's $23 doing nothing. So I'll do it with these parameters right
here. Usually with save or stocks,
you plan on selling in like a year or ten years
by instead I'm doing in a week. So honestly, $23 honestly might be a win. Let's just convert it into the interactive
brokers code and then run it. The second bar scans for news articles on companies
and the news is good. We look up the company
that it may be related to and then we buy. If it's bad and we own that stock,
we immediately sell. And this is how we can test. How does the news affect the stock market? Something I wasn't expecting was
how closed all information is basically everywhere
after the whole Twitter and Reddit API situation
everywhere is doing it now, so it looks like I'm forking up
some more cash. First, I downloaded the list of stocks on NASDAQ and New York Stock Exchange. I used to open again
to generate a description for each stock. Then embed this description
so I can vector, search it later, upload to Astra and we're good to go easy. All right, let's test it out. Who is ten? Awesome. So it seems to be working. Coding with Lewis builds
awesome trading boss with AI. Okay, cool. Then I plugged in and use API
so I can scan for news and identify what stock is likely going to
be talked about or affected. Now the back trading strategy, this one is going to be
a little bit more tough considering there's a whole bunch of data
outside of just the stock itself. Also,
I don't want to use any more API credits. It was already expensive as it is,
and I'm pretty much running out. So I'll write a script
to give me the date. Headline sentiment
and stock ticker is affiliated with. I just got the NVIDIA 49 and it's really coming in clutch right now
with a machine learning aspect of it. And just because I'm curious, I'm
speaking to the final results here, 655 positive articles,
300 neutrals and 550 negatives. Wow. Bummer. All right. This testing shouldn't be too hard. So it was pretty hard. So I have this set up here
where I can just put in a stock ticker and I'll use a sentiment analysis
based off of what I've done. I'll just do s box like Starbucks. It's actually funny
because Starbucks did really well lately, so it was climbed up
after a massive thing. Which insane? $102. So imagine if five days later I sold it. Let's try Tesla. I'd be a crazy one here. Okay. Even there you make money and do. Oh, wow. That's actually a crazy, crazy thing. I mean, to be fair, Elon
is always getting himself into some crap. Absolutely insane. Okay, let's convert this into interactive
broker code, and we're off to the races. Here's what we have to do. We select a random stock at every stock
listed using the same news API. Like last time we grab the five
most recent articles. We embed the articles and have data stocks
match out with the Taylor Swift lyric that relates to it the most. We then determine
if this lyric is positive or negative. If it's positive, we buy as much stock
as we can, otherwise it's time to sell. And I can't even believe
that we're doing this. Buy less, build First Less Locked Down. The Taylor Swift Lyrics. This one was surprisingly hard to find,
but Alisal or a dash of data provided it all on GitHub
and it only has 17 stars. An absolute legend. She literally has no idea
how much she's just helping you right now. Now separate all the lines of each lyric. For further reference for myself,
I'll add what album and song there from now to save herself some time. We can just do the sentiment analysis
on every single lyric now so we can save it
and ask her to be in bed. The lyrics and save to a new column and push up in batches
to ask her to be an actor. A first test. Awesome. Grab her existing list of stocks,
set up a function that pick one out random so I can grab and use data
from and good news pun intended is that we already have
the news API set up so we can just reuse a lot of the functions there. Now let's get some back test started. How I tested
this was similar to the new sentiment, but it's a bit harder
considering us all random sometimes. It did really well, sometimes it didn't. And there's a thousand of stocks
available to choose from. So I'm thinking
I'm satisfied with my testing. Let's just convert to interactive brokers
code and call it a day. So it's the next day. I have all three bots here
all ready to go. Can I press the button? Here we go. Oh, Mid-Wicket. Oh. Oh, oh. So I was only able to run them
for about three or four days because I had so many issues
when I actually deploy that. But more on that later. For now, let's get into the results. So for bot one, only
two stocks were purchased. Duke Energy was bought
the last day of trading, 16 shares at $90.09,
but a total of $1,441.44. We then sold like 2 hours
later for $89.66 at a loss. So with this stock,
we ended up losing $6.88 with Mara. We ended up buying 24 shares at $9.38 totaling to $225.24. We then sold that $10.22, meaning
we made a profit of $20.16 combined both together. And we actually made $13.28. I mean,
I wasn't really going to be surprised that bought number one wasn't going to cause significant loss or gain,
but it was fun to do either way. We bought over nine stocks, GameStop,
we bought 22 shares at $12.76 and then sold at $13.23,
meaning we made a profit of $10.15. The Grinder app. We bought 46 shares at $6.14
and then sold at $6.76, giving us a profit of $28.29. Take-Two Interactive. We bought only one share, $153.94,
and then sold for $154. This was a last minute trade,
so we only made a $0.06 profit. The Insulet Corp, we bought one
share at $170.05 and sold for $174.26, giving us a profit of $4.22
Hudson Pacific Properties. We bought 50 shares for $5.63 and sold $5.73, giving us a $4.80 profit. AT&T, we bought 18 shares at $15.56 and sold for $15.78,
giving us a $3 and 90 $0.01 profit. Astra space. We bought 195
stocks at $1 and four for $0.08 and then selling at $1 and four for $0.02. This means we got a loss at a dollar
and $0.33. Hudson Global
we bought 18 shares at $15.40 and then sold at $15.47,
giving us a $1 and $26 profit. Molson Coors Beer. We bought four stocks at $59.65 and then sold for $59 and 66 one cents,
giving us a four sound profit. And the part that you're probably waiting
for the Taylor Swift bottle here, the results of that. So we actually only ever bought two stocks
during our Taylor Swift bot run. I'm thinking maybe this was because
of the limited data from when the stocks were initially bought,
but the first one was Nuveen Global. Then this article called JT
stayed in the game with Nuveen Global High Income Fund. Somehow related to Stay beautiful,
Stay Beautiful from the song Stay Beautiful from the original Taylor Swift
album came up. Not sure why, but it went with it. So we ended up buying 101 shares at $11.22 and then sold at $11.20,
which means that we lost $2.02. Then it randomly chose at X Corp
that leases railcars to companies. So again, from the album Taylor Swift,
it picked out the lyrics. When you think Tim McGraw from the song
Tim McGraw and then bought ten shares at $108.63 and then eventually sold at $110.87, giving us a profit of $22.45. That's right. We made money off this real money. So after all is said and done, all three
of our boss brought in a combined $109.35. This is from around 3 to 4 days of active trading and between 13 different stocks,
but not all happy. The $109.35 accounts
for commissions and fees included. But I also had to buy
a lot of subscriptions to access real time market data. So interactive brokers
automatically took $117.70 off. So if you actually want to include that in your portfolio,
we actually lost $8.35 by it. I can only get
because you keep tuning in to my YouTube shorts, my long form videos
and all my other socials. Coding with Lewis is my full time job
as well as well as full time job. Who helps out of these videos? And to me, that's just beyond insane.
So thank you. Thank you so much
for supporting me on my journey. We're planning a special event
in our Discord Channel, so make sure you check it out
in the description below to find out more. If you like videos like this
where I actually build things, then check out my Reddit bot
which builds those Reddit TikTok videos that you always see as well as my news
API bot that reports the news to you.