WEBVTT

00:00.540 --> 00:07.280
Welcome to the solution for coding exercise 11 and we import pen I sent my plug flipped and we also

00:07.280 --> 00:09.410
import the Apple Facebook.

00:09.460 --> 00:10.460
Yes we fire

00:17.160 --> 00:24.270
and actually here we have daily data and now we have to change the frequency year to monthly and this

00:24.270 --> 00:30.300
is also called down sampling and for each and every month we have to display the last the traded stock

00:30.300 --> 00:39.510
price per month and we can actually change the frequency with the free sample method and we pass M for

00:39.510 --> 00:42.460
monthly and then we select.

00:42.480 --> 00:50.590
The very last stock price for each month and the question is about as of the last traded price for Facebook

00:50.590 --> 00:59.520
and march to 15 and that is eighty two point two to and we can actually see here on the left hand side.

00:59.620 --> 01:06.730
So here we have the very last calendar day of each month and then a question ninety nine we should actually

01:06.730 --> 01:13.690
perform the same operation but instead of having at the last the day of each month we want to have the

01:13.690 --> 01:14.290
period.

01:14.290 --> 01:21.790
So for example only January February March and so on and uh we can do this again with the re sample

01:21.790 --> 01:29.350
method and pass M and then we have to pass a period to the kind parameter and by doing so we create

01:29.350 --> 01:36.370
actually a period index and again we select the very last the price of each month.

01:36.400 --> 01:44.230
So let's run here so and here we have on the left hand side now a period index January February March

01:44.260 --> 01:51.860
and so on so on the last two exercises that we down sample to monthly and we actually display it.

01:51.930 --> 01:58.890
The very last trading price but we can also display the average monthly trading price.

01:59.250 --> 02:07.210
And we can do this by again using the read sample method and the changing then the mean method and uh

02:07.290 --> 02:13.980
we save the resulting data frame and the variable stocks monthly and the question is this.

02:13.980 --> 02:18.090
What was the average stock price for Apple in April to 15

02:20.720 --> 02:25.100
and the average price was one hundred twenty seven point nine.

02:25.100 --> 02:31.820
Here we have to create airline plots for the daily stock prices as well for the monthly stock prices.

02:31.820 --> 02:38.940
So first of all we have here the daily stock prices and now the monthly stock prices.

02:39.200 --> 02:47.390
And we can see that we essentially smooth and the data so we we can see actually daily movements and

02:47.420 --> 02:55.990
uh these uh smooth movement here and the monthly data in this exercise we sat down sample stocks to

02:56.000 --> 03:01.660
a weekly frequency and showing the prices on Fridays and the Christmas year.

03:01.670 --> 03:08.540
What was the Facebook stock price on the fourth Friday and January 215 and again we use the read sample

03:08.540 --> 03:16.610
method and as the frequency we have weekly Friday and we take the last the day actually of each week.

03:16.610 --> 03:17.480
So Friday

03:20.290 --> 03:21.250
a..

03:21.280 --> 03:28.810
Actually the fourth Friday and January 215 and the Facebook stock price was here seventy seven point

03:28.840 --> 03:31.620
eighty three next.

03:31.630 --> 03:35.630
Let's have a look at stock prices in January to 15.

03:36.550 --> 03:42.580
And uh we can see here that we do not have all the 31 days of January because here we have only trading

03:42.580 --> 03:43.000
days.

03:43.390 --> 03:50.230
So we do not have prices here for bank holidays and weekends for example.

03:50.230 --> 03:56.710
The third and the fourth of January are Saturday and Sunday and he and this question how we shall create

03:56.740 --> 04:00.900
a daytime index that we thought 31 days in January to 15.

04:01.030 --> 04:05.680
And later we have to re index here our stocks data frame by the new index.

04:05.680 --> 04:09.520
But first of all let's create the new day time index.

04:09.520 --> 04:16.480
And of course we again do this with the date range method with a start date the 1st of January and we

04:16.480 --> 04:18.900
have 31 periods.

04:19.120 --> 04:23.110
So that's the daytime index all days in January.

04:23.140 --> 04:29.740
And now finally we have to re index the data frame stocks by the day time index all days in January

04:30.160 --> 04:37.810
and we actually have to forward fill any resulting missing values service stock prices that is pretty

04:37.810 --> 04:44.500
common to use uh the last traded price on Friday also for Saturday and Sunday.

04:44.500 --> 04:49.860
And therefore in this case that makes sense to use the forward fill method.

04:49.870 --> 04:57.790
So first of all you see the re indexed method on the stocks data frame and we pass the new in next year

04:57.820 --> 05:03.070
our all days January index and then we select the format for the method

05:06.850 --> 05:13.300
and we have now also the timestamps for the third and fourth of January Saturday and Sunday.

05:13.300 --> 05:21.180
And uh the values are exactly the same as on the 2nd of January of Friday because we forward filled

05:21.190 --> 05:23.010
here the N A values.

05:23.110 --> 05:25.480
So that was the coding exercise eleven.

05:25.480 --> 05:29.980
I hope you had fun and the hope to see you also in the next exercise by.
