Help: Matlab code to import stock price data from an excel file using the function input.
이전 댓글 표시
I have an excel file named Stocks.xlsx which contains the closing prices of 87 S&P 500 stocks for the period 31/12/2007-30/11/2017. I have to choose four of them (e.g. ‘AAPL’, ‘AMZN, ‘HPQ’ ,’IBM’) and insert the prices into a script file for the period 29/11/2013-30/11/2017 using the function input. Can anyone help me write the matlab code. Thanks in advance.
This is what i wrote, but i have not been very successful.
m1=input('Insert the first stock: '); % We insert the ticker of the first stock in ‘’
m2=input('Insert the second stock: '); % We insert the ticker of the second stock in ‘’
m3=input('Insert the third stock: '); % We insert the ticker of the third stock in ‘’
m4=input('Insert the fourth stock: '); % We insert the ticker of the fourth stock in ‘’
tickers={m1,m2,m3,m4};
for i=1:length(tickers)
prices{i}=xlsread('Stocks.xlsx','29112013','30112017',tickers{:,i});
end
for i=1:length(tickers)
p(:,i)=prices{1,i}.Close;
plow(:,i)=prices{1,i}.Low;
end
댓글 수: 1
Benjamin Kraus
2017년 12월 26일
I cannot edit your question, but your code needs to indented so that it is formatted as code. For the sake of others:
m1=input('Insert the first stock: ');
m2=input('Insert the second stock: ');
m3=input('Insert the third stock: ');
m4=input('Insert the fourth stock: ');
tickers={m1,m2,m3,m4};
for i=1:length(tickers)
prices{i}=xlsread('Stocks.xlsx','29112013','30112017',tickers{:,i});
end
for i=1:length(tickers)
p(:,i)=prices{1,i}.Close;
plow(:,i)=prices{1,i}.Low;
end
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!