Dynamic Table and cross section Table manipulation
이전 댓글 표시
Dear Experts,
I have an expanding table, tableA as shown
tableA
stockID portfolio0 return date
Apple 0.3 0.1 199901
IBM 0.2 -0.3 199901
In the next period, expanding tableA increases a column as shown
tableA
stockID portfolio0 portfolio1 return date
Apple 0.5 0.1 0.6 199902
IBM 0 -0.2 0.4 199902
TableA will keep expanding a column at a time until it has 10 columns.
tableA
stockID portfolio0 portfolio1 ... portfolio9 return date
Apple 0.5 0.1 ... 0.6 0.6 199910
....
Snap 0.2 -0.2 ... -0.4 -0.2 199910
Now we need to calculate total returns for each portfolio in a new tableB.
It is calculated by
sum(tableA.portfolio0 .* tableA.return)
From the first tableA, tableB becomes
tableB
portfolio0 date
-0.3 199901
According to second round of tableA, the total returns are
portfolio0 = sum(tableA.portfolio0 .* tableA.return)
portfolio1 = sum(tableA.portfolio1 .* tableA.return)
table B becomes
tableB
portfolio0 portfolio1 date
-0.3 0 199901
0.3 -0.2 199902
This whole process repeats until tableA reaches 10 columns with portfolio0- portfolio9 and it will remain as 10 columns while the values for the portfolioX, return, date changes. TableB will eventually look like
tableB
portfolio0 portfolio1 portfolio2 ... portfolio9 date
-0.3 0 0 0 199901
0.3 -0.2 0 0 199902
XX XX XX 0 199903
....
XX XX XX XX 199910
....
XX XX XX XX 201703
Any ideas?
Thank you so much LL
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Portfolio Optimization and Asset Allocation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!