LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default use of worksheet function average in VBA

You can use the Application.Index

set the 2 or 3 argument to zero depending on what you want to slice. See
Excel help on the index function for an explanation.

--
Regards,
Tom Ogilvy

"Paul" wrote in message
om...
Hi,

I am trying to use the AVERAGE worksheetfunction in VBA, but don't
know how to ... the code below calculates a binomial stock price tree
for 10 time periods ... I now want to calculate the maximum stock
price across all states during a specific time period ... for example
for time period 10, I have 11 states. the maximum should now be
calculated for time period 10 across the 11 states (the problem is
therefore one of calculating the average of one dimension of a
multidimension array) ...

thanks in advance,

thei

Code:

Sub AverageStockPrice()

'input parameters
sig = 0.4
T = 1
N = 10
r = 0.05
S = 100

Dim St() As Double
Dim AvSt

'initialise parameters
dt = T / N
u = Exp(sig * Sqr(dt))
d = 1 / u
pu = (Exp(dt * r) - d) / (u - d)
pd = 1 - pu
edx = u / d
disc = Exp(-r * dt)

ReDim St(N, 0 To N)

St(0, 0) = S

'initialise asset prices
ReDim St(N, 0 To N)
St(0, 0) = S

For Index = 1 To N Step 1
St(Index, 0) = St(0, 0) * d ^ (Index - 0)
For State = 1 To Index
St(Index, State) = St(Index, State - 1) * edx
Next State
Next Index

'calculate average stock price across states at each time index

For Index = N To 0 Step -1
AvSt = Application.Average
Next Index

End Sub



 
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
Is it possible to use address function in average function [email protected] Excel Discussion (Misc queries) 8 December 18th 07 12:52 AM
Cumulative Average on a worksheet Daryl New Users to Excel 1 April 5th 06 12:12 AM
Error Handling #N/A with AVERAGE Function - Average of values in Row Sam via OfficeKB.com Excel Worksheet Functions 13 July 31st 05 03:59 PM
I want to use the MATCH function with the AVERAGE function but I . Miguel Excel Worksheet Functions 2 April 23rd 05 05:29 PM
How do I nesting subtotal function within average function in Exc Amy Yeh Excel Worksheet Functions 4 January 19th 05 06:23 PM


All times are GMT +1. The time now is 11:38 PM.

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

About Us

"It's about Microsoft Excel"