1
00:00:00,090 --> 00:00:00,720
Hey guys,

2
00:00:00,720 --> 00:00:05,720
it's Angela here and welcome to Day 36 of 100 Days of Code. Today

3
00:00:06,150 --> 00:00:08,370
we've got a fun project for you.

4
00:00:08,550 --> 00:00:12,720
We're going to be building a stock news monitoring project.

5
00:00:13,410 --> 00:00:16,650
So I don't know how many of you guys trade stocks out there,

6
00:00:16,800 --> 00:00:19,110
but I've recently started learning about it.

7
00:00:19,350 --> 00:00:22,590
And one of the pictures that always come to my mind when I think of people

8
00:00:22,590 --> 00:00:25,440
trading stocks is something like this,

9
00:00:25,890 --> 00:00:28,230
where if you will sit in front of a million screens,

10
00:00:28,260 --> 00:00:31,020
looking at all of the data and all of the news.

11
00:00:31,800 --> 00:00:33,990
Now I did a bit of research into this

12
00:00:34,050 --> 00:00:39,050
and it seems like a lot of the people who trade stocks professionally have

13
00:00:39,110 --> 00:00:43,700
access to what's that a Bloomberg terminal, which looks something like this.

14
00:00:43,790 --> 00:00:45,890
And it provides you with a number of things,

15
00:00:46,370 --> 00:00:49,640
the current stock prices of whichever companies you're looking at,

16
00:00:50,150 --> 00:00:55,130
and also the breaking news that's relevant to those companies. So 

17
00:00:55,130 --> 00:00:57,440
depending on whether if they had some good news

18
00:00:57,440 --> 00:01:00,680
say they earned a lot of money in the last quarter, or

19
00:01:00,690 --> 00:01:04,519
they built a really great product or they developed a new vaccine.

20
00:01:04,760 --> 00:01:09,760
Then obviously you can imagine the price of their company's stock go up or down

21
00:01:11,540 --> 00:01:16,540
depending on the type of news that comes out. And finally these platforms

22
00:01:17,450 --> 00:01:22,450
also give you the ability to alert you when relevant pieces of news happen that are

23
00:01:23,930 --> 00:01:26,030
related to stocks that you're following.

24
00:01:27,170 --> 00:01:32,170
So I found out for my friend that to subscribe to one of these Bloomberg

25
00:01:33,290 --> 00:01:34,123
terminals,

26
00:01:34,220 --> 00:01:39,220
it costs something like $24,000 a year.

27
00:01:39,920 --> 00:01:43,160
So that was the end of that research. Um,

28
00:01:43,190 --> 00:01:46,820
but I thought about it and I thought about the kind of things that would be

29
00:01:46,820 --> 00:01:49,400
really useful to somebody who trades stocks.

30
00:01:49,580 --> 00:01:54,260
And I thought about how we could turn this into a Python project.

31
00:01:54,830 --> 00:01:56,360
So here's what's going to happen.

32
00:01:56,600 --> 00:02:01,600
We're going to DIY our own a Bloomberg terminal or at least the parts of the

33
00:02:01,640 --> 00:02:05,240
functionality that are quite useful. First,

34
00:02:05,300 --> 00:02:09,500
let's take a look at what stock market data looks like. So here,

35
00:02:09,500 --> 00:02:14,500
I've got a website up called tradingview.com and I'm looking at the large cap

36
00:02:15,950 --> 00:02:16,783
companies.

37
00:02:17,120 --> 00:02:20,840
So these are well known companies that you've probably heard of like Apple or

38
00:02:20,840 --> 00:02:22,370
Microsoft or Amazon.

39
00:02:22,910 --> 00:02:26,330
And let's say that we had an interest in a particular stock.

40
00:02:26,360 --> 00:02:28,610
Let's say that we bought shares in Tesla,

41
00:02:29,120 --> 00:02:31,340
and we want to know how it's doing. Well,

42
00:02:31,340 --> 00:02:34,130
we could take a closer look at it and we could take a look at

43
00:02:34,400 --> 00:02:35,840
the full featured chart.

44
00:02:36,560 --> 00:02:41,560
And this shows us the price of the Tesla stock over the past few days.

45
00:02:45,410 --> 00:02:49,670
Now I'm going to change the time zone here to the actual time zone of the

46
00:02:49,670 --> 00:02:54,170
exchange. And if I change the view to one day view,

47
00:02:54,470 --> 00:02:58,730
then you can see the points at which the market is open and when it's closed.

48
00:02:59,110 --> 00:03:03,010
So these blue sections highlight when the market is closed.

49
00:03:03,730 --> 00:03:07,540
Currently it's the 22nd of July. So because this day's

50
00:03:07,540 --> 00:03:11,550
data is not yet complete, we're going to look at the previous day's data.

51
00:03:11,580 --> 00:03:12,750
So this is yesterday.

52
00:03:13,320 --> 00:03:18,120
And you can see that NASDAQ opens at 9:30 AM New York time

53
00:03:18,180 --> 00:03:21,840
and it closes down at 4:00 PM on the same day.

54
00:03:22,410 --> 00:03:24,960
And often when you're getting data on stocks,

55
00:03:25,260 --> 00:03:30,060
you can get the price of a particular stock at the point when the market opens

56
00:03:30,300 --> 00:03:33,120
and when the market closes. For example,

57
00:03:33,120 --> 00:03:38,120
we could compare the price of the Tesla stock at market close yesterday.

58
00:03:38,610 --> 00:03:43,610
So that was about $1,567 and at market close the previous day

59
00:03:45,560 --> 00:03:48,510
so that's four o'clock on the 20th of July,

60
00:03:48,900 --> 00:03:53,900
and that was at around $1,641.

61
00:03:54,120 --> 00:03:59,120
So there was a big difference between the end of the 20th of July and the end of

62
00:03:59,490 --> 00:04:03,630
the 21st of July. As a stock trader would be quite 

63
00:04:03,630 --> 00:04:08,310
interested in these big fluctuations because it might mean that we would want to

64
00:04:08,340 --> 00:04:12,150
buy more, or we might want to sell our stocks in Tesla.

65
00:04:13,020 --> 00:04:14,910
When you look at a lot of these services

66
00:04:14,940 --> 00:04:18,690
be it Bloomberg terminals or something much simpler like this,

67
00:04:19,019 --> 00:04:21,930
they often give you a whole bunch of other data as well.

68
00:04:23,100 --> 00:04:28,100
One of the most useful things is actually to look at the news that's related to

69
00:04:28,350 --> 00:04:32,340
the company that you're investigating. So for example,

70
00:04:32,340 --> 00:04:34,740
these are the current headlines for Tesla,

71
00:04:35,250 --> 00:04:39,990
and it comes from various news sources like Reuters or my Wall Street or

72
00:04:39,990 --> 00:04:44,850
Bloomberg. And it gives us some information to start analyzing.

73
00:04:44,850 --> 00:04:48,480
For example, well why was there this big drop, what's the reason,

74
00:04:48,990 --> 00:04:52,710
and there's various news sources that might tell us why. For example,

75
00:04:52,710 --> 00:04:56,130
maybe they're experiencing problems with servicing staff,

76
00:04:56,220 --> 00:05:00,330
or maybe as this news piece suggests, the stock is probably going to rise again.

77
00:05:00,930 --> 00:05:02,850
So these are really interesting things

78
00:05:02,880 --> 00:05:05,820
if we were to trade this particular stock.

79
00:05:06,750 --> 00:05:10,350
If we were to create a Python program that's going to help us trade stocks,

80
00:05:11,010 --> 00:05:14,010
then this is how it might work. First,

81
00:05:14,160 --> 00:05:18,480
we're going to pull in the stock prices of the stocks that we're interested in.

82
00:05:18,900 --> 00:05:21,810
So we would be using an API to get this data.

83
00:05:22,560 --> 00:05:26,460
And let's say that we were monitoring the Tesla stock cause we bought some

84
00:05:26,460 --> 00:05:29,400
shares and we want to know how it's doing. Well,

85
00:05:29,430 --> 00:05:34,430
it might pull in the data for the price of Tesla stock that was at market close.

86
00:05:35,220 --> 00:05:37,950
Let's say that today was March the 11th.

87
00:05:38,250 --> 00:05:43,170
So we're pulling in yesterday's closing price and let's just say, for example,

88
00:05:43,320 --> 00:05:44,700
it is $1,000.

89
00:05:45,270 --> 00:05:49,320
Now the next thing our program is going to do is it's going to pull in the

90
00:05:49,350 --> 00:05:52,020
closing price on the previous day.

91
00:05:52,530 --> 00:05:56,760
And we're going to compare these two values. So over the course of one day,

92
00:05:56,790 --> 00:05:59,300
what was the difference. And in this case,

93
00:05:59,360 --> 00:06:03,890
there's a difference of a hundred dollars and the direction is up.

94
00:06:03,950 --> 00:06:08,720
So it increased in value, right? Going from March 9th to March 10th.

95
00:06:08,960 --> 00:06:12,260
So that's good news for us if we bought in. Now,

96
00:06:12,320 --> 00:06:16,910
we can also calculate what is the percentage that this rise represents.

97
00:06:16,940 --> 00:06:21,770
So if we look at this difference of a hundred dollars and calculate it as a

98
00:06:21,770 --> 00:06:24,890
percentage of yesterday's closing price,

99
00:06:25,160 --> 00:06:30,160
then we can see that the price on March 9th was 10% lower than on March 10th.

100
00:06:31,340 --> 00:06:33,650
So let's say that in our Python program,

101
00:06:34,010 --> 00:06:37,550
we set the program to run and fetch us some news

102
00:06:37,790 --> 00:06:42,530
whenever we get a slightly extraordinary rise or an extraordinary fall.

103
00:06:42,920 --> 00:06:46,850
So you can define that as anything you want, but let's say it's 10%.

104
00:06:47,600 --> 00:06:52,400
If there was a difference of 10% or more between yesterday's closing price and

105
00:06:52,400 --> 00:06:55,040
the previous day, then we want to know about it.

106
00:06:55,910 --> 00:07:00,470
So we're going to get our API to fetch us some relevant news.

107
00:07:01,070 --> 00:07:05,240
That way we can figure out what is the reason for this rise or what is the

108
00:07:05,240 --> 00:07:06,350
reason for this fall.

109
00:07:06,860 --> 00:07:11,030
And it might just turn out well because Tesla launched a new product,

110
00:07:11,360 --> 00:07:14,240
or because they've acquired a new factory.

111
00:07:14,480 --> 00:07:17,240
Some sort of indicator that says, well,

112
00:07:17,240 --> 00:07:20,630
this company is going to do a lot better. Now,

113
00:07:20,630 --> 00:07:25,630
once the stock prices have triggered this alert and we fetched the news data,

114
00:07:26,660 --> 00:07:29,660
then we're going to send ourselves an SMS.

115
00:07:29,930 --> 00:07:34,190
So we're going to send ourselves a message telling us what was the big

116
00:07:34,220 --> 00:07:39,220
fluctuation that happened and what is the relevant news so that we can decide

117
00:07:39,440 --> 00:07:41,780
there and then whether if you want to sell our stock,

118
00:07:41,810 --> 00:07:42,950
or if we want to buy more.

119
00:07:43,730 --> 00:07:48,440
We're aiming for messages from Twilio that look a bit like this.

120
00:07:48,950 --> 00:07:49,610
That way

121
00:07:49,610 --> 00:07:52,940
when you wake up in the morning and you're wondering what's happening with my

122
00:07:52,940 --> 00:07:57,020
Tesla stock and it just so happens that over the last two days,

123
00:07:57,110 --> 00:07:59,510
it experienced huge fluctuations,

124
00:07:59,870 --> 00:08:04,870
then you would get sent the relevant pieces of news to help you decide and help

125
00:08:05,270 --> 00:08:10,190
you figure out what you should do with your trades. That's the goal.

126
00:08:10,430 --> 00:08:15,350
And the best part of this project is the fact that it's going to be mostly up to

127
00:08:15,350 --> 00:08:17,060
you as to how you create it

128
00:08:18,190 --> 00:08:20,350
In the course resources I've got links

129
00:08:20,650 --> 00:08:24,100
to starting projects with the comment and hints,

130
00:08:24,580 --> 00:08:29,020
and depending on which level of difficulty you want to choose, normal,

131
00:08:29,020 --> 00:08:33,520
hard or extra hard, you can pick the starting project that's right for you.

132
00:08:34,090 --> 00:08:35,710
Once you pick the starting project,

133
00:08:35,740 --> 00:08:37,780
then you are going to work through each of the comments

134
00:08:38,110 --> 00:08:42,280
and you're going to try and complete the functionality of this program.

135
00:08:42,940 --> 00:08:47,200
Now I want you to spend at least a half an hour to 45 minutes working on this

136
00:08:47,200 --> 00:08:51,580
project, just because it has quite a few APIs that you need to tap into.

137
00:08:51,940 --> 00:08:53,440
And most importantly,

138
00:08:53,710 --> 00:08:58,440
I want you to read through the API documentation yourself so that you can

139
00:08:58,440 --> 00:09:02,820
understand how to work with it and how to figure out things on your own.

140
00:09:03,210 --> 00:09:06,300
Because after all, there are millions of APIs out there

141
00:09:06,420 --> 00:09:09,270
and if you're going to need it for a special project of your own,

142
00:09:09,570 --> 00:09:12,870
you're going to need to go through this process that all developers go through

143
00:09:13,050 --> 00:09:18,050
which is digging through documentation and understanding how to work with an

144
00:09:18,240 --> 00:09:19,073
external piece of  software

145
00:09:19,550 --> 00:09:21,350
or code.

146
00:09:21,380 --> 00:09:25,700
That's the challenge I've set for you. Head over to the course resources now and

147
00:09:25,700 --> 00:09:29,630
get the starting code so that you can get started working on the project.

148
00:09:29,750 --> 00:09:30,380
Good luck.

