Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
 
Posts: n/a
Default VBA function for annualized return (geometric mean)

Hi Guys,

I am trying to write this fuction for calculating annualized return
from the monthly returns I have. If I use, (1+Rm) as my range input, I
can calculate the annualized return. But when I am trying to add 1 to
monthly returns within the function and get the answer, I am getting an
error. (apparently I can not add 1 to each element in the input
array/range).
Can somebody please help! (thanks in advance)

Function ROR(d As Range, n As Integer)

Dim a() As Single
Dim f As Integer

'f = Application.Count(d)

c = d.Rows.Count
e = d.Columns.Count
If c e Then
f = c
Else
f = e
End If

ReDim a(d.Cells.Count)
For i = 1 To UBound(a)
a(i) = d.Cells(i)
Next i


prod = Application.WorksheetFunction.Product(a())


k = n / f

ROR = prod ^ k - 1


End Function

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Harlan Grove
 
Posts: n/a
Default VBA function for annualized return (geometric mean)

wrote...
I am trying to write this fuction for calculating annualized return

....

Why are you doing this? Why not use Excel's built-in GEOMEAN function?

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
 
Posts: n/a
Default VBA function for annualized return (geometric mean)

wrote:
apparently I can not add 1 to each element in the input array/range


It is unclear what you did to "add 1 to each element", but I had no
problem making the following change (inserting "1 +"):

a(i) = 1 + d.Cells(i)

I am getting an error.


It is unclear what you mean by "error". Do you mean an Excel
#VALUE or similar error? I do not get any such thing. Or do you
mean that the result is not what you expect -- perhaps always -1?

You have a programming error. By writing "ReDim a(d.Cells.Count)",
you implicitly set the lower bound to 0. But you fill only a(1)
through
a(10). Since you declare "dim a() as single", a(0) is zero, so
Product() always returns zero. You should write:

Redim a(1 to d.Cells.Count)

On the other hand, it is unclear what you pass to your ROR()
function. The wrong parameters for "d" or "n" could cause Excel
errors, of course.


----- original posting -----

wrote:
Hi Guys,

I am trying to write this fuction for calculating annualized return
from the monthly returns I have. If I use, (1+Rm) as my range input, I
can calculate the annualized return. But when I am trying to add 1 to
monthly returns within the function and get the answer, I am getting an
error. (apparently I can not add 1 to each element in the input
array/range).
Can somebody please help! (thanks in advance)

Function ROR(d As Range, n As Integer)

Dim a() As Single
Dim f As Integer

'f = Application.Count(d)

c = d.Rows.Count
e = d.Columns.Count
If c e Then
f = c
Else
f = e
End If

ReDim a(d.Cells.Count)
For i = 1 To UBound(a)
a(i) = d.Cells(i)
Next i


prod = Application.WorksheetFunction.Product(a())


k = n / f

ROR = prod ^ k - 1


End Function


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom functions calculating time arguments Help Desperate Bill_De Excel Worksheet Functions 12 April 25th 06 02:22 AM
VLookUp function to return multiple rows sebastian stephenson Excel Worksheet Functions 7 April 20th 06 06:25 PM
Can a function return a Null (blank ) value? Maybe a custom functi colin_e Excel Worksheet Functions 2 March 16th 06 02:36 PM
Excel worksheet function that will return the currency for a cell funmi_Bash Excel Worksheet Functions 2 August 15th 05 09:17 AM
Is there a function that will return info of the cursor location? cbre_bryork Excel Worksheet Functions 3 May 15th 05 02:02 AM


All times are GMT +1. The time now is 08:23 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"