Code covered by the BSD License  

Highlights from
dowload FRED data and US Constant Maturity Treasury Rates

dowload FRED data and US Constant Maturity Treasury Rates

by

 

dowload FRED data and US Constant Maturity Treasury Rates

data_FRBH15=func_download_USCMT_DATA
function data_FRBH15=func_download_USCMT_DATA

% OUTPUT: dataset containing the FRBH15 data
%
% FUNCTION CONTENT 
%   Step 1: connect to the US FED address 
%       http://www.federalreserve.gov/datadownload/Output.aspx?rel=H15&series=bf17364827e38702b42a58cf8eaa3f78&lastObs=&from=&to=&filetype=csv&label=include&layout=seriescolumn&type=package 
%   Step 2: download  data in a temporary file which is processed in 2 succesive steps  
%   Step 3: read the processed file as a dataset 
%
%  Please note that the downloaded data is part of the Federal Reserve Board statistical
%  releases. The releases are subject to the website and copyright policies to of 
%  the Board of Governors of the Federal Reserve System
%
%
% Copyright (c) 2013, Oana Alexandra Damian. All rights reserved.
% 
% Redistribution and use in source or in binary forms, with or without modification, are permitted provided that the redistributions of source 
% code or of binary form must retain the above copyright notice and the following disclaimer in the source code and in documentation and/or 
% other materials provided with the distribution.
%
% DISCLAIMER
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" % AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
% POSSIBILITY OF SUCH DAMAGE.


fprintf('\n\n\n=========================================')       
fprintf('\n FRBH15 extraction started')  

FRBH15_file_address='http://www.federalreserve.gov/datadownload/Output.aspx?rel=H15&series=bf17364827e38702b42a58cf8eaa3f78&lastObs=&from=&to=&filetype=csv&label=include&layout=seriescolumn&type=package';
FRBH15_file_temporary='FRBH15_raw.txt';
[filestr,status] = urlwrite(FRBH15_file_address,FRBH15_file_temporary);
FID=fopen(FRBH15_file_temporary);
DATA = textscan(FID, '%s', 'delimiter', '\n', 'whitespace', '','TreatAsEmpty','ND');
DATA = DATA{1};
fclose all;
DATA=DATA(6:end);
DATA{1}='Date,USCMT_1m,USCMT_3m,USCMT_6m,USCMT_1y,USCMT_2y,USCMT_3y,USCMT_5y,USCMT_7y,USCMT_10y,USCMT_20y,USCMT_30y';



FID=fopen('FRBH15.txt','w') ;
 for idx_frb=1:numel(DATA)
     DATA{idx_frb}=strrep(DATA{idx_frb},'ND','');
     fprintf(FID,'%s',DATA{idx_frb});
     fprintf(FID,'\n');
 end
 fclose all;
 data_FRBH15=dataset('file','FRBH15.txt','delimiter',',');
 POZ_VALID=sum(isnan(double(data_FRBH15(:,2:end))),2)<11;
 data_FRBH15=data_FRBH15(POZ_VALID,:);
 data_FRBH15.Date=datenum(data_FRBH15.Date,'yyyy-mm-dd');


fprintf('\n FRBH15 extraction finished') 
fprintf('\n=========================================\n\n')       

Contact us