0% found this document useful (0 votes)
26 views

%%% Input Data Closed Price

This document contains code for analyzing stock market data and optimizing a portfolio of stocks. It reads in stock price data from a file, calculates the rate of return for each stock, and takes the average. It initializes equal starting weights for each stock. Constraint functions are defined for the objective function and constraints. The fminimax function is then used to optimize the portfolio weights to maximize return while satisfying the constraints.

Uploaded by

Evan Susandi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

%%% Input Data Closed Price

This document contains code for analyzing stock market data and optimizing a portfolio of stocks. It reads in stock price data from a file, calculates the rate of return for each stock, and takes the average. It initializes equal starting weights for each stock. Constraint functions are defined for the objective function and constraints. The fminimax function is then used to optimize the portfolio weights to maximize return while satisfying the constraints.

Uploaded by

Evan Susandi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

%%% INPUT DATA CLOSED PRICE

[FileName,PathName]=uigetfile('*.xls;*.xlsx;*.csv','Insert Data
Stock'); %--Calling data stock
PathFile=[PathName,FileName]; %--PathFile data stock
[Data,DataTxt,RawData]=xlsread(PathFile); %--Reading excel format
from PathFile
[RowData,ColData]=size(Data) %--Measuring size matrix Data

%%% HITUNG RATE OF RETURN
for i=1:RowData-1
for j=1:ColData
Return(i,j)=(Data(i,j)-Data(i+1,j))/Data(i+1,j);
end
end

%%% HITUNG AVERAGE RETURN
AverageReturn=mean(Return)
%%% INISIALISASI BOBOT SAHAM
InitialWeight=(1/ColData)
w0=-[ones(ColData,1)*(InitialWeight)]'

%%% PENDEFINISIAN FUNGSI OBJEKTIF
Myfun1=@(w)(Return(:,1)*w(1)+Return(:,2)*w(2)+Return(:,3)*w(3)+Return
(:,4)*w(4)+Return(:,5)*w(5)+Return(:,6)*w(6)+Return(:,7)*w(7)+Return(
:,8)*w(8)+Return(:,9)*w(9)+Return(:,10)*w(10)+Return(:,11)*w(11))
41

%%% PENDEFINISIAN FUNGSI KENDALA
A=[-eye(ColData,ColData);eye(ColData,ColData);AverageReturn;Return]
G=-0.15 %DIASUMSIKAN
Mp=-(Return*w0')
b=[ones(ColData,1);-zeros(ColData,1);G;Mp]
Aeq=ones(1,ColData)
beq=-ones(1,1)
ub=zeros(ColData,1)
lb=-ones(ColData,1)

%%% OPTIMASI DENGAN FMINIMAX
opsi=optimset('LargeScale','Off','Display','On','GradConstr','On');
[x,fval,maxfval,exitflag]=fminimax(Myfun1,[w0],A,b,Aeq,beq,lb,ub)
format long
wOptim=-x

You might also like