I am using the following packages:
library("quantmod")
library("PerformanceAnalytics")
library("termstrc")
Data:
AAA <- matrix(sample(30), ncol = 10)
BBB <- matrix(sample(30), ncol = 10)
CCC <- matrix(sample(30), ncol = 10)
with
print(AAA)
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]   28   18   16   10   20   21   23   27    5     6
[2,]   19   22   24   13   17   14   15   30    4     8
[3,]    1   25   11    2   29    9    3    7   12    26
> print(BBB)
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]   26   22   24   21   23   25   11   17    8    13
[2,]   14   18   16   28   12    1   10    6   20    15
[3,]    9    4   30    7    5   27    2    3   19    29
> print(CCC)
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]    6   29    9   24   26   10   12   21    5    22
[2,]   14    4   28   19    8   23   20   27   16     1
[3,]    7   17   13   18   30    2    3   15   11    25
Now I have the following problem: There are 3 matrices (AAA, BBB and CCC), these matrices have all the same nummer of observations (3 obs. and 10 var.). I calculated the min- & max-position for each row or observation in "AAA" (min/max for time t).
Calculated the following:
maxAAA_pos <- max.col(AAA)
minAAA_pos <- max.col(-AAA)
Result:
> print(maxAAA_pos)
[1] 1 8 5
> print(minAAA_pos)
[1] 9 9 1
The position of these min/max variables are telling me now which variable I have to take from the matrices BBB and CCC to calculate the following (example for the 1 observation):
Ft = variable from BBB at time t
St+1 = variable from CCC at time t+1
Result_max = (Ft / St+1) - 1
Result_min = 1 - (Ft / St+1)
My problem now is to select "Ft" and "St+1", which are given from the positions min/max variables from AAA and in the vector maxAAA_pos and minAAA_pos at time t.
This means the calculation should look like this for t=1 or the first observation:
Result_max = (26 / 14) - 1
Result_min = 1 - (8 / 16)
Thanks in advanced!
