TimeSeriesImport          package:fCalendar          R Documentation

_I_m_p_o_r_t _M_a_r_k_e_t _D_a_t_a _f_r_o_m _t_h_e _I_n_t_e_r_n_e_t

_D_e_s_c_r_i_p_t_i_o_n:

     A collection and description of functions to import  financial and
     economic market data from the Internet. Download functions are
     available for economic and financial market data from
     Economagic's, from  Yahoo's, from the Federal Reserve's, and from
     the the forecasts.org Internet sites. 

     The functions are:

       'economagicImport'  Economic series from Economagic's Web site,
       'yahooImport'       daily stock market data from Yahoo's Web site,
       'yahooSeries'       easy to use download from Yahoo,
       'keystatsImport'    key statistics from Yahoo's Web site,
       'fredImport'        time series from St. Louis FRED Web site,
       'forecastsImport'   monthly data from the Financial Forecast Center.

_U_s_a_g_e:

     economagicImport(query, file = "tempfile", 
         source = "http://www.economagic.com/em-cgi/data.exe/",  
         frequency = c("quarterly", "monthly", "daily"), save = FALSE, 
         colname = "VALUE", try = TRUE)  
     yahooImport(query, file = "tempfile", 
         source = "http://chart.yahoo.com/table.csv?", save = FALSE,
         sep = ";", swap = 20, try = TRUE)
     keystatsImport(query, file = "tempfile", 
         source = "http://finance.yahoo.com/q/ks?s=", save = FALSE, 
         try = TRUE) 
     fredImport(query, file = "tempfile", 
         source = "http://research.stlouisfed.org/fred2/series/", 
         frequency = "daily", save = FALSE, sep = ";", try = TRUE) 
     forecastsImport(query, file = "tempfile", 
         source = "http://www.forecasts.org/data/data/", save = FALSE, 
         try = TRUE) 
         
     yahooSeries(symbols = c("^DJI", "IBM"), from = NULL, to = NULL, 
         nDaysBack = 365, quote = c("Open", "High", "Low", "Close", "Volume"), 
         aggregation = c("d", "w", "m"), returnClass = c("timeSeries", "ts", 
         "matrix", "data.frame"), getReturns = FALSE, ...)
             
     show.fWEBDATA(object)
     ## S3 method for class 'keystats':
     print(x, ...)

_A_r_g_u_m_e_n_t_s:

aggregation: [yahooSeries] - 
           a character string denoting the aggregation level of the 
          downloaded data records, 'd' for daily, 'w' for weekly and
          'm' for monthly data records. 

 colname: [economagicImport] - 
           a character string which defines the name of the value
          column. By default "VALUE". 

    file: a character string with filename, usually having extension
          ".csv", where to save the downloaded data. 

frequency: a character string, one of "quarterly", "monthly", or
          "daily", defining the frequency of the data records. 

from, to: [yahooSeries] - 
           an ISO-8601 formatted character string of the starting (end)
           date, e.g. "2005-01-01". 

getReturns: [yahooSeries] - 
           a logical flag. Should return values be computed using the 
          function 'returnSeries'? 

nDaysBack: [yahooSeries] - 
           an integer giving the length of the download period in
          number  of days starting n days back from today. Only in use
          if  'from' and 'to' are not specified. 

  object: an S4 object of class '"fWEBDATA"'. 

   query: a character string, denoting the location of the data at the 
          web site. 

    save: a logical value, if set to TRUE the downloaded data file will
           be stored under the path and file name specified by the
          string 'file'. By default FALSE. 

   quote: [yahooSeries] - 
           a character value or vector of strings giving the column
          name(s)  of those instruments to be extracted from the
          download.  

returnClass: [yahooSeries] - 
           a character string naming the class of the object to be 
          returned. By default the function 'yahooSeries' returns  a
          '"timeSeries"' object, alternatives are: '"ts"',  '"matrix"',
          or '"data.frame"'. 

     sep: a character value, defining the field separator for the 
          destination file which saves the downloaded data records. By
          default a semicolon. 

  source: a character string with the download URL. 

 symbols: [yahooSeries] - 
           a character string value or vector, the Yahoo symbol
          name(s). 

    swap: [yahooImport] - 
           an integer value which determines when we swap from the 19th
          to 20th century, by default 20, i.e. we swap 1920. This is
          necessary since Yahoo does not list the century in its dates,
          e.g. "15-Aug-02". 

     try: a logical value, if set to TRUE the Internet access will be
          checked. 

       x: [print.keystats] - 
           an object of class 'keystats' as returned by the function
          'keystatsImport'. 

     ...: optional arguments to be passed. 

_D_e_t_a_i_l_s:

     *Import data from www.economagic.com* 

      Frequently requested data files from Economagic for the US
     economy include:

       '[query]'                    Description:
                                    
       'var/leading-ind-long'       Index of Leading Economic Indicators
       'beana/t102l01'              Real Gross Domestic Product
       'fedstl/trsp500'             SP 500 Total Return
       'fedstl/gnp'                 Gross National Product in Current Dollars
       'var/cpiu-long'              Consumer Price Index - All Urban Consumers
       'feddal/ru'                  Unemployment Rate
       'fedstl/indpro'              Total Industrial Production Index
       'fedstl/exjpus+2'            FX Rate: Japanese Yen to one US Dollar
       'fedstl/fedfunds+2'          Federal Funds Rate
       'fedstl/mdiscrt+2'           Discount Rate
       'fedbog/tcm30y+2'            30-Year Treasury Constant Maturity Rate
       'fedstl/mprime+2'            Bank Prime Loan Rate
       'fedstl/tb3ms+2'             3-Month Treasury Bills - Secondary Market
       'fedstl/tb6ms+2'             6-Month Treasury Bills - Secondary Market
       'fedbog/cm+2'                30 Year Federal Home Loan Mortgages
       'var/west-texas-crude-long'  Price of West Texas Intermediate Crude

     *Import data from chart.yahoo.com:* 

      The query string is given as  

      's=SYMBOL&a=DD&b=MM&c=CCYY&g=d&q=q&z=SYMBOL&x=.csv'  

      where 'SYMBOL' has to replaced by the symbol name of the 
     instrument, and 'DD', 'MM', and 'CCYY' by the  day, month-1 and
     century/year when the time series should start.

     Here are some examples of symbols:

       '[query]'  Description:
                  
       '^DJI'     Dow Jones 30 Industrial Averages
       '^NYA'     New York Stock Exchange Composite
       '^NDX'     Nasdaq 100 Index
       '^IXIC'    Nasdaq Composite Index
       '^TYX'     US 30Y Treasury Bond Index
       'IBM'      BM DJIA Stock
       'KO'       Coca-Cola DJIA Stock

     The meaning of the tokens in the query string are the following:

       Token  Description
              
       's'    Selected Ticker-Symbol
       'a'    First Quote starts with Month (mm)
       'b'    First Quote starts with Day (dd)
       'c'    First Quote starts with Year (ccyy)
       'd'    Last Quote ends with Month (mm)
       'e'    Last Quote ends with Day (dd)
       'f'    Last Quote ends with Year (ccyy)
       'z'    Selected Ticker-Symbol

     Note, that month tokens range between 0 and 11 for January to 
     December! 

_V_a_l_u_e:

     The functions 'economagicImport', 'fredImport', and 'yahooImport'
     return an S4 object of class 'fWEBDATA'  with the following slots:

   @call: the function call.   

   @data: the data as downloaded formatted as a data.frame. 

  @param: a character vector whose elements contain the values of
          selected  parameters of the argument list. 

  @title: a character string with the name of the download. This can be
           overwritten specifying a user defined input argument. 

@description: a character string with an optional user defined
          description.  By default just the current date when the test
          was applied will be returned.


     The function 'yahooSeries' returns by default an S4 object of 
     class  'timeSeries' or alternatively an object specified by the
     function argument 'returnClass'.

_N_o_t_e:

     *Internet Download:* 

      Note, that if the service provider changes the data file format 
     it may become necessary to modify and update the functions.  
      The R package 'tseries' from Adrian Trapletti offers an 
     alternative function to download stock market data and indexes 
     from Yahoo's Internet site.

     *Functions added to Splus Version:* 

      These functions are only used when running Rmetrics under SPlus. 
     Note, that only part of the functionality is supported which is 
     required running these R functions for Rmetrics under Splus.

_A_u_t_h_o_r(_s):

     Diethelm Wuertz for the Rmetrics R-port.

_E_x_a_m_p_l_e_s:

     ## Not run: 
     ## SOURCE("fcALENDAR.6A-TimeSeriesImport")

     ## economagicImport -
        USDEUR = economagicImport(query = "fedny/day-fxus2eu", 
          frequency = "daily", colname = "USDEUR")
        # Print Data Slot if Internet Download was Successful:
        if (!is.null(USDEUR)) print(USDEUR@data[1:20, ])

     ## economagicImport -
        USFEDFUNDS = economagicImport(query = "fedstl/fedfunds+2", 
          frequency = "monthly", colname = "USFEDFUNDS")
        if (!is.null(USFEDFUNDS)) print(USFEDFUNDS@data[1:20, ])
        
     ## economagicImport -
        USGNP = economagicImport(query = "fedstl/gnp", 
          frequency = "quarterly", colname = "USGNP")
        if(!is.null(USGNP)) print(USGNP@data[1:20, ])  
          
     ## yahooImport -
        # [test 19/20 century change 01-12-1999 -- 31-01-2000]
        query = "s=IBM&a=11&b=1&c=1999&d=0&q=31&f=2000&z=IBM&x=.csv"
        IBM = yahooImport(query)  
        if (!is.null(IBM)) print(IBM@data[1:20, ]) 
        
     ## fredImport -
        DPRIME = fredImport("DPRIME")
        if (!is.null(DPRIME)) print(DPRIME@data[1:20, ])       
     ## End(Not run)

