# NIFTY Case Study

In Week 9, NIFTY Case Study, while calculating the percentage of Market price higher than the previous day I’m able to get the same as shown in the video. But after computing the percentage of Market price lower than the previous day and summing both results it’s not equal to 100. Why does this happen?

Hi @msanthosh1855,
I get you, but think of it the other way… If we had only 5 values in the time series data, there would have been only 4 comparisons(2-1, 3-2, 4-3, 5-4).
So, if we say that the steady increase in prices was there for 3 instances, whereas prices decreased on one such instance, it would have been 3/5 + 1/5 = 0.8

Similarly, if we have n values, we’ll be having n-1 comparisons. Thus for finite values, (n-1)/n will never be 1.

2 Likes

Hey! I had some other query on the same topic.
In order to understand the rolling function better, I tried to sum the values instead of calculating the mean of it

Interestingly it reveals that weekend values are being taken as 0 instead of skipping them while calculating the sum and hence the Moving Average. I’m not quite sure if this is how the moving averages are actually calculated or do we have to modify the rolling function somehow to compensate for the Gap and allow it to exclude weekends from the ‘last 5 days’.

Kindly provide a solution as to what is the right approach here

Thank You
-Keshav

Hi @keshav0801,
That’s something to worry about, as far the rolling function is concerned, it does not consists of a filter like this to remove weekends out of the rolling window.

One solution which may work out, is to set the `window = 7` so that weekends get included in each window, and hence it will automatically be equal to 5. This will work out for `.sum()` but surely will fail if we try to calculate mean.

Here is the documentation for rolling function, maybe if someone can figure out some other way of doing it.

Hi again! @Ishvinder
As you suggested, I tried to do some experiments with setting different values for window.
what I figured out was that if i set window = 5 instead of ‘5d’ then i can get accurate results with both mean() and sum(), but first 4 values yields NaN due to absence of 5 values before them.
I also tried to use ‘7d’ for the sum, and it worked out great for calculating sum(), all the values came out to be around 50k which is what was desired
But as you can guess window = ‘5d’ and window = 7 do not yield the desired result
I think for calculating accurate Moving Averages, only correct way would be to use window = 5 or window = ‘7d’

Hope I’m thinking in the right direction.
Thanks

1 Like

Cool!
Yes i also meant to say window=‘7d’ anyhow.
For the NaNs problem, maybe you can look after `min_period` argument from the documentation.

2 Likes

I think to get the subset of NIFTY data for fridays, instead of using for loop & pd.copy, we can use

new_nifty[new_nifty.index.dayofweek == 4]

Any implications in above approach?

Even when we use window = 5d, the average for the 5th day should be 10774.8, but it is showing 10723.8, can you please explain why?