How to sequentially process the columns of a table?

2 Ansichten (letzte 30 Tage)
Cheerful
Cheerful am 8 Mär. 2017
Kommentiert: Cheerful am 10 Mär. 2017
Dear Experts,
I have a table, tableA as shown below.
tableA
portfolio0 portfolio1 portfolio2 ... portfolio9 returns date
XX XX XX XX XX 199901
XX XX XX XX XX 199901
XX XX XX XX XX 199901
....
XX XX XX XX XX 199901
I can compute the total return for column 1 as
portfolio0 = tableB.portfolio0 .* tableB.returns.
However, when i do the following, I have an error. When I use
tableB.strcat('portfolio', 'i') = tableA.strcat('portfolio', 'i') .* tableA.returns where i = 0 to 9.
How do I process portfolio0 to portfolio9 together and store it like tableB as shown below.
tableB
portfolio0 portfolio1 ... portfolio2 date
XXX XXX XXX 199901.
In actual case, I will have tableA for different date and the processing are shown above. Hence the final tableB will look like
tableB
portfolio0 portfolio1 ... portfolio2 date
XXX XXX XXX 199901
XXX XXX XXX 199902
....
XXX XXX XXX 199912
Thank you so much for your advice LL

Antworten (1)

Walter Roberson
Walter Roberson am 8 Mär. 2017
https://www.mathworks.com/help/matlab/ref/varfun.html
  1 Kommentar
Cheerful
Cheerful am 10 Mär. 2017
It is a light at the end of the tunnel!
func = @(x) sum(x.*temp.ret);
temp1 = varfun(func, temp, 'InputVariables' , {'portfolio0', 'portfolio1'});
temp1.date = 199901;
temp1.Properties.VariableNames({'Fun_portfolio0' 'Fun_portfolio1'}) = {'portfolio0' 'portfolio1'};
Since I need to combine each table which have varying number of columns into one,
tempT= outerjoin(tempT, temp1, 'Keys', 'date');
I end up alot of columns that need to rename. Is there a simpler way to look like the below?
portfolio0 portfolio1 portfolio2 ... date
0.1 0 0 ... 199901
0.3 0.4 0 ... 199902
thanks alot

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Portfolio Optimization and Asset Allocation finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by