Portfolio optimization in markovitz
3 ビュー (過去 30 日間)
古いコメントを表示
I have problem in this code,
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
error messege: Undefined function 'diff' for input arguments of type 'cell'.
Error in tick2ret (line 92) RetSeries = diff(TickSeries)./TickSeries(1:end-1,:);
7 件のコメント
Kevin Chng
2018 年 10 月 2 日
I don't have any error in running your code.
However, your attached excel file is .csv format.
Hence recommend you change your code from
T = readtable('data (2).xlsx') % Name of your data
to
T = readtable('data (2).csv') % Name of your data
回答 (1 件)
Kevin Chng
2018 年 10 月 3 日
Hi Luan Vardari,
In your original question, i think you are able to resolve it by changing
T = readtable('data (2).xlsx') % Name of your data
to
T = readtable('data (2).csv') % Name of your data
In your comment, you attached another script which is using CVX.
How to make your script work?
2) Unzip the folder in your working folder/current folder : Click on Extract here. The working folder is the folder where has your markowitz_opt.m script
3) After unzip, open the folder. Open cvx_setup.m and cvx_startup.m in MATLAB, and run them. When you run them in MATLAB, your working folder is still the same folder which has your markowitz_opt.m script.
4) Now, open markowitz_opt.m and run them. Done!
if you have any doubt, you are welcome to ask here.
2 件のコメント
Kevin Chng
2018 年 10 月 3 日
Great to heard that.
Sorry that I'm not familiar with this. I have to understand what is the meaning of those symbols first.
n=25; %number of items
p_mean = randn(n,1);
temp = randn(n,n);
sig = temp'*temp;
r = floor(0.1*n);
alpha = 0.8;
r_min = 1;
Or you may post a new questions about this to seek help from the community.
^^
参考
カテゴリ
Help Center および File Exchange で Portfolio Optimization and Asset Allocation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!