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!