Header menu logo FSharp.Data.Fred

BinderScriptNotebook

F# Data FRED

F# Data FRED is a library for FRED database data access based on FSharp.Data. Short for Federal Reserve Economic Data, FRED is an online database consisting of hundreds of thousands of economic data time series from scores of national, international, public, and private sources. This library uses the FRED API to access the data.

You can use FSharp.Data.Fred in dotnet interactive notebooks in Visual Studio Code or Jupyter, or in F# scripts (.fsx files), by referencing the package as follows:

#r "nuget: FSharp.Data.Fred, 0.2.1"   
#r "nuget: FSharp.Data" //Also load FSharp.Data
open FSharp.Data
open FSharp.Data.Fred
open System //Usefull to access DateTime

F# Data FRED

First in order to use the methods you'll need to create a value with type Fred. Fred receives an API key as a parameter (string). Get your FRED API key. Example: let apiKey = "insert API key here"

Now you can use the created value myFred to access all the methods in the FRED library.

FRED.Series Module Functions:

  1. Search.
  2. Info.
  3. Categories.
  4. Release.
  5. Tags.
  6. Observations.

F# Data FRED: Series.Search

A collection of economic data series that match the parameters.

The parameters are the following:

  1. searchText, required.
    The words to match against economic data series.
  2. searchType, optional. Default is SearchType.FullText.
    Determines the type of search to perform. One of the following: SearchType.FullText or SearchType.SeriesId.
    • SearchType.FullText searches series attributes title, units, frequency, and tags by parsing words into stems. This makes it possible for searches like 'Industry' to match series containing related words such as 'Industries'. Of course, you can search for multiple words like 'money' and 'stock'. Remember to url encode spaces (e.g. 'money%20stock').
    • SearchType.SeriesId performs a substring search on series IDs. Searching for 'ex' will find series containing 'ex' anywhere in a series ID. '' can be used to anchor searches and match 0 or more of any character. Searching for 'ex' will find series containing 'ex' at the beginning of a series ID. Searching for 'ex' will find series containing 'ex' at the end of a series ID. It's also possible to put an '' in the middle of a string. 'm*sl' finds any series starting with 'm' and ending with 'sl'.
  3. realtimeStart, optional. Default: today's date.
    The start of the real-time period. For more information, see Real-Time Periods.
  4. realtimeEnd, optional. Default: today's date.
    The start of the real-time period. For more information, see Real-Time Periods.
  5. limit, optional. Default: 1000.
    The maximum number of results to return. integer between 1 and 1000.
  6. orderBy, optional. Default: If the value of searchType is SearchType.FullText then the default value of orderBy is SearchOrder.SearchRank. If the value of searchType is SearchType.SeriesId then the default value of orderBy is SearchOrder.SeriesId.
    Order results by values of the specified attribute. One of the following: SearchOrder.SearchRank SearchOrder.SeriesIdOrder SearchOrder.Title SearchOrder.Units SearchOrder.Frequency SearchOrder.SeasonalAdjustment SearchOrder.RealTimeStart SearchOrder.RealTimeEnd SearchOrder.LastUpdated SearchOrder.ObservationStart SearchOrder.ObservationEnd SearchOrder.Popularity SearchOrder.GroupPopularity
  7. sortOrder, optional. Default: If orderBy is equal to SearchOrder.SearchRank or SearchOrder.Popularity, then the default value of sortOrder is SortOrder.Descending. Otherwise, the default sortOrder is SortOrder.Ascending.
    Sort results is ascending or descending order for attribute values specified by orderBy.

Examples:

Search for "10-Year" text without specifying any optional parameters.

myFred.Series.Search("10-Year").Summary()
Count of search hits: 10590
Top 10 results:
  1. 10-Year Treasury Constant Maturity Minus 2-Year Treasury Constant Maturity 
         Id: T10Y2Y     Period: 1976-06-01 to 2023-11-09  Freq: Daily 

  2. 10-Year Treasury Constant Maturity Minus 2-Year Treasury Constant Maturity 
         Id: T10Y2YM    Period: 1976-06-01 to 2023-10-01  Freq: Monthly 

  3. 10-Year Treasury Constant Maturity Minus 3-Month Treasury Constant Maturity 
         Id: T10Y3M     Period: 1982-01-04 to 2023-11-09  Freq: Daily 

  4. Market Yield on U.S. Treasury Securities at 10-Year Constant Maturity, Quoted on an Investment Basis 
         Id: DGS10      Period: 1962-01-02 to 2023-11-08  Freq: Daily 

  5. Market Yield on U.S. Treasury Securities at 10-Year Constant Maturity, Quoted on an Investment Basis 
         Id: GS10       Period: 1953-04-01 to 2023-10-01  Freq: Monthly 

  6. 10-Year Treasury Constant Maturity Minus 3-Month Treasury Constant Maturity 
         Id: T10Y3MM    Period: 1982-01-01 to 2023-10-01  Freq: Monthly 

  7. Market Yield on U.S. Treasury Securities at 10-Year Constant Maturity, Quoted on an Investment Basis 
         Id: WGS10YR    Period: 1962-01-05 to 2023-11-03  Freq: Weekly, Ending Friday 

  8. Market Yield on U.S. Treasury Securities at 10-Year Constant Maturity, Quoted on an Investment Basis 
         Id: RIFLGFCY10NA Period: 1962-01-01 to 2022-01-01  Freq: Annual 

  9. 10-Year Breakeven Inflation Rate 
         Id: T10YIE     Period: 2003-01-02 to 2023-11-09  Freq: Daily 

 10. 10-Year Breakeven Inflation Rate 
         Id: T10YIEM    Period: 2003-01-01 to 2023-10-01  Freq: Monthly

Search for "10-Year" text specifying some optional parameters.

myFred.Series.Search("10-Year", 
                     searchType = SearchType.FullText, 
                     limit = 3, 
                     orderBy = SearchOrder.GroupPopularity, 
                     sortOrder = SortOrder.Descending).Summary()
Count of search hits: 10590
Top 3 results:
  1. 10-Year Treasury Constant Maturity Minus 2-Year Treasury Constant Maturity 
         Id: T10Y2Y     Period: 1976-06-01 to 2023-11-09  Freq: Daily 

  2. 10-Year Treasury Constant Maturity Minus 2-Year Treasury Constant Maturity 
         Id: T10Y2YM    Period: 1976-06-01 to 2023-10-01  Freq: Monthly 

  3. 10-Year Treasury Constant Maturity Minus 3-Month Treasury Constant Maturity 
         Id: T10Y3M     Period: 1982-01-04 to 2023-11-09  Freq: Daily

Search for "Hello World" text that should not match any series.

myFred.Series.Search("Hello World").Summary()
Count of search hits: 0
Top 0 results:

F# Data FRED: Series.Info

Get the information for an economic data series.

This method only asks for the series id as a parameter (string)

Examples:

Get the information for series id = "GS10"

myFred.Series.Info "GS10"
val it: JsonProvider<...>.InfoResponse =
  {
  "realtime_start": "2023-11-13",
  "realtime_end": "2023-11-13",
  "seriess": [
    {
      "id": "GS10",
      "realtime_start": "2023-11-13",
      "realtime_end": "2023-11-13",
      "title": "Market Yield on U.S. Treasury Securities at 10-Year Constant Maturity, Quoted on an Investment Basis",
      "observation_start": "1953-04-01",
      "observation_end": "2023-10-01",
      "frequency": "Monthly",
      "frequency_short": "M",
      "units": "Percent",
      "units_short": "%",
      "seasonal...

F# Data FRED: Series.Categories

Get the categories for an economic data series.

The parameters are the following:

  1. id, required.
    The id for a series (string).
  2. realtimeStart, optional. Default: today's date.
    The start of the real-time period. For more information, see Real-Time Periods.
  3. realtimeEnd, optional. Default: today's date.
    The start of the real-time period. For more information, see Real-Time Periods.

Examples:

Get the category information for series id = "GS10"

myFred.Series.Categories "GS10"
val it: JsonProvider<...>.CategoriesResponse =
  {
  "categories": [
    {
      "id": 115,
      "name": "Treasury Constant Maturity",
      "parent_id": 22
    }
  ]
}

You can also access the category fields with Array.map:

myFred.Series.Categories("GS10").Categories
|> Array.map(fun x -> x.Name)
val it: string array = [|"Treasury Constant Maturity"|]

F# Data FRED: Series.Release

Get the release for an economic data series.

The parameters are the following:

  1. id, required.
    The id for a series (string).
  2. realtimeStart, optional. Default: today's date.
    The start of the real-time period. For more information, see Real-Time Periods.
  3. realtimeEnd, optional. Default: today's date.
    The start of the real-time period. For more information, see Real-Time Periods.

Examples:

Get the release information for series id = "GS10"

myFred.Series.Release "GS10"
val it: JsonProvider<...>.ReleaseResponse =
  {
  "realtime_start": "2023-11-13",
  "realtime_end": "2023-11-13",
  "releases": [
    {
      "id": 18,
      "realtime_start": "2023-11-13",
      "realtime_end": "2023-11-13",
      "name": "H.15 Selected Interest Rates",
      "press_release": true,
      "link": "http://www.federalreserve.gov/releases/h15/"
    }
  ]
}

F# Data FRED: Series.Tags

Get the FRED tags for a series.

The parameters are the following:

  1. id, required.
    The id for a series (string).
  2. realtimeStart, optional. Default: today's date.
    The start of the real-time period. For more information, see Real-Time Periods.
  3. realtimeEnd, optional. Default: today's date.
    The start of the real-time period. For more information, see Real-Time Periods.
  4. orderBy, optional. Default: OrderByTags.SeriesCount. Order results by values of the specified attribute. One of the following: OrderByTags.SeriesCount, OrderByTags.Popularity, OrderByTags.Created, OrderByTags.Name, OrderByTags.GroupId.
  5. sortOrder, optional. Default: SortOrder.Ascending. Sort results is ascending or descending order for attribute values specified by orderBy.

Examples:

Get the first 3 tags information for series id = "GS10" without specifying any optional parameters.

myFred.Series.Tags("GS10").Tags
|> Array.truncate 3 
val it: JsonProvider<...>.Tag array =
  [|{
  "name": "h15",
  "group_id": "rls",
  "notes": "H.15 Selected Interest Rates",
  "created": "2012-08-16 15:21:17-05",
  "popularity": 56,
  "series_count": 270
};
    {
  "name": "10-year",
  "group_id": "gen",
  "notes": "",
  "created": "2012-02-27 10:18:19-06",
  "popularity": 53,
  "series_count": 288
};
    {
  "name": "interest rate",
  "group_id": "gen",
  "notes": "",
  "created": "2012-05-29 10:14:19-05",
  "popularity": 70,
  "series_count": 1596
}|]

Get the first 3 tags information for series id = "GS10" specifying some optional parameters.

myFred.Series.Tags("GS10", orderBy = OrderByTags.Popularity, sortOrder = SortOrder.Descending).Tags
|> Array.truncate 3 
val it: JsonProvider<...>.Tag array =
  [|{
  "name": "h15",
  "group_id": "rls",
  "notes": "H.15 Selected Interest Rates",
  "created": "2012-08-16 15:21:17-05",
  "popularity": 56,
  "series_count": 270
};
    {
  "name": "10-year",
  "group_id": "gen",
  "notes": "",
  "created": "2012-02-27 10:18:19-06",
  "popularity": 53,
  "series_count": 288
};
    {
  "name": "interest rate",
  "group_id": "gen",
  "notes": "",
  "created": "2012-05-29 10:14:19-05",
  "popularity": 70,
  "series_count": 1596
}|]

F# Data FRED: Series.Observations

Get the observations or data values for an economic data series.

The parameters are the following:

  1. id, required.
    The id for a series (string).
  2. realtimeStart, optional. Default: today's date.
    The start of the real-time period. For more information, see Real-Time Periods.
  3. realtimeEnd, optional. Default: today's date.
    The start of the real-time period. For more information, see Real-Time Periods.
  4. limit, optional. Default: 1000.
    The maximum number of results to return. integer between 1 and 1000.
  5. sortOrder, optional. Default: SortOrder.Ascending.
    Sort results is ascending or descending observation date order.
  6. observationStart, optional. Default: DateTime(1776,07,04) (earliest available).
    The start of the observation period. DateTime(yyyy,MM,dd) formatted DateTime.
  7. observationEnd, optional. Default: today's date. DateTime(9999,12,31) (latest available).
    The end of the observation period. DateTime(yyyy,MM,dd) formatted DateTime.
  8. units, optional. Default: Units.Levels (No transformation).
    A key that indicates a data value transformation. One of the following: Units.Levels Units.Change Units.ChangefromYearAgo Units.PercentChange Units.PercentChangefromYearAgo Units.CompoundedAnnualRateofChange Units.ContinuouslyCompoundedRateofChange Units.ContinuouslyCompoundedAnnualRateofChange Units.NaturalLog. Unit transformation formulas
  9. frequency, optional.
    An optional parameter that indicates a lower frequency to aggregate values to. The FRED frequency aggregation feature converts higher frequency data series into lower frequency data series (e.g. converts a monthly data series into an annual data series). In FRED, the highest frequency data is daily, and the lowest frequency data is annual. There are 3 aggregation methods available- average, sum, and end of period. See the aggregation_method parameter. One of the following: Frequency.Daily, Frequency.Weekly, Frequency.Biweekly, Frequency.Monthly, Frequency.Quarterly, Frequency.Semiannual, Frequency.Annual, Frequency.WeeklyEndingFriday, Frequency.WeeklyEndingThursday, Frequency.WeeklyEndingWednesday, Frequency.WeeklyEndingTuesday, Frequency.WeeklyEndingMonday, Frequency.WeeklyEndingSunday, Frequency.WeeklyEndingSaturday, Frequency.BiweeklyEndingWednesday, Frequency.BiweeklyEndingMonday.
  10. aggMethod, optional. Default: AggMethod.Average.
    A key that indicates the aggregation method used for frequency aggregation. This parameter has no affect if the frequency parameter is not set. One of the following: AggMethod.Average, AggMethod.Sum, AggMethod.EndOfPeriod.

Examples:

Get the observations for "GS10" series without specifying any optional parameters.

myFred.Series.Observations("GS10").Observations
|> Seq.truncate 3 
val it: JsonProvider<...>.Observation seq =
  seq
    [{
  "realtime_start": "2023-11-13",
  "realtime_end": "2023-11-13",
  "date": "1953-04-01",
  "value": "2.83"
};
     {
  "realtime_start": "2023-11-13",
  "realtime_end": "2023-11-13",
  "date": "1953-05-01",
  "value": "3.05"
};
     {
  "realtime_start": "2023-11-13",
  "realtime_end": "2023-11-13",
  "date": "1953-06-01",
  "value": "3.11"
}]

Get the observations for "DTP10J25" with a semi-annual frequency.

myFred.Series.Observations("DTP10J25", frequency = Frequency.Semiannual).Observations
|> Seq.truncate 3 
val it: JsonProvider<...>.Observation seq =
  seq
    [{
  "realtime_start": "2023-11-13",
  "realtime_end": "2023-11-13",
  "date": "2015-01-01",
  "value": "."
};
     {
  "realtime_start": "2023-11-13",
  "realtime_end": "2023-11-13",
  "date": "2015-07-01",
  "value": "0.624"
};
     {
  "realtime_start": "2023-11-13",
  "realtime_end": "2023-11-13",
  "date": "2016-01-01",
  "value": "0.315"
}]
val ignore: value: 'T -> unit
Multiple items
namespace FSharp

--------------------
namespace Microsoft.FSharp
Multiple items
namespace FSharp.Data

--------------------
namespace Microsoft.FSharp.Data
type WorldBankData = static member GetDataContext: unit -> WorldBankDataService nested type ServiceTypes
WorldBankData.GetDataContext() : WorldBankData.ServiceTypes.WorldBankDataService
namespace FSharp.Data.Fred
namespace System
namespace System.IO
val envVars: Collections.IDictionary
type Environment = static member Exit: exitCode: int -> unit static member ExpandEnvironmentVariables: name: string -> string static member FailFast: message: string -> unit + 1 overload static member GetCommandLineArgs: unit -> string array static member GetEnvironmentVariable: variable: string -> string + 1 overload static member GetEnvironmentVariables: unit -> IDictionary + 1 overload static member GetFolderPath: folder: SpecialFolder -> string + 1 overload static member GetLogicalDrives: unit -> string array static member SetEnvironmentVariable: variable: string * value: string -> unit + 1 overload static member CommandLine: string ...
<summary>Provides information about, and means to manipulate, the current environment and platform. This class cannot be inherited.</summary>
Environment.GetEnvironmentVariables() : Collections.IDictionary
Environment.GetEnvironmentVariables(target: EnvironmentVariableTarget) : Collections.IDictionary
Multiple items
type LiteralAttribute = inherit Attribute new: unit -> LiteralAttribute

--------------------
new: unit -> LiteralAttribute
[<Literal>] val KeyJson: string = "/home/runner/work/FSharp.Data.Fred/FSharp.Data.Fred/docs/../fredKey.json"
val apiKey: string
Multiple items
namespace FSharp.Data.Fred

--------------------
type Fred = new: key: string -> Fred static member loadKey: keyFile: string -> string member Key: string member Series: Series
<summary> Represents a type for accessing the Fred API. You must provide an api key. </summary>
<example><code lang="fsharp"> let myFred = Fred "insert your API key here" </code> or <code lang="fsharp"> let myFred = Fred.loadKey "fredKey.json" </code></example>


--------------------
new: key: string -> Fred
static member Fred.loadKey: keyFile: string -> string
val myFred: Fred
property Fred.Series: Series with get
<summary> Represents a Fred data series. </summary>
member Series.Search: searchText: string * ?searchType: SearchType * ?realtimeStart: DateTime * ?realtimeEnd: DateTime * ?limit: int * ?orderBy: SearchOrder * ?sortOrder: SortOrder -> Search
type SearchType = | FullText | SeriesId
<summary> Represents the type of search to perform. </summary>
<category index="1">Unions</category>
union case SearchType.FullText: SearchType
<summary> Searches series attributes title, units, frequency, and tags by parsing words into stems. This makes it possible for searches like 'Industry' to match series containing related words such as 'Industries'. Of course, you can search for multiple words like 'money' and 'stock'. Remember to url encode spaces (e.g. <c>money%20stock</c>). </summary>
type SearchOrder = | SearchRank | SeriesIdOrder | Title | Units | Frequency | SeasonalAdjustment | RealTimeStart | RealTimeEnd | LastUpdated | ObservationStart ...
<summary> Order results by values of the specified attribute. </summary>
<category index="2">Unions</category>
union case SearchOrder.GroupPopularity: SearchOrder
<summary> Order search by group popularity </summary>
type SortOrder = | Ascending | Descending
<summary> Sort results is ascending or descending observation date order. </summary>
<category index="3">Unions</category>
union case SortOrder.Descending: SortOrder
<summary> Sort results in descending order. </summary>
member Series.Info: id: string -> JsonProvider<...>.InfoResponse
member Series.Categories: id: string * ?realtimeStart: DateTime * ?realtimeEnd: DateTime -> JsonProvider<...>.CategoriesResponse
type Array = interface ICollection interface IEnumerable interface IList interface IStructuralComparable interface IStructuralEquatable interface ICloneable member Clone: unit -> obj member CopyTo: array: Array * index: int -> unit + 1 overload member GetEnumerator: unit -> IEnumerator member GetLength: dimension: int -> int ...
<summary>Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the base class for all arrays in the common language runtime.</summary>
val map: mapping: ('T -> 'U) -> array: 'T array -> 'U array
val x: JsonProvider<...>.Category
property JsonProvider<...>.Category.Name: string with get
member Series.Release: id: string * ?realtimeStart: DateTime * ?realtimeEnd: DateTime -> JsonProvider<...>.ReleaseResponse
member Series.Tags: id: string * ?realtimeStart: DateTime * ?realtimeEnd: DateTime * ?orderBy: OrderByTags * ?sortOrder: SortOrder -> JsonProvider<...>.TagsResponse
val truncate: count: int -> array: 'T array -> 'T array
type OrderByTags = | SeriesCount | Popularity | Created | Name | GroupId
<summary> Order Tags by values of the specified attribute. </summary>
<category index="8">Unions</category>
union case OrderByTags.Popularity: OrderByTags
<summary> Order by tag popularity </summary>
member Series.Observations: id: string * ?observationStart: DateTime * ?observationEnd: DateTime * ?limit: int * ?sortOrder: SortOrder * ?units: Units * ?frequency: Frequency * ?aggMethod: AggMethod * ?realtimeStart: DateTime * ?realtimeEnd: DateTime -> JsonProvider<...>.ObservationsResponse
module Seq from Microsoft.FSharp.Collections
val truncate: count: int -> source: 'T seq -> 'T seq
type Frequency = | Daily | Weekly | Biweekly | Monthly | Quarterly | Semiannual | Annual | WeeklyEndingFriday | WeeklyEndingThursday | WeeklyEndingWednesday ...
<summary> The FRED frequency aggregation feature converts higher frequency data series into lower frequency data series (e.g. converts a monthly data series into an annual data series). In FRED, the highest frequency data is daily, and the lowest frequency data is annual. </summary>
<category index="5">Unions</category>
union case Frequency.Semiannual: Frequency

Type something to start searching.