Calculating returns of a range using Product + Offset functions

gcefaloni

Board Regular
Joined
Mar 15, 2016
Messages
119
Hi,

I'm trying to calculate monthly returns of a stream of returns using an ongoing set of daily returns. So what I was trying to do was something of the sort:

A4:A10000 column = WORKDAY(daily dates)
B4:B10000 column = daily returns %
S2:S61 column = end of month dates (Jan 2019 to Dec 2023)
T2:T61 column = where I would like monthly returns %to populate next to each month in column S

Returns start at row 4; lets say we are trying to calculate Feb 2019 returns
{=PRODUCT(1+OFFSET(return of first day of the month of cell showing '02/28/2019',COUNTIFS('daily_dates',"=<"&'02/28/2019','daily_dates',">"&('02/28/2019'-DAY('02/28/2019')+1)),0,-DAYS('02/28/2019','01/31/2019'))-1)}

Which currently translates into
{=PRODUCT(1+OFFSET(INDEX(A4:B10000,MATCH((S3-DAY(S3)+1),A4:A10000,0),2),COUNTIFS($A4:$A10000,"=<"&S3,$A4:$A10000,">"&(S3-DAY(S3)+1)),0,-NETWORKDAYS(S3-DAY(S3)+1,S3))-1)}

It returns me a "#Ref" output.

So there are a few things I'm not sure about:
1- Using INDEX(A4:B10000,MATCH((S3-DAY(S3)+1),A4:A10000,0),2) give me my initial reference cell that corresponds to the first day of the month that I'm trying to calculate returns for, does that only give me the value instead of the actual cell that the Offset function could use (e.g. return -0.00027 instead of B4.). Currently returns B$4$ in evaluate formula check.
2- The countifs syntax to calculate the height of the range within the offset function using lesser than EOMonth date in S3 and first day of the month showing in S3. When evaluation the formula, it returns 0 instead of whatever the range height should be.
3- Calculating the offset range height using Networkdays. It currently seems to return the correct 20 for Feb 2019.

You guys seeing any solution/modification to what I'm doing in order to achieve the objective of simply calculating geometric monthly returns using daily returns?

Here's my current table:

A B S T
DateDaily Change %31-Jan-19
31-Jan-1928-Feb-19#Ref!
01-Feb-19-0.027%31-Mar-19#Ref!
04-Feb-19-0.252%Apr-19
05-Feb-190.193%May-19
06-Feb-190.010%Jun-19
07-Feb-190.261%Jul-19
08-Feb-19-0.020%Aug-19
11-Feb-19-0.079%Sep-19
12-Feb-19-0.061%Oct-19
13-Feb-19-0.012%Nov-19
14-Feb-190.365%Dec-19
15-Feb-19-0.056%Jan-20
18-Feb-190.027%Feb-20
19-Feb-190.059%Mar-20
20-Feb-19-0.033%Apr-20
21-Feb-19-0.170%May-20
22-Feb-190.224%Jun-20
25-Feb-190.077%Jul-20
26-Feb-190.194%Aug-20
27-Feb-19-0.330%Sep-20
28-Feb-19-0.180%Oct-20
01-Mar-190.161%Nov-20
04-Mar-19Dec-20
05-Mar-19Jan-21
06-Mar-19Feb-21
07-Mar-19Mar-21
08-Mar-19Apr-21
11-Mar-19May-21
12-Mar-19Jun-21
13-Mar-19Jul-21
14-Mar-19Aug-21
15-Mar-19Sep-21
18-Mar-19Oct-21
19-Mar-19Nov-21
20-Mar-19Dec-21
21-Mar-19Jan-22
01-Feb-19Feb-22

<colgroup><col><col><col><col></colgroup><tbody>
</tbody>
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Are you looking for the average of column B values for a specific month based on the number of workdays in that month?


If yes, you could try something like this…
=SUMPRODUCT(--($A$3:$A$349>$S3),--($A$3:$A$349<=$S4),($B$3:$B$349))/NETWORKDAYS($S3+1,$S4)


In my example that I tested column A has the dates, column B has numbers, S3 is 1/31/2019, and S4 is 2/28/2019. You will have to adjust ranges for your data and you should be able to copy the formula down for subsequent months.

Hope that helps,

Doug
 
Last edited:
Upvote 0
Are you looking for the average of column B values for a specific month based on the number of workdays in that month?


If yes, you could try something like this…
=SUMPRODUCT(--($A$3:$A$349>$S3),--($A$3:$A$349<=$S4),($B$3:$B$349))/NETWORKDAYS($S3+1,$S4)


In my example that I tested column A has the dates, column B has numbers, S3 is 1/31/2019, and S4 is 2/28/2019. You will have to adjust ranges for your data and you should be able to copy the formula down for subsequent months.

Hope that helps,

Doug

Hi Doug,

It needs to be geometric returns so using Product(1+blablabla)-1 is necessary. As for the result of the formula you gave, it seems to be a bit off. The result your formula is outputting is around 0.0096% whereas we should be getting something around 0.19% for the month of February 2019 based on the numbers in the table above. Not sure what is the difference.
 
Upvote 0
I don't know what geometric returns are. Please elaborate...do you have a formula to return a geometric return? I supplied an average for the month. Can you modify the formula to give you the result you want?
 
Last edited:
Upvote 0
I don't know what geometric returns are. Please elaborate...do you have a formula to return a geometric return? I supplied an average for the month. Can you modify the formula to give you the result you want?

https://exceljet.net/excel-functions/excel-geomean-function

The most versatile way to do it is an array formula where we compute PRODUCT(1+(daily returns array))-1. This will give you the geometric mean of the returns. In our exemple, I am trying to get the daily returns array through the offset function while filtering for only the month we need.
 
Upvote 0
So the geometric mean (not geometric returns) is determined by calculating the nth root of the product of n numbers. Pretty straightforward.

The equation including OFFSET as you started is something like this... =PRODUCT(OFFSET($A$2,MATCH($S2,$A$2:$A$158,1),1,MATCH($S3,$A$2:$A$158,1)-MATCH($S2,$A$2:$A$158,1),1))^(1/(MATCH($S3,$A$2:$A$158,1)-MATCH($S2,$A$2:$A$158,1)))

It worked perfectly on some test data that I setup. You may have to make adjustment to fit your data.

Doug
 
Upvote 0
So the geometric mean (not geometric returns) is determined by calculating the nth root of the product of n numbers. Pretty straightforward.

The equation including OFFSET as you started is something like this... =PRODUCT(OFFSET($A$2,MATCH($S2,$A$2:$A$158,1),1,MATCH($S3,$A$2:$A$158,1)-MATCH($S2,$A$2:$A$158,1),1))^(1/(MATCH($S3,$A$2:$A$158,1)-MATCH($S2,$A$2:$A$158,1)))

It worked perfectly on some test data that I setup. You may have to make adjustment to fit your data.

Doug


Sorry for late response. I was tyring to play around to figure out how your formula worked. I think it works if you have a full month's data but then I realized that using the S3-S2 methodology won't work if the current month isn't completed and I want to know what is the return for the current month if it's not over, which is something that will happen every day of every month except the first day of the month.
 
Last edited:
Upvote 0
Does that mean you have the future dates in colA, but no data in colB?
 
Upvote 0
Does that mean you have the future dates in colA, but no data in colB?

Yes, I essentially use a macro that prints the day's date and the corresponding daily return at the end of every day. So the table just keeps growing every day, I would like to keep track of the past month's returns in their own cell but then move on to the next month, check what the first day of that month is (used in reference point of the offset function) and then check what is the last available date for the current month to see what the return is.

I have uploaded a sample file here: https://file.io/jTEaYH

The current formulas in E3 and E4 are incorrect because they don't take geometric mean in effect but they deal with the months properly. I would essentially like to do the same thing using the PRODUCT(1+range)^(1/n)-1 formula in G3. I'm guessing we also need the reference point of the offset function to move to the first day of every month.
 
Upvote 0
Yes, I essentially use a macro that prints the day's date and the corresponding daily return at the end of every day.

Good, no date without value in colB. The Match in the formula should work to find the row for the last day of the month or less...so if the date stops on 10th, it returns that row. Test the Match by itself to see how it works.

I have not downloaded the file so I have idea what is in colE or colG. I did just realize that when you get the match and offset working with your data you can use the GEOMEAN function instead of product and nth root.
 
Upvote 0

Forum statistics

Threads
1,213,494
Messages
6,113,986
Members
448,538
Latest member
alex78

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top