Note: Edited to add row & column references to make table easier to read
Edited to remove ambiguity about manual calculations
Hello Experts,
I'm trying to use Lookup and Reference functions to dynamically define the ranges used by various statistical calculations like AVERAGE, STDEV, CORREL.
The approach i have in mind is to use a a user defined functions for each calculation, using SecurityA, SecurityB, #daysHistory as required parameters.
My workbook has two sheets:
PairList! (note: this sheet might have up to 700 rows)
user input--------------------------------- Calculated values-------------------------------------
SecurityA SecurityB #DaysHistory fnRatioAvg fnRatioStdDev fnCorrelation
1 HK 20 HK 5 HELP! i'll do myself later i'll do myself later
4 HK 20 HK 5 HELP! i'll do myself later i'll do myself later
...
...
Price! (note: this sheet might have up to 65000 rows and 700 securities)
I have currently sorted it ASCENDING, but could change to DESCENDING if the lookups are more efficient.
A B C
1 SecurityID Date Price
2 1 HK Equity 8/10/2006 84.85
3 1 HK Equity 8/11/2006 84.9
4 1 HK Equity 8/14/2006 85.25
5 1 HK Equity 8/15/2006 85.6
6 1 HK Equity 8/16/2006 86.85
7 1 HK Equity 8/17/2006 87.85
8 1 HK Equity 8/18/2006 88.25
9 1 HK Equity 8/21/2006 87.05
10 20 HK Equity 8/10/2006 13.48
11 20 HK Equity 8/11/2006 13.62
12 20 HK Equity 8/14/2006 13.52
13 20 HK Equity 8/15/2006 13.5
14 20 HK Equity 8/16/2006 13.74
15 20 HK Equity 8/17/2006 13.62
16 20 HK Equity 8/18/2006 13.6
17 20 HK Equity 8/21/2006 13.5
18 4 HK Equity 8/10/2006 28.8
19 4 HK Equity 8/11/2006 28.7
20 4 HK Equity 8/14/2006 28.55
21 4 HK Equity 8/15/2006 28.5
22 4 HK Equity 8/16/2006 28.8
23 4 HK Equity 8/17/2006 28.8
24 4 HK Equity 8/18/2006 28.65
25 4 HK Equity 8/21/2006 28.35
...
...
Assuming data for both Prices! and PairList start in cell A1 (with headers), manually the calculations for the first pair (1 HK / 20 HK) would be
={AVERAGE(Prices!C7:C9/Prices!C15:C17)}
={STDEV(Prices!C7:C9/Prices!C15:C17)}
={CORREL(LN(Prices!C7:C9/Prices!C6:C8),LN(Prices!C15:C17/Prices!C14:C16))}
The result table looks like this:
SecurityA SecurityB #DaysHistory fnRatioAverage fnRatioStdDev fnCorrelation
1 HK Equity 20 HK Equity 3 6.4624 0.0230 7%
4 HK Equity 20 HK Equity 3 2.1071 0.0073 -18%
The problem I have is defining the ranges dynamically with reference to SecurityA, SecurityB, #daysHistory in the pair table.
I'm experimenting with various Lookup and Reference functions (eg VLOOKUP, COLUMN, ROW, INDEX, INDIRECT, OFFSET, MATCH).
If someone could help me with fnRatioAverage, I should be able to do fnRatiopStdDev, fnCorrelation on my own.
Any suggestions much appreciated. Thanks.
-Tom