Hey guys,
it's Angela here and welcome to Day 36 of 100 Days of Code. Today
we've got a fun project for you.
We're going to be building a stock news monitoring project.
So I don't know how many of you guys trade stocks out there,
but I've recently started learning about it.
And one of the pictures that always come to my mind when I think of people
trading stocks is something like this,
where if you will sit in front of a million screens,
looking at all of the data and all of the news.
Now I did a bit of research into this
and it seems like a lot of the people who trade stocks professionally have
access to what's that a Bloomberg terminal, which looks something like this.
And it provides you with a number of things,
the current stock prices of whichever companies you're looking at,
and also the breaking news that's relevant to those companies. So
depending on whether if they had some good news
say they earned a lot of money in the last quarter, or
they built a really great product or they developed a new vaccine.
Then obviously you can imagine the price of their company's stock go up or down
depending on the type of news that comes out. And finally these platforms
also give you the ability to alert you when relevant pieces of news happen that are
related to stocks that you're following.
So I found out for my friend that to subscribe to one of these Bloomberg
terminals,
it costs something like $24,000 a year.
So that was the end of that research. Um,
but I thought about it and I thought about the kind of things that would be
really useful to somebody who trades stocks.
And I thought about how we could turn this into a Python project.
So here's what's going to happen.
We're going to DIY our own a Bloomberg terminal or at least the parts of the
functionality that are quite useful. First,
let's take a look at what stock market data looks like. So here,
I've got a website up called tradingview.com and I'm looking at the large cap
companies.
So these are well known companies that you've probably heard of like Apple or
Microsoft or Amazon.
And let's say that we had an interest in a particular stock.
Let's say that we bought shares in Tesla,
and we want to know how it's doing. Well,
we could take a closer look at it and we could take a look at
the full featured chart.
And this shows us the price of the Tesla stock over the past few days.
Now I'm going to change the time zone here to the actual time zone of the
exchange. And if I change the view to one day view,
then you can see the points at which the market is open and when it's closed.
So these blue sections highlight when the market is closed.
Currently it's the 22nd of July. So because this day's
data is not yet complete, we're going to look at the previous day's data.
So this is yesterday.
And you can see that NASDAQ opens at 9:30 AM New York time
and it closes down at 4:00 PM on the same day.
And often when you're getting data on stocks,
you can get the price of a particular stock at the point when the market opens
and when the market closes. For example,
we could compare the price of the Tesla stock at market close yesterday.
So that was about $1,567 and at market close the previous day
so that's four o'clock on the 20th of July,
and that was at around $1,641.
So there was a big difference between the end of the 20th of July and the end of
the 21st of July. As a stock trader would be quite
interested in these big fluctuations because it might mean that we would want to
buy more, or we might want to sell our stocks in Tesla.
When you look at a lot of these services
be it Bloomberg terminals or something much simpler like this,
they often give you a whole bunch of other data as well.
One of the most useful things is actually to look at the news that's related to
the company that you're investigating. So for example,
these are the current headlines for Tesla,
and it comes from various news sources like Reuters or my Wall Street or
Bloomberg. And it gives us some information to start analyzing.
For example, well why was there this big drop, what's the reason,
and there's various news sources that might tell us why. For example,
maybe they're experiencing problems with servicing staff,
or maybe as this news piece suggests, the stock is probably going to rise again.
So these are really interesting things
if we were to trade this particular stock.
If we were to create a Python program that's going to help us trade stocks,
then this is how it might work. First,
we're going to pull in the stock prices of the stocks that we're interested in.
So we would be using an API to get this data.
And let's say that we were monitoring the Tesla stock cause we bought some
shares and we want to know how it's doing. Well,
it might pull in the data for the price of Tesla stock that was at market close.
Let's say that today was March the 11th.
So we're pulling in yesterday's closing price and let's just say, for example,
it is $1,000.
Now the next thing our program is going to do is it's going to pull in the
closing price on the previous day.
And we're going to compare these two values. So over the course of one day,
what was the difference. And in this case,
there's a difference of a hundred dollars and the direction is up.
So it increased in value, right? Going from March 9th to March 10th.
So that's good news for us if we bought in. Now,
we can also calculate what is the percentage that this rise represents.
So if we look at this difference of a hundred dollars and calculate it as a
percentage of yesterday's closing price,
then we can see that the price on March 9th was 10% lower than on March 10th.
So let's say that in our Python program,
we set the program to run and fetch us some news
whenever we get a slightly extraordinary rise or an extraordinary fall.
So you can define that as anything you want, but let's say it's 10%.
If there was a difference of 10% or more between yesterday's closing price and
the previous day, then we want to know about it.
So we're going to get our API to fetch us some relevant news.
That way we can figure out what is the reason for this rise or what is the
reason for this fall.
And it might just turn out well because Tesla launched a new product,
or because they've acquired a new factory.
Some sort of indicator that says, well,
this company is going to do a lot better. Now,
once the stock prices have triggered this alert and we fetched the news data,
then we're going to send ourselves an SMS.
So we're going to send ourselves a message telling us what was the big
fluctuation that happened and what is the relevant news so that we can decide
there and then whether if you want to sell our stock,
or if we want to buy more.
We're aiming for messages from Twilio that look a bit like this.
That way
when you wake up in the morning and you're wondering what's happening with my
Tesla stock and it just so happens that over the last two days,
it experienced huge fluctuations,
then you would get sent the relevant pieces of news to help you decide and help
you figure out what you should do with your trades. That's the goal.
And the best part of this project is the fact that it's going to be mostly up to
you as to how you create it
In the course resources I've got links
to starting projects with the comment and hints,
and depending on which level of difficulty you want to choose, normal,
hard or extra hard, you can pick the starting project that's right for you.
Once you pick the starting project,
then you are going to work through each of the comments
and you're going to try and complete the functionality of this program.
Now I want you to spend at least a half an hour to 45 minutes working on this
project, just because it has quite a few APIs that you need to tap into.
And most importantly,
I want you to read through the API documentation yourself so that you can
understand how to work with it and how to figure out things on your own.
Because after all, there are millions of APIs out there
and if you're going to need it for a special project of your own,
you're going to need to go through this process that all developers go through
which is digging through documentation and understanding how to work with an
external piece of software
or code.
That's the challenge I've set for you. Head over to the course resources now and
get the starting code so that you can get started working on the project.
Good luck.