Help: Matlab code to import stock price data from an excel file using the function input.
Show older comments
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 Comment
Benjamin Kraus
on 26 Dec 2017
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
Accepted Answer
More Answers (0)
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!