Clear Filters
Clear Filters

Matlab Portfio Optimization efficent frontierr problem

1 view (last 30 days)
I have problem with data read, i dont know why, can help someone?
Error: Error using Portfolio/estimateAssetMoments (line 100) AssetReturns must be a matrix with either finite or NaN values.
Error in d (line 5) p = estimateAssetMoments(p, dailyReturn);
Below have the code and in attach can find data.
if true
T = readtable('data (2).xlsx') % Name of your data
symbol = T.Properties.VariableNames(3:end)';
dailyReturn = tick2ret(T{:,3:end});
p = Portfolio('AssetList',symbol,'RiskFreeRate',0.01/252);
p = estimateAssetMoments(p, dailyReturn);
p = setDefaultConstraints(p);
w1 = estimateMaxSharpeRatio(p)
[risk1, ret1] = estimatePortMoments(p, w1)
f = figure;
tabgp = uitabgroup(f); % Define tab group
tab1 = uitab(tabgp,'Title','Efficient Frontier Plot'); % Create tab
ax = axes('Parent', tab1);
% Extract asset moments from portfolio and store in m and cov
[m, cov] = getAssetMoments(p);
scatter(ax,sqrt(diag(cov)), m,'oc','filled'); % Plot mean and s.d.
xlabel('Risk')
ylabel('Expected Return')
text(sqrt(diag(cov))+0.0003,m,symbol,'FontSize',7); % Label ticker names
hold on;
[risk2, ret2] = plotFrontier(p,10);
plot(risk1,ret1,'p','markers',15,'MarkerEdgeColor','k',...
'MarkerFaceColor','y');
hold off
tab2 = uitab(tabgp,'Title','Optimal Portfolio Weight'); % Create tab % Column names and column format columnname = {'Ticker','Weight (%)'}; columnformat = {'char','numeric'}; % Define the data as a cell array data = table2cell(table(symbol(w1>0),w1(w1>0)*100)); % Create the uitable uit = uitable(tab2, 'Data', data,... 'ColumnName', columnname,... 'ColumnFormat', columnformat,... 'RowName',[]); % Set width and height uit.Position(3) = 450; % Widght uit.Position(4) = 350; % Height end

Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!