Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel VBA -Custom function sumproduct

Hi there,

I'm trying to develop a custom VBA function to calculate logarithmi
growth rates. The function is pretty basic in nature; it consists o
multiplying a log vector of observations (ex. sales) by a vector o
time weights and dividing by the appropriate denominator.
Given N observations,
The vector of time weights equals (2*j - N -1), for j = 1 to N
The denominator equals (N^3-N)/6

Here's the code I came up with to automate this process

Function loggrowth(observations As Variant) As Variant
Dim Denominator As Variant
Dim j As Variant
Dim Item As Variant
Dim k As Variant
Dim N As Variant
N = Application.Count(observations)
Denominator = (N ^ 3 - N) / 6
loggrowth = 0
j = 0
For Each Item In observations
For j = 1 To N
If WorksheetFunction.Ln(Item) 0 Then _
loggrowth = loggrowth + WorksheetFunction.Ln(Item) * (2 * j - N - 1)
Next j
Next Item
loggrowth = loggrowth / Denominator
End Function


This doesn't seem to work for some reaso

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default Excel VBA -Custom function sumproduct

What does "This doesn't seem to work..." mean?

Irrespective of the answer to the above, you need to examine the
weights. For any value of j < (N+1)/2 the corresponding weight will be
<0!

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article , ppp698
says...
Hi there,

I'm trying to develop a custom VBA function to calculate logarithmic
growth rates. The function is pretty basic in nature; it consists of
multiplying a log vector of observations (ex. sales) by a vector of
time weights and dividing by the appropriate denominator.
Given N observations,
The vector of time weights equals (2*j - N -1), for j = 1 to N
The denominator equals (N^3-N)/6

Here's the code I came up with to automate this process

Function loggrowth(observations As Variant) As Variant
Dim Denominator As Variant
Dim j As Variant
Dim Item As Variant
Dim k As Variant
Dim N As Variant
N = Application.Count(observations)
Denominator = (N ^ 3 - N) / 6
loggrowth = 0
j = 0
For Each Item In observations
For j = 1 To N
If WorksheetFunction.Ln(Item) 0 Then _
loggrowth = loggrowth + WorksheetFunction.Ln(Item) * (2 * j - N - 1)
Next j
Next Item
loggrowth = loggrowth / Denominator
End Function


This doesn't seem to work for some reason


---
Message posted from http://www.ExcelForum.com/


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
#VALUE! error with custom excel vba function Martin J. Excel Discussion (Misc queries) 8 October 6th 08 01:58 PM
Excel custom function dialog [email protected] Excel Worksheet Functions 0 February 16th 06 01:08 AM
Excel 2003: custom function with dotnet Thomas Mutzl Excel Programming 2 December 11th 03 11:38 AM
Adding a custom function to the default excel function list DonutDel Excel Programming 3 November 21st 03 03:41 PM
Excel Custom Function with Select Case Heather[_7_] Excel Programming 14 November 6th 03 11:37 PM


All times are GMT +1. The time now is 08:33 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"