Question of Creating Function
Show older comments
Hi everyone,
I am a student from Education field and wish to self-teach myself the matlab, while studying through the handouts from my friends, I found an exercise I have difficulties to solve since this will be the first exercise I will do. Please help me out.
The exercise states as follow:
-------------------------------------------------------------------------------------------------------------------------------------
Code the following in MATLAB
The Yahoo Finance API can be used to returns stock price data for a given symbol. In this example, YHOO daily price from 4/13/2009 to 1/28/2010 is requested. http://ichart.finance.yahoo.com/table.csv?s=YHOO&d=0&e=28&f=2010&g=d&a=3&b=13&c=2009&ignore=.csv
The details of the parameters are as follows:
s Ticker symbol (YHOO in the example)
a The "from month"• - 1
b The "from day"• (two digits)
c The "from year"•
d The "to month"• - 1
e The "to day"• (two digits)
f The "to year"•
g d for day, m for month, y for yearly
Write a function that reads an Excel file for a number of stock symbols, then for each symbol the function
- sends requests to Yahoo Finance API repeatedly, retrieves the response and stores the response in a variable
- gets the Adjusted Closing Price column
- stores the Adjusted Closing Price as a column (without the header)in the output variable
The function takes the API parameters above as the input variables (except “s”). For N symbols, there should be N columns in the output variable.
Write sample code that calls the function above, return data into a variable, save the data to an Excel file.
Hint: You can use MATLAB function urlread() to read the response and store the result in a variable as follows:
x=urlread('http://ichart.finance.yahoo.com/table.csv?s=YHOO&d=0&e=28&f=2010&g=d&a= 3&b=13&c=2009&ignore=.csv')
To split rows, use this syntax
data=strsplit(x, '\n');
For each row, in order to split it into multiple columns
arow=strsplit(sprintf('%s',row{:}),',')
in which the variable “row” is an element in the cell array “data”. “arrow” is a cell array
------------------------------------------------------------------------------------------------
Thank you!
3 Comments
Jan
on 24 Jan 2016
Please explain your difficulties with any details. Otherwise it is hard to guess how we can help you.
Edward L.
on 24 Jan 2016
Edited: Walter Roberson
on 25 Jan 2016
Answers (2)
the cyclist
on 25 Jan 2016
0 votes
This seems like a pretty challenging exercise for a brand-new MATLAB student. Could I suggest you try something simpler first, such as the MATLAB Academy introductory tutorial?
1 Comment
Edward L.
on 25 Jan 2016
Walter Roberson
on 25 Jan 2016
0 votes
The first thing the exercise wants you to do is read an excel file to get a list of stock symbols. Then it wants you to go through each stock symbol that you just read in, and request data from Yahoo Finance for that stock symbol. For each stock symbol, out of the data that is retrieved from Yahoo, extract the Adjusted Closing Price column, and add that closing price as a new column on an overall variable you are building up. At the end, the overall variable should have one column of closing prices for each stock symbol.
Categories
Find more on Web Services 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!