multiplying elements of vector and matrix waves
Eduard Kas
I like to use Igor to calculate the risk of a portfolio of construction projects, taking into consideration that the combined variance of a portfolio of projects depends on the relative emphasis on each of the projects, the risk of the projects, and the correlation between the projects. In Igor I have defined the Weight (W) and Standard Deviation (SD) parameters as vectors and the correlation parameter as a 2D matrix. I am wondering how the calculations - involving the multiplication of elements from two different vectors with elements from a matrix - can be most conveniently approached.
To illustrate the essence of the calculations I include a simple example with just three projects, say projects A, B, and C. The code is worked out as follows:
Make Weight = {0.5,0.3,0.2}; Make Correlation = {{1.0,0.8,0.6},{0.8,1.0,0.4},{0.6,0.4,1.0}}; Make 'Stand. deviation' = {30,20,15}
Manually the variance of the combined projects can be calculated in the following way. The combined project variance =
0.5*0.5*1.0*30*30 (= first point of W * first point of W * intersection first row / first column matrix * first point of SD * first point of SD +
0.5*0.3*0.8*30*20 (= first point of W * second point of W * intersection second row / first column matrix * first point of SD * second point of SD) +
0.5*0.2*0.6*30*15 (= first point of W * third point of W * intersection third row / first column matrix * first point of SD * third point of SD) +
0.3*0.5*0.8*20*30 (same as second calculation) +
0.3*0.3*1.0*20*20 (= second point of W * second point of W * intersection second row / second column matrix * second point of SD * second point of SD) +
0.3*0.2*0.4*20*15 (= second point of W * third point of W * intersection third row / second column matrix * second point of SD * third point of SD) +
0.2*0.5*0.6*15*30 (same as third calculation) +
0.2*0.3*0.4*15*20 (same as sixth calculation) +
0.2*0.2*1.0*15*15 (= third point of W * third point of W * intersection third row / third column matrix * third point of SD * third point of SD)
Where: W = wave entitled Weight; SD = wave entitled Standard Deviation
Any help is highly welcome. I have the idea that the calculations can be made with Igor and that loops may be useful, especially in situations where the calculations relate to a large number of projects, but due to my relatively short experience with Igor, I have not a rounded idea about how to proceed.
Eduard
You need to take a look at MatrixOP. It supports both element by element multiplication as well as matrix multiplication. To find out more, execute on the command line:
DisplayHelpTopic "MatrixOP"
If you have any trouble implementing any equation feel free to send me their concise mathematical expressions (not the lengthy sample that you typed above) and I will help you with the IGOR code.
A.G.
WaveMetrics, Inc.
ag@wavemetrics.com
September 18, 2009 at 05:06 pm - Permalink