Compare average monthly stock return data
2 次查看(过去 30 天)
显示 更早的评论
I would like to compare the average of the monthly stock return data listed in the 41x1 cell array 'DS_10T' with the data listed in the cell array 'DS_10B'.
As there are some NaNs within my data I hope that one can somehow not factor them into the averages.
I attached a short version of the relevant data as my original dataset would need significantly more memory, because it includes a lot more stocks.
Even tough every cell array contains 41 tables with data from different timeframes I would only need a comparison of the overall average monthly return out of all tables in 'DS_10T' versus the overall average monthly return of all tables of 'DS_10B' in the following format:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/566869/image.jpeg)
Where "Sell" depicts the average monthly returns of the 'DS_10B' array, "Buy" the average monthly returns of the 'DS_10T' array and Buy-Sell the difference between the two values. The numbers in parentheses can be ignored for now.
13 个评论
回答(1 个)
dpb
2021-3-29
See the optional 'nanflag' argument to mean--
M = mean(___,nanflag) specifies whether to include or omit NaN values from the calculation for any of the previous syntaxes. mean(A,'includenan') includes all NaN values in the calculation while mean(A,'omitnan') ignores them.
cellfun and an anonymous function should let you do this in one line, methinks. :)
I didn't explore the big table in depth, but I'd guess you could probably also do all the analyses directly with the table itself with the use of grouping variables and rowfun and perhaps varfun
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!