Multiple Column Sorting and Calculation of Returns

1 view (last 30 days)
DSK
DSK on 12 Aug 2018
Commented: DSK on 13 Aug 2018
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.

Answers (1)

KSSV
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
KSSV
KSSV on 13 Aug 2018
YOu need to work on specific column, which you want to sort.
DSK
DSK on 13 Aug 2018
Thank you for your help. I am still unsure how to proceed but I will see what I can do with your tips.
I appreciate your time and help. If you could provide any other tips or hints, I would be grateful.

Sign in to comment.

Categories

Find more on Word games in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!