在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
function stocks = hist_stock_data(start_date, end_date, varargin) % HIST_STOCK_DATA Obtain historical stock data % hist_stock_data(X,Y,'Ticker1','Ticker2',...) retrieves historical stock % data for the ticker symbols Ticker1, Ticker2, etc... between the dates % specified by X and Y. X and Y can either be strings in the format % ddmmyyyy or Matlab datenums, where X is the beginning date and Y is the % ending date. The program returns the stock data in a structure giving % the Date, Open, High, Low, Close, Volume, and Adjusted Close price % adjusted for dividends and splits. % % hist_stock_data(X,Y,'tickers.txt') retrieves historical stock data % using the ticker symbols found in the user-defined text file. Ticker % symbols must be separated by line feeds. % % hist_stock_data(X,Y,{'Ticker1' 'Ticker2'}) combined the ticker symbols % into a single cell array when calling hist_stock_data (sometimes easier % for calling the funtion with a cell array of ticker symbols). % % hist_stock_data(X,Y,'Ticker1','frequency',FREQ) retrieves historical % stock data using the frequency specified by FREQ, which must be either % 'd' for daily, 'wk' for weekly, or 'mo' for monthly. % % hist_stock_data(X,Y,'Ticker1','type','div') retrieves dividend data. If % anything but 'div' is specified then it will default to retrieving % historical prices. % % EXAMPLES % stocks = hist_stock_data('23012003','15042008','GOOG','C'); % Returns the structure array 'stocks' that holds historical % stock data for Google and CitiBank for dates from January % 23, 2003 to April 15, 2008. % % stocks = hist_stock_data('12101997','18092001','tickers.txt'); % Returns the structure arrary 'stocks' which holds historical % stock data for the ticker symbols listed in the text file % 'tickers.txt' for dates from October 12, 1997 to September 18, % 2001. The text file must be a column of ticker symbols % separated by new lines. % % stocks = hist_stock_data(now-10, now, {'GOOG' 'C'}); % Get stock data for approximately the last 10 days for the two % tickers specified in the cell array. % % stocks = hist_stock_data('12101997','18092001','C','frequency','w') % Returns historical stock data for Citibank using the date range % specified with a frequency of weeks. Possible values for % frequency are d (daily), wk (weekly), or mo (monthly). If not % specified, the default frequency is daily. % % stocks = hist_stock_data('12101997','18092001','C','type','div') % Returned historical dividend data for Citibank between Oct 12, % 1997 and September 18, 2001. % % DATA STRUCTURE % INPUT DATA STRUCTURE FORMAT % X (start date) ddmmyyyy String % Y (end date) ddmmyyyy String % Ticker NA String % ticker.txt NA Text file % FREQ NA String; 'd', 'wk', or 'mo' % TYPE NA String; 'div' % % OUTPUT FORMAT % All data is output in the structure 'stocks'. Each structure % element will contain the ticker name, then vectors consisting of % the organized data sorted by date, followed by the Open, High, Low, % Close, Volume, then Adjusted Close prices. % % DATA FEED % The historical stock data is obtained using Yahoo! Finance website. % By using Yahoo! Finance, you agree not to redistribute the % information found therein. Therefore, this program is for personal % use only, and any information that you obtain may not be % redistributed. % % NOTE % This program uses the Matlab command urlread in a very basic form. % If the program gives you an error and does not retrieve the stock % information, it is most likely because there is a problem with the % urlread command. You may have to tweak the code to let the program % connect to the internet and retrieve the data. 公司名称为对应公司的NYSE(New York Stock Exchange纽约证券交易所)的编号,比如McDonald: MCD, Google:GOOG 原作者:Josiah Renfree(2008) |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论