 Hello everyone, welcome to the class of business forecasting. Today, we will discuss different type of moving average methods. In the previous session, we discussed different components of time series analysis and measures of forecast accuracy. Today, we will continue that concept and we will use different type of measure of forecast accuracy in moving average methods. At the same time, we will learn the most three important techniques of moving average methods. That is called simple moving average, weighted moving average, and exponential moving average. In practice, there are many more methods of moving average that exist, but we will concentrate on three most popular methods that have been used in the industry. So let us discuss today's session. In predictive analytics and machine learning, forecasting is one of the important aspects of decision making. In general, there are different type of forecasting techniques available. Here we can see that qualitative methods which we have discussed in the previous session, and then time series methods which we are concentrating in detail. Then causal models or regression analysis we will discuss in detail of machine concepts of supervised learning we will discuss. And then simulations model also will be covered one by one. But today, we will concentrate only on moving average methods. Remember, in the past session, we discussed different type of components of time series as well as the measures of forecast accuracy that we will try to apply here. We will not concentrate about components because we have already discussed the components of time series analysis. Today, we will concentrate the use of measure of accuracy because three different models of moving average we will discuss today. One is the simple moving average and then weighted and the exponential. Let us start with the simple moving average. In general, these three models are most popular in the industry and easy to use. And these models are being used for stationary data or steady data. In general, if you have too much of outlayer or randomness or irregularities, then this type of model may not work effectively or the error of forecast accuracy might be high. So therefore, we will be assuming that data are being preprocessed, missing data or outlayer has been removed and suppose you have a steady data or to some extensionary data and then we will use these three models, we will make a forecast. We will concentrate on how these models are being used or what are the techniques of these models so that one can understand the calculation process or the iterative process as well as the application part with some examples. I will also illustrate the Excel all these three problems or three methods using Excel also. So, let us start the first model that is called simple moving average. Simple moving average is the most easiest moving average techniques among the available you know techniques available in the literature. So, in simple moving average what do we do? You take suppose you have a data sets, you take couple of initial data say 3 pre-odd, 4 pre-odd or 7 pre-odd or say 10 pre-odd and then you fix it. Then you drag that average first suppose you have taken a 7 days average. So, you take the 7 days average so that first 7 days average is average is coming to be the forecast for the 8 period. Then when you go to the next period you drop the older period and take the new period and drag this average for the forthcoming process. So, this is what the simple moving average. In general, you know if you have a weekly data, monthly data or say you know quarterly data or yearly data for any type of data actually or even with the small time period say you know daily data or say you know time wise say at 8 o'clock, 9 o'clock, 10 o'clock this type of data also you have you can use moving average, but only condition is that the data should be stationary otherwise the forecast accuracy will not be the good. So, in simple moving average what do you do? You give equal weightages to all the past data when you take the average you are not changing any weightages. So, let us see how it works. Look at the statement here. Suppose here I have mentioned about 3 months. You can take 3 months or 4 months or 7 months or you know depending on the example suppose 3 periods. I will show you different type of period clustering or period range and then I will illustrate different type of examples. So, now suppose if you see the you know the formula of simple moving average suppose if you take a k period moving average it is nothing but the past k period you consider and divided by k you are getting simple average simple average. But then why it is moving? Why it is not simple average? Because in the next period when you forecast for the next of k plus for k plus 1 period when you do the forecast you drop the older period, one older period and you add a new period the kth period come into the picture. So, therefore every iteration you drop one older period and you add one new period therefore we call it is a moving average or say simple moving average. Here is the one example you can see here. Suppose this is the sample data sets and for the sake of illustration we have taken say 3 months moving average and you take the first 3 period because it is a 3 months moving average you have fixed. This 3 months moving average you cannot change suppose that is fixed now and then what you do? You take the average of these 3 months look at the average of these 3 months we have taken here and we have made a forecast of 26.33 for which period? For actually 4th period for 4th period forecast we have done here ok now that is done. Now next point now you want to make a forecast for the 5th period. So for 5th period what you would do? For 5th period what you would do? You drop first period and you include 4th period. So your new average will be you know 2nd period, 3rd period and 4th period. So at every time period what you are doing? You are actually you are dropping on older period and you are adding one new period and this way you are dragging your moving average therefore we call it is a simple moving average. Now this process is easier and if the data are to some extent stationary to some extent stationary your forecast will also be to some extent you know good prediction as well as also you know the accuracy will be quite good. I will show you through excel illustration we will get to know detail about it. In the previous session we have discussed different type of major of accuracy or already I told in the previous session also and today also I will be repeating that statement that whatever the forecast you get that is not a matter. The matter is look at here even here we got a forecast say you know 26 so this is just couple of data I have taken not all data. Let us go to the next slides you will get to know suppose here you have full amount of data suppose and you want to make a forecast for pre-ordered team. So what is the future forecast with your data sales and whatever the model you are adapting whether it is a simple moving average or weighted moving average or name method so far we have discussed not a matter. Matter is what is your major of accuracy that is the most important part. If you have a less major of accuracy or percentage of error then we can say that that model is better. I have already discussed the comparative analysis between the name model and the basic moving average today we are going to discuss the detail about it. So let us see the illustration of simple moving average quickly. So suppose you have a data say and suppose for the sake of illustration earlier in the previous slide I have talked about say 3 months moving average or 3 period moving average suppose here I have taken 4 period moving average. This period of cluster is being taken based on your term management decision making or the group decision making or based on the requirement for example for stock price prediction for example say you can take 7 days moving average for short term prediction etcetera or say you know maybe 20 days moving average and for long term investor they take actually 200 days moving average or say 50 days moving average because 200 I will show you today at the end of the session you will get to know why people take 200 days moving average, who takes 200 days moving average, who takes 7 days moving average. You remember the corona cases when used to see during corona in our mobile that in the in world meter that how much cases has come corona cases has come in my state or in my country and in China or in USA what used to see used to see the 7 days if you click some you know particular state or particular country we used to see that you know that 7 days moving average. That means they have taken a 7 days average and they have dragged that. So every new day the older period older periods goes back and like dropped and the new period new day comes and the 7 days are been carrying forward every day or every moving average process. So that is called the 7 days moving average. In corona cases I can remember it was shown through the world meter websites. But anyway suppose you can optimize this also 4 days moving average based on the data pattern which will give which combination of period will give you the least error you can consider that period as your average of combination. Otherwise it is a group decision making based on the requirement of the problem or the context of the problem statement. Suppose here we have assumed the 4 period average. Now look at the data sets here. Suppose 4 period average means for 5th period we will make the first forecast then here. So 4 period average we have taken and we have got the forecast here. I will show you that in Excel also but the summary I have kept here for your quick understanding. And then you can see the error. Now we are adding new component that is called error. So what is the error? The actual minus forecast. So here you can see that minus 2.5 keep it as it is then the absolute value we have taken absolute value we have taken and that is 2.5 and we have taken percentage error. Well that means actual say you know 2.5 by your like absolute value by 25 into 100 percent. So this way you have calculated the error and the square error is nothing but the square of this or square of absolute value whichever you want. So this for first iteration we have done it, store it. Then you drag here moving average, so simple moving average because equal weightage you have given suppose here 4 periods you have taken. So what is the equal weightage is 25 percent to each, 25 percent, 25 percent, 25 percent, 25 percent. This weightage we fixed actually because 4 period average you have taken and now you drag it. So what in the next period what we will do? You will drop this first period and you will add the fifth period and new average will be you know this one and you drag this, you move forward this is what the moving average. For example, for period 18 your average will be last 4 period that average will come here that is it. But see all points will have equal weightages this is what the mandatory requirement for simple moving average because you are doing simple moving average only and you are dragging it therefore it is a moving average. So this is what the forecast using you know simple moving average we got 26.5 just as a forecast it can be different depending on the requirement or the practical cases. Suppose here for that data sets simple moving average forecast is 26.5 for the period 18. Now you think about your absolute error here suppose you have found say mean absolute error after taking all the error and absolute value you take the average you will get say you know couple of data we have 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13. Suppose 13 data you have you can take an average here and you get you know mean absolute deviation as 1.71 and absolute percentage error how much 6.61 and mean square error if you take the square and then take the average of that sum and then average you are getting actually 4 the entire detail analysis of this 4 methods and the RMSE square root of this we have already discussed you can go through that you can refer to that particular lecture and you can understand how the calculations are being done. Anyway I will show you in Excel today also. So this is what the forecast through simple moving average. Now if you see the graph look at the graph here so nice so we have taken the 4 period moving average for this data sets so actually 4 period are coming here look at the 4 period 1, 2, 3, 4 and first forecast has come here but actual data is here for that period this is the error you can note down the error which is nothing but how much 2.2 I think minus 2.5. Now you come back here so here now you move your forecast so this first period you drop and new period you add so now your new forecast will be new combination of forecast will be this 4 period because you are you have dropped this folder period you have added a new period and you will get a forecast for 6th period so this way you know you can carry for all the forecast and look at the forecast to some extent quite good actually because it is taking average out but this to some extent ok for steady data if you have a non-stationary data how to handle that we will discuss in some other session so this is what the simple moving average. Now if you think or if you recall the same data sets and name method we have analyzed this data through name method also and if you remember the forecast accuracy there the mean absolute percent error was 9.34 percent in name method I have taken that slide only the summary slide of name method and you can see here mean absolute percentage error is 9.34 percent and in our moving simple moving average it was 6. something right let us see it was I think 6.6 percent so what does it mean it means that simple moving average is giving least error or minimum error in terms of percentage here it is a 6.5 percent 6 percent and that is a 9.4 percent 3 4 percent so here it is giving least error or the minimum error therefore the measure of accuracy is higher in moving average for these data sets so we would recommend that to the clients or to the management that you know prefer simple moving average for this data rather than name method because it is giving lower error or you know better measure of accuracy. Now if you think about the mean square error also here it is for moving average simple moving average here it is coming out to be 4 and mean square error like the way you calculate standard deviation here I have shown you the calculation process of mean square error you can do that as it is and then if you calculate the same through name method we found 10.37 so here also we could see that the mean square error is higher in name method but in simple moving average it is lower so therefore we can recommend that we can see that in either of the cases we can see that you know simple moving average is performing better as compared to name model for this data sets. If you change the data set it might name method can be winner but for this particular data set we could see that simple moving average is performing better and RMEC also you can check here it is 3.22 and there are others I think it is 2 look at the 2 so in every aspects you know whatever the method of measure of accuracy you select simple moving average is coming out to be a better performer. Now we understood the simple moving average now we will go we will extend the concept to the weighted moving average look at the simple moving average you need to understand but it is very much applicable in industry many people prefer it now let us see what additional part are been involved in weighted moving average which is extension of simple moving average weighted moving average are nothing but the moving average same process of moving average you will follow and the cluster of the range of the data sets in the in the beginning you will fix it as it is like simple moving average but the only difference is that in simple moving average suppose you have taken a 4 period moving average and there you have taken you have given equal weightages to all the 4 period right like 25 percent 25 percent 25 percent 25 percent 4 period that you have fixed that weightages so equal weightages you have given and you have dragged your moving average but in weighted moving average you have the flexibility to change the weights so it is like that if you think that you want to give some extra weightage to the immediate period suppose there is a little uptrend in the data or in downtrend in the data and you suppose too much of corona cases coming up suppose the example that I was giving so in that case you can see that immediate period has a should be given higher voltage because there is uptrend in the corona cases right so in that case you can give some some sort of extra weightage to the immediate period so that flexibility is with you in weighted moving average so let us see how the weighted moving average works with same examples that you know and it also the advantage of weighted moving average is that in practice if you think that the data has a train or data has a some some sort of variation which is following a bit like seasonality or to some extent there is a different method I will discuss that in detail like winter method or decomposition method or seasonality index calculations will discuss detail but I am talking about the suppose if the data follows similar pattern and if you think that in a particular period it has a higher weightages so you and that has been repeated to some extent you can change your weightages why to give equal weightage to all the data because you know the trend of the data and if there is uptrend down to some extent seasonal variation so maybe and you want to use weighted moving average probably it is better to change the weights so this is what the flexibility you have been weighted moving average here is the formula look at here so by multi you multiply each data point by its weight because you are changing the weights at W1, W2, W3, W4 say I will show you some examples some of the weighted data points divide the sum by the total weight repeat the process for each data point and then drag it so here same as same as it is simple moving average but look at here K period moving average is nothing but weight multiplied by the data and divided by the total sum for example suppose if you take a 4 period say 4 period moving average so suppose you know you can say Y say 4 will be say you know W1 you know Y1 plus W2, Y2 plus W3, Y3 suppose if you take a 4 period average suppose in that case say phi plus say W4, Y4 by W1 plus W2 plus W3 plus W4 some of them should be 1 the weight is so this is what your forecast now for fifth period now if you drag it say this weightage are fixed now this weightages are fixed now look at this this weightage will remain fixed this outage will remain fixed now and now what you do if you want to make forecast for say 6th period you just drop Y1 you just drop it and add just replace being Y like you know it will be like let me elaborate so the weight say W1 W1 into Y2 plus W2 into Y3 plus W3 into say Y4 plus W4 into say Y5 by W1 plus W2 plus W3 plus W4 so that means the weightage are being fixed weightages are fixed now everywhere you can see and then you are just changing the data sets because you are dragging it and you are making forecast so you can make a forecast of say Y1 plus now this way you can make a forecast this is what does in weighted moving average so flexibility of weights are been there with you now you might have a question sir in practice this weightages may change from person to person now so I may give a different weight I may I may think that you know that immediate period may take some higher voltages the total some total of distribution of the weightage should be 1 but suppose I may think give 50 percent to the immediate period but my friend can give a 50 percent to the older period depending on the thought process and the psychology of the people or the you know decision making process of the people then so the in that case the forecast will change from person to person no in the the advantage of weighted moving average is that once you have a good amount of data and you initially assign some weights say suppose for period you have taken combination right so you give some weightages initially whatever the weightages you give you can optimize the weights actually so actually if you optimize the all the weights that you have given to your data sets for every people the finally the weightage will come as a same points that means everybody will come with the same optimum weights same optimum solution how come everybody will come with the same weights for for any data sets if everybody starts with the say you know say n period moving average you will get to know I will show you in excel how you can optimize and how everybody will come up with the same weights selection for the weighted moving average methods we will discuss that in excel so now suppose here is the illustration of the weighted moving average suppose same for period moving average we have taken same data sets we have taken now that which we have illustrated for simple moving average and now if you take for period moving average here here you are not giving 20 percent weightages to the to the each 4 data you are giving these weightages you might say from where you got sir this weights we have optimized it I optimized this data this weights I will show you in excel so now based on this data pattern this is the best combination of weights actually 32 percent weightage you are giving to the for immediate period so if you drag it even suppose if you take a forecast for 18th period so you take first last 4 period actually 32 percent weightage you are giving to the 17th period also because you have dragged it so therefore this weightages will fixed you have to you know you have to freeze it you have to optimize it I will show you that in excel once you finalize your weights you drag it you will get the forecast here you found forecast 26.14 but in the previous period you got 26.5 I think look at 26.5 so you might say that sir simple moving average is showing 26.5 and weighted moving average showing some lesser value here so which which forecast we should consider anyone you can consider think because it is a forecast it may not 26.5 or 26. something may not be the forecast actual value it may be 22 it may be 30 I have shown you many examples right suppose if computer close shut down their shop enter enter demand will come to your store there will be spike so you don't know there may be if there is a strike cell will not come actually so because you cannot run your business so there may be many situations and the practical understanding if you see so anything can happen in future but based on the data pattern past data behavior we are making a future prediction that is your predictive analytics right. So, we have made a forecast so that is not the objective what is the final outcome this is expected outcome actual case is the the error part measure of accuracy. So, let us see what is the measure of accuracy for this particular weighted moving average model here we found MAD 1.54 and look at the MAP since we are comparing MAP only here you can see 5.98 which is lesser than even simple moving average that means in method we found I think it was around 9. something or say around 10% so now from 9. something we found in weighted in simple moving average it was 6. something 6.34 something. So, the percentage of error has reduced in simple moving average now if you think the weighted moving average because you are based on the data pattern you have given a different weight now you realize is that since you have optimized the weights and you have understood the data pattern in better manner so optimization software say also in excel you found that the percentage of error is quite lesser than simple moving average also how much 5.98. So, you select weighted moving average for this data actually even discard the simple moving average because weighted moving average is giving better or better forecast here even MAC also here that that was something how much here it is 3.78 and it was in simple moving average it was 4. So, it is also lesser in RMS you look at here it is 2 here it is 1. something look at here 1.98. So, every aspects whatever the major of accuracy techniques you select you see that weighted moving average is better for this particular same data sets. So, we can take a final decision that you know weighted moving average is better than for this particular data sets then simple moving average and name method also. So, this is what the weighted moving average look at the weighted moving average graph here also you have taken the first 4 period and you have started calculating the 5th period forecast, but here you have taken the weighted moving average you have given different weightage to the all the past period and you have dragged the average this what your forecast for weighted moving average and the results in the table I have shown you. Now, let us go to the excel and understand the two methods of moving average that is called simple moving average and weighted moving average through illustration. You can see the excel sheet here now. So, the two method that we have discussed today now will illustrate them through excel. So, if you see here the first model is a simple moving average and here I have taken the 4 period moving average you can see here 4 period simple moving average I have shown you that is in PPT, but here the calculation the iteration I am in a illustrative. So, now look at the 5th period forecast is the average now I have dragged it actually for 6th period you can see here I have dropped the first period and the 5th period I have included. So, this way I will drag my average and the 4th period average is fixed now. So, if you take it and if you drag you are actually getting you know the forecast for the 18th period. So, here 26.5 which I have shown you as a screenshot in the PPT. So, this is what the forecast for like 18th period, but that is not the important you have to calculate the error. So, error is nothing but the actual minus forecast and then we have taken you know all the previous error and absolute value of them and then percentage error which I have shown you and then mean square error square of the absolute value. So, this way we have calculated the error, but then we have taken dragged it like the way we have dragged the moving average and we have calculated the mean absolute deviation we have calculated the mean percentage error mean absolute percentage error 6.62 percent remember it and then we have calculated the mean square error also. So, here it is 4 percent and if you remember the name method which you have discussed in the previous session here you can see 9.34 percent for the same data sets and ms is 10 point, but in simple moving average we found 6.25 6 percent and say 4 percent. So, this is what the forecast and the corresponding error right and this is the calculation for us process for simple moving average. Now, look at the RMEC here you got the square root of it note down it is 2 point something now come to the weighted moving average. So, same way we have calculated the weighted moving average, but here 4 period we have fixed, but the weightages we have assigned initially we have assigned this weight suppose I have optimized it, but I will show you initially suppose I have taken this weightage combination suppose I have taken a weighted combination say 33 percent, 23 percent, 11 and 32 percent how come I found this final optimum optimum weights I will show you now. Now, suppose this is the weight forecast for the 5th period weighted average and then second period like 6th period we have dragged it look at the first period we have dropped we could have been added same like simple moving average, but we have taken the weighted average now and we are dragging it. So, you could drag this because I have fixed the weights look at I have fixed the weights here look at I have put the dollar sign. So, now if you drag it will get the forecast for the say 18th period. So, this is what the forecast for 18th period say keep it here. So, this is the forecast for the 18th period. Now, you have to calculate the corresponding measure of accuracy now onwards we will like here I have calculated all like you know absolute error percentage error all these things, but now onwards I will be focusing only on the mean square error because I have to optimize the weights error also. So, I have taken only column of square error mean square. So, I have calculated the mean square sum and the mean square error the average of that how many data 13 data we have look at the number of error. So, here you can see number of error how many. So, 13 data point we found as a error. So, we have taken the average of that of square error and we found the mean square error is 3.78 and the RMS is 1 point like you know square of mean square error square root of. So, we found this is the you know results now what we will do look at the weight initially suppose I will put some weight say 0.1 say 0.2 say 0.3 and say 0.2 initially I have given. So, total say you know 1 not coming up to be even 1 say whatever suppose you know you can put 0.4 say you can look at some should be 1 because the total weights should be 100%. So, initial some initial value I have given now my forecast is different. So, you might say which forecast to select whether this weight combination work best or earlier that the weightage I have shown you initially in excel that is the best. So, we will optimize it right initial I have given this weightage combination you can put any other weights also and ultimately we will arrive to a single optimum values for everybody. Let us see how I can optimize you go to data and go to solver look at the solver portion is here how to install solver and how to run it I have discussed detail in the previous session. So, I am not going to repeat that suppose you have the solver here and then you bring this solver this optimizations software now linear non-linear optimization here we will use the non-linear optimization because mean square or RMSE is the square root. So, we will have to select the you know non-linear optimization rather than simple simplex LP method. So, here which cell you want to optimize you want to minimize your RMSE right. So, we have selected this cell look at here I can delete all this and I can show you again for your information. So, just select this and go to this particular cell we want to minimize that right come here and then it is a minimization problem or maximization problem it is a minimization problem because you are minimizing the error right. So, for your minimizing the RMSE you can select the RMSE also suppose I have select RMSE to minimize. So, do not select max select the minimum points like you know to up to minimize the objective function and the changing variables means the decision variables who are our decision variables here our decision variables are these weights we have to find these weights right 4 weights. So, we have selected these weights one by one you can put also by comma sign I have dragged all put together. Now, decision variables these cells we have also you know input it into the solver optimization solver now conditions what are the conditions let me delete all this I will start from the scratch. So, that you can understand. So, come here at and select these weights all these weights should be less equals to 1 right here you can put the sign of less than greater than binary integer etcetera equality sign here it should be all weights should be less equals to 1 right everybody all the 4 weights should be less equal to 1. So, we add it now one more part sum of them should be 1 sum of them here in this particular cell I have taken the sum of them. So, sum of them should be 1. So, I will put equal sign I will put 1 sum of them should be 1 now done. So, conditions are being added now objective function will be put and the type of objective function is the minimization or maximization also means and the variable cells changing variables or the decision variables also been added into the system now. And put this mix here that you click this because it is a non-negative results the weights will be positives only. So, we have put you know a decision variables may not be cannot be negative. So, I have put you know non-negativity conditions over here. So, now here you can see if you see here. So, there is a options of simplex LP non-linear programming problem or radiant methods or say evelential algorithm like genetical algorithm etcetera. So, here will be opting non-linear optimization because our objective function is non-linear. So, select it and solve it look at we found the optimum solution here look at initially I have changed the data now weights now optimum weights we have found as 33 percent, 23, 11 and 32 and this space tensor I have kept in you know in the PPT which I have illustrated. This is what the weighted moving average method and the optimum weight we have finalized it will remain same for everybody actually and the corresponding RMS is this which is better than to some extent you know simple moving average. Therefore, we recommended you know weighted moving as the best method for this data sets to make a forecast and 18 pure forecast is also there 26.13 or on force and corresponding RMS is the measure of accuracy is 1.9 or you know you can say that you can calculate the mean absolute error also if you want percentage error and you can calculate that also here I have illustrated RMS which is lower than you know simple moving average and this is what the process. One more thing I want to show you before I conclude this session even if you change any other value like you know if you put say 0.4, 0.2, say 0.4 and say 0.1, suppose initially you have given it is not closer to 1 say initially whatever value you can give you just give and go to solver and run it again system will take care because you have put a condition of some of the weights should be 1 and initial value whatever you have given not a matter again you are getting the same results. So, that means it is optimization has been done here. So, entire weights are been optimized based on the combination of the all 4 weights which whose range are lying from 0 to 1 system has taken all the combination of the weights and they have come up with the best weighted combination for these data sets and the corresponding least RMSC they have predicted they have they have projected and the corresponding forecast has come automatically as per the iterative process. So, this is what the weighted moving average methods and today if you come back to the slides today we have discussed to now in the first half we have discussed these two methods that is called simple moving average and weighted moving average and we have illustrated them also with the numerical data in excel. Now, after the break we will focus on exponential moving average which is much more popular especially in the stock market and what is the concept of exponential moving average and why people use these methods rather than simple moving average and weighted moving average in specially in the you know in financial sector we will discuss that after the break. Thank you.