Multiple Column Sorting and Calculation of Returns
1 view (last 30 days)
Show older comments
Hi,
I am fairly new in Matlab and I have a question on how to sort a table.
I have a table of stocks for many years with returns, skewness and volatility, so it looks like this:
Stock 1 1989 Return Skewness Volatility
Stock 1 1990 Return Skewness Volatility
Stock 2 1989 Return Skewness Volatility
Stock 2 1990 Return Skewness Volatility
Stock 2 1991 Return Skewness Volatility
etc. (some stocks have more yearly observations than others).
I want to double sort all stocks on a yearly basis based on both skewness and volatility on 5 quantiles each. That means I want to end up with 25 portfolios, and then use Column 3 to calculate the return of each portfolio.
I don't really know what to do. Your help is great appreciated. Thanks.
0 Comments
Answers (1)
KSSV
on 13 Aug 2018
fid = fopen('data.txt','r') ;
S = textscan(fid,'%s %f %f %f %f %f') ;
fclose(fid) ;
stock = S{2} ;
year = S{3} ;
return = S{4} ;
skewness = S{5} ;
volatility = S{6} ;
You can sort them the way you want now.
3 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!