spoofhopper
New Member
Hi - could someone please repost the workbook so I can try to understand Haseeb's solution?
the code for column H (Security XIRR) is
=XIRR(CHOOSE({1,2},OFFSET(E$2,MATCH(A2,P[Sec],0)-1,0,COUNTIF(P[Sec],A2)),OFFSET(G$2,MATCH(A2,P[Sec],0)-1,0,COUNTIF(P[Sec],A2))),(CHOOSE({1,2},OFFSET(D$2,MATCH(A2,P[Sec],0)-1,0,COUNTIF(P[Sec],A2)),OFFSET(F$2,MATCH(A2,P[Sec],0)-1,0,COUNTIF(P[Sec],A2)))))
Some extra tweaks can be made to the formula as below to make it:
- much faster to calculate (by looking up previous results in the same column)
- normal entry formula (without CSE)
=IFERROR(VLOOKUP(P[@Sec],P[#Headers]:H1,COUNTA(P[#Headers]:H$1),0),XIRR(INDEX(P,N(IF(1,MODE.MULT(IF(N(INDEX(P[Sec]=A2,)),MMULT(ROW(P)-ROW(P[#Headers]),{1,1}))))),N(IF(1,MATCH({"OV","IV"},P[#Headers],0)))),INDEX(P,N(IF(1,MODE.MULT(IF(N(INDEX(P[Sec]=A2,)),MMULT(ROW(P)-ROW(P[#Headers]),{1,1}))))),N(IF(1,MATCH({"OD","ID"},P[#Headers],0))))))
... or similar to HaseebA's approach: (also non-CSE and much simpler!)
=IFERROR(VLOOKUP(A2,A$1:H1,COLUMNS(A$1:H1),0),XIRR(CHOOSE(3+MMULT(-(A2:A$1207=A2),{2,1}),E2:E$1207,G2:G$1207,),CHOOSE(3+MMULT(-(A2:A$1207=A2),{2,1}),D2:D$1207,F2:F$1207,)))
Use CHOOSE like,
=XIRR(CHOOSE({1,2},L2:L27,N2:N27),CHOOSE({1,2},B2:B27,M2:M27),15%)
I got the answer 18.1%