Specification

The contents of a Collection is specified in a Specification. There are three types of Specifications. Their respective SpecificationTypes are: CollectionSpecification, SFDBSpecification (see SimpleFastDB) and ExternalDataSpecification (see ExternalData).

The Specification contains information about what data (see DataFields) at what dates/datetimes (see Constituents) are included in the Collection.

A typical way of creating and using a Specification of the CollectionSpecification type is:

TFire> tickers = ["MMM", "AOS", "ABT", "ACN", "ATVI"];

TFire> spec = Specification(tickers, Date(2001,6,2),Date(2018,6,8); extend_back=600);

TFire> collection = setup_collection(spec);

The Specification of a given Collection may be obtained as:

TFire> spec = Specification(collection);

Constituents

The Constituents contain information about ticker symbols and timeperiods as well as resolution. In a Collection every Sample in an Asset is specified by the ticker, a beginning and end date in the Constituents.

The Constituents changes depending on if they represent a Collection, a SimpleFastDB or ExternalData. For example, even though there are one timeperiod per sample in a Collection, there are only one timeperiod per time series in a SimpleFastDB. Thus, Constituents may be translated between Collection, SimpleFastDB and ExternalData.

ConstituentsContinuous

The ConstituentsContinuous is used when the data for each ticker is continuous in time.For example daily close data for an asset that is traded daily.

Fields:

  • ticker_ranges: An ordered dictionary linking tickers to vectors of datetime ranges, indicating time series intervals for each asset.
  • resolution: Describes the data granularity, e.g., "1d", "1m".
  • specification_type: ExternalSpecification, CollectionSpecification or SFDBSpecification

ConstituentsDiscrete

The ConstituentsDiscrete is used when the data for each ticker is discrete in time. For example when intraday data is to be fetched for several days for an asset that is traded only part of the day, like a stock.

Fields:

  • dates: An ordered dictionary where each date references a ConstituentsContinuous, allowing representation of non-continuous data.
  • resolution: Specifies the data granularity.
  • specification_type: ExternalSpecification, CollectionSpecification or SFDBSpecification

DataFields

DataFields specifies which fields of data (suck as price, volume etc) are available in the Collection, SimpleFastDB or ExternalData.

Fields:

  • fields: A Set of Symbols specifying data fields.

When creating a new SpecificationCollection a preset set of DataFields may be included by passing a Symbol insted of a DataFields object to the constructor.

Supported Symbols and their associated DataFields are:

  • :normal => [:open, :close, :adj_close, :adj_close_log, :high, :low, :volume]
  • :reduced => [:adj_close, :adj_close_log]
  • :all_adj_log => [:adj_close_log, :adj_open_log, :adj_high_log, :adj_low_log]

When nothing is specified, i.e. a SpecificationCollection is created without passing a DataFields object, the :normal DataFields are used.

Translations Between SpecificationTypes

While every type of Specification may be manually specified, an automatic translation is most commonly used. The most frequent procedure is to create a CollectionSpecification, which is then translated to a SFDBSpecification that is then translated to an ExternalDataSpecification.

CollectionSpecification to SFDBSpecification

The function

specification_sfdb(spec::SpecificationStruct{C,T}; extend_first=Day(0), extend_last=Day(1000)) where {C<:AssetConstituents,T<:CollectionSpecification}

translates a CollectionSpecification to a SFDBSpecification. The SFDBSpecification specifies one time series per ticker. The extend_first and extend_last parameters indicate how many days/minutes etc of data should be added to the beginning and end of the timeseries. If extend_first=0 and extend_last=0, the resulting SFDBSpecification will specify a timeseries that begins from the first datetime specified for that ticker in the CollectionSpecification and end with the last datetime.

SFDBSpecification to ExternalDataSpecification

A SFDBSpecification is converted to an ExternalDataSpecification by the function

specification_external(spec::SpecificationStruct{C,T}) where {C<:AssetConstituents,T<:SFDBSpecification}

The constituents are here kept as they are, but the data fields are modified to convert logarithmized data fields to their non logarithmized counterparts.

Functions

For functions related to Specifications seeSpecification - Functions