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:
F# Data FRED: Series.Search
A collection of economic data series that match the parameters.
The parameters are the following:
-
searchText, required.
The words to match against economic data series. -
searchType, optional. Default is
SearchType.FullText
.
Determines the type of search to perform. One of the following:SearchType.FullText
orSearchType.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'.
-
-
realtimeStart, optional. Default: today's date.
The start of the real-time period. For more information, see Real-Time Periods. -
realtimeEnd, optional. Default: today's date.
The start of the real-time period. For more information, see Real-Time Periods. -
limit, optional. Default:
1000
.
The maximum number of results to return. integer between1
and1000
. -
orderBy, optional. Default: If the value of
searchType
isSearchType.FullText
then the default value oforderBy
isSearchOrder.SearchRank
. If the value ofsearchType
isSearchType.SeriesId
then the default value oforderBy
isSearchOrder.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
-
sortOrder, optional. Default: If
orderBy
is equal toSearchOrder.SearchRank
orSearchOrder.Popularity
, then the default value ofsortOrder
isSortOrder.Descending
. Otherwise, the defaultsortOrder
isSortOrder.Ascending
.
Sort results is ascending or descending order for attribute values specified byorderBy
.
Examples:
Search for "10-Year"
text without specifying any optional parameters.
myFred.Series.Search("10-Year").Summary()
|
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()
|
Search for "Hello World"
text that should not match any series.
myFred.Series.Search("Hello World").Summary()
|
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"
|
F# Data FRED: Series.Categories
Get the categories for an economic data series.
The parameters are the following:
-
id, required.
The id for a series (string
). -
realtimeStart, optional. Default: today's date.
The start of the real-time period. For more information, see Real-Time Periods. -
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"
|
You can also access the category fields with Array.map
:
myFred.Series.Categories("GS10").Categories
|> Array.map(fun x -> x.Name)
|
F# Data FRED: Series.Release
Get the release for an economic data series.
The parameters are the following:
-
id, required.
The id for a series (string
). -
realtimeStart, optional. Default: today's date.
The start of the real-time period. For more information, see Real-Time Periods. -
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"
|
F# Data FRED: Series.Tags
Get the FRED tags for a series.
The parameters are the following:
-
id, required.
The id for a series (string
). -
realtimeStart, optional. Default: today's date.
The start of the real-time period. For more information, see Real-Time Periods. -
realtimeEnd, optional. Default: today's date.
The start of the real-time period. For more information, see Real-Time Periods. -
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
. -
sortOrder, optional. Default:
SortOrder.Ascending
. Sort results is ascending or descending order for attribute values specified byorderBy
.
Examples:
Get the first 3 tags information for series id = "GS10"
without specifying any optional parameters.
myFred.Series.Tags("GS10").Tags
|> Array.truncate 3
|
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
|
F# Data FRED: Series.Observations
Get the observations or data values for an economic data series.
The parameters are the following:
-
id, required.
The id for a series (string
). -
realtimeStart, optional. Default: today's date.
The start of the real-time period. For more information, see Real-Time Periods. -
realtimeEnd, optional. Default: today's date.
The start of the real-time period. For more information, see Real-Time Periods. -
limit, optional. Default:
1000
.
The maximum number of results to return. integer between1
and1000
. -
sortOrder, optional. Default:
SortOrder.Ascending
.
Sort results is ascending or descending observation date order. -
observationStart, optional. Default:
DateTime(1776,07,04)
(earliest available).
The start of the observation period.DateTime(yyyy,MM,dd)
formattedDateTime
. -
observationEnd, optional. Default: today's date.
DateTime(9999,12,31)
(latest available).
The end of the observation period.DateTime(yyyy,MM,dd)
formattedDateTime
. -
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 -
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
. -
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
|
Get the observations for "DTP10J25"
with a semi-annual frequency.
myFred.Series.Observations("DTP10J25", frequency = Frequency.Semiannual).Observations
|> Seq.truncate 3
|
namespace FSharp
--------------------
namespace Microsoft.FSharp
namespace FSharp.Data
--------------------
namespace Microsoft.FSharp.Data
<summary>Provides information about, and means to manipulate, the current environment and platform. This class cannot be inherited.</summary>
Environment.GetEnvironmentVariables(target: EnvironmentVariableTarget) : Collections.IDictionary
type LiteralAttribute = inherit Attribute new: unit -> LiteralAttribute
--------------------
new: unit -> LiteralAttribute
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
<summary> Represents a Fred data series. </summary>
<summary> Represents the type of search to perform. </summary>
<category index="1">Unions</category>
<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>
<summary> Order results by values of the specified attribute. </summary>
<category index="2">Unions</category>
<summary> Order search by group popularity </summary>
<summary> Sort results is ascending or descending observation date order. </summary>
<category index="3">Unions</category>
<summary> Sort results in descending order. </summary>
<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>
<summary> Order Tags by values of the specified attribute. </summary>
<category index="8">Unions</category>
<summary> Order by tag popularity </summary>
<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>