Portfolio optimization in markovitz
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Kevin Chng
le 2 Oct 2018
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
Réponses (1)
Kevin Chng
le 3 Oct 2018
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 commentaires
Kevin Chng
le 3 Oct 2018
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.
^^
Voir également
Catégories
En savoir plus sur Portfolio Optimization and Asset Allocation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!