Collection - Functions
TFire.TradingDates
— MethodTradingDates(col::Collection)
Returns a TradingDates
object containing the unique set of trading dates across all assets in the given Collection
.
TFire.Specification
— MethodSpecification(col::Collection{A}) where A <: AssetsCon
Constructs a SpecificationStruct
from the given Collection
object. The SpecificationStruct
contains information about the constituents and data fields of the collection.
The function iterates through the assets in the collection, extracting the start and end dates for each asset. This information is used to construct a ConstituentsContinuous
object, which represents the constituents of the collection. The data fields are also extracted from the first asset in the collection.
The resulting SpecificationStruct
contains the constituents, data fields, and the specification type (in this case, CollectionSpecification
).
TFire.condensate_type
— Methodcondensate_type(col::Collection)
The type of the outermost (latest) condensate in the assets of the collection.
TFire.copy_collection
— Methodcopy_collection(col::Collection)
Returns a deepcopy of the collection.
TFire.get_asset
— Methodget_asset(col::Collection{A}, ticker::String) where {A <: AssetsCon}
Returns the asset with the given ticker from the collection.
TFire.get_dates
— Methodget_dates(col::Collection{A}) where {A <: AssetsDisc}
Returns the dates for all the discrete assets in the given collection.
TFire.get_eval_dates
— Methodget_eval_dates(col::Collection{A}) where A <: AssetsCon
Returns all unique evaluation dates for the collection in chronological order.
TFire.get_first_asset
— Methodget_first_asset(collection::Collection{T}) where T <: Assets
Returns the first asset from the iterator over all the assets in the collection. Useful if one needs to get an asset but doesn't care which.
TFire.get_tickers
— Method get_tickers(col::Collection)
Returns a vector with the names of all the tickers in the collection. For continuous assets the names are ordered as the assets.
TFire.has_layer_type
— Methodhas_layer_type(col::Collection, lay_typ::Type{T}) where T <: AssetLayer
Returns true if collection has layer type in chain of layers. Otherwise false.
TFire.list_layer_types
— Methodlist_layer_types(col::Collection)
Returns a vector with the condensate types for the assets in the collection. Outermost condensate first.
TFire.number_of_samples
— Methodnumber_of_samples(col::Collection)
Total number of samples for all assets in collection.
TFire.setup_collection
— Methodsetup_collection(col::Collection{A}) where A <: AssetsCon
Sets up a new Collection
instance based on the provided Collection
object..
TFire.setup_collection
— Methodsetup_collection(spec::SpecificationStruct{C,T}; extend_first::Int=1000, extend_last::Int=1000,
trading_dates::Union{Nothing,TradingDates}=nothing) where {C<:AssetConstituents, T<:CollectionSpecification}
Sets up a new Collection
based on the provided SpecificationStruct
, with optional extensions to the first and last trading dates, and an optional TradingDates
object.
Args: spec::SpecificationStruct{C,T}: The specification struct containing the collection configuration. extendfirst::Int: The number of days to extend the first trading date by (default is 1000 days). extendlast::Int: The number of days to extend the last trading date by (default is 1000 days). trading_dates::Union{Nothing,TradingDates}: An optional TradingDates
object containing the unique set of trading dates across all assets in the collection.
Returns: A new Collection
instance, or nothing
if no assets were found.
TFire.setup_collection
— Methodsetup_collection(spec::SpecificationStruct{C,T}, sfdb::SimpleFastDB) where {C<:AssetConstituents, T<:CollectionSpecification}
Sets up a new Collection
based on the provided SpecificationStruct
and SimpleFastDB
. The function creates the necessary assets, settings, and other required components for the Collection
.
Args: spec::SpecificationStruct{C,T}: The specification struct containing the collection configuration. sfdb::SimpleFastDB: The SimpleFastDB
instance to use for setting up the collection.
Returns: A new Collection
instance, or nothing
if no assets were found.
TFire.setup_collection
— Methodsetup_collection(spec::SpecificationStruct{C,T}, trading_dates::Union{Nothing,TradingDates}) where {C<:AssetConstituents, T<:CollectionSpecification}
Sets up a new Collection
based on the provided SpecificationStruct
, with an optional TradingDates
object.
Args: spec::SpecificationStruct{C,T}: The specification struct containing the collection configuration. trading_dates::Union{Nothing,TradingDates}: An optional TradingDates
object containing the unique set of trading dates across all assets in the collection.
Returns: A new Collection
instance.
Collection Manipulation - Functions
Getindex Functions
Base.getindex
— MethodBase.getindex(col::Collection{AssetsCon{T}}, ind_col::I) where {T <: Assets, I <: Collection}
Returns a new Collection
with the assets selected from the assets in the provided Collection
ind_col
. The new Collection
will have the same settings, settingsused, and donorspec as the original Collection
.
Base.getindex
— MethodBase.getindex(col::Collection{AssetsCon{T}}, ind::I) where {T <: Assets, I <: Union{String, DateTime, Date}}
Returns a new Collection
with the assets selected by the provided index ind
. The index can be a single value of type:
String
: Selects assets by their ticker.DateTime
: Selects assets based on a specific timestamp.Date
: Selects assets for a particular date.
Base.getindex
— MethodBase.getindex(col::Collection{AssetsCon{T}}, inds::UnitRange{I}) where {T <: Assets, I <: Integer}
TBW
Base.getindex
— MethodBase.getindex(col::Collection{AssetsCon{T}}, inds::Vector{I}) where {T <: Assets, I <: Union{String, DateTime, Date}}
Returns a new Collection
with the assets selected by the provided vector of indices inds
. The indices can be of type:
String
: Selects assets by their ticker.DateTime
: Selects assets based on a specific timestamp.Date
: Selects assets for a particular date.
The new Collection
will have the same settings, settingsused, and donorspec as the original Collection
.
Base.getindex
— MethodBase.getindex(col::Collection{AssetsCon{T}}, ind::Type{L}) where {T <: Assets, L <: AssetLayer}
Returns a new Collection
with the assets filtered by the specified AssetLayer
type L
. The new Collection
will have the same settings, settingsused, and donorspec as the original Collection
.
Base.getindex
— MethodBase.getindex(col::Collection{AssetsDisc{T}}, ind::Union{Date, Integer, String}) where T <: Assets
Returns a new Collection
based on the provided index type:
- If
ind
is aDate
, returns a newCollection
with the continuous assets at the specified date. - If
ind
is anInteger
, returns a newCollection
with the continuous assets at the specified index. The index represents the integer index of the discrete time point in the collection (e.g., for daily data, 1 refers to the first day, 2 to the second day, etc.). - If
ind
is aString
, returns a newCollection
with the discrete assets that have the specified ticker.
The new Collection
will have the same settings, settingsused, and donorspec as the original Collection
.
Set Operations Functions
Base.:+
— Method+(col1::Collection, col2::Collection)
Performs a union of two collections. Settings and settings_used need to be equal for the two collections. Returns a new collection.
Base.:-
— Method-(col1::Collection, col2::Collection)
Performs a set difference between two collections. Settings and settings_used need to be equal for the two collections. Returns a new collection.
Base.:==
— Method==(col1::Collection, col2::Collection)
Compares two Collection
objects for equality. The comparison checks if the settings
and settings_used
fields are equal, and if the assets
fields are equal.
Base.intersect
— Methodintersect(col1::Collection, col2::Collection)
Returns the intersection of two collections. Settings and settings_used need to be equal for the two collections.
Base.setdiff
— Methodsetdiff(col1::Collection, col2::Collection)
Performs a set difference between two collections. Settings and settings_used need to be equal for the two collections. Returns a new collection.
Base.union
— Methodunion(col1::Collection, col2::Collection)
Performs a union of two collections. Settings and settings_used need to be equal for the two collections. Returns a new collection.
Collection Settings - Functions
TFire.TFSettings_load
— MethodTFSettings_load()
Loads the TFGlobalSettings from a JSON file in the TFSettings directory. If the file does not exist, it will be created by calling TFSettings_save()
.
TFire.TFSettings_save
— MethodTFSettings_save()
Saves the current TFGlobalSettings to a JSON file in the TFSettings directory.
TFire.add!
— Methodadd!(settings::Settings, param::Parameters)
Adds parameters params
into settings
.
TFire.add_and_replace_parameters!
— Methodadd_and_replace_parameters(set::Settings, set_add::Settings)
Adds all parameters in set_add
to set
. Replaces already existing parameters.
TFire.add_missing!
— Methodadd_missing!(settings::Settings, params::Parameters)
Adds parameters params
into settings
only if they do not already exist in setingst
.
TFire.get_parameter
— Methodget_parameter(settings::Settings, layer_type::Type, key::Symbol)
Returns the parameter value unless key
is subtype of DefaultParameter
in which case a special value defined by the type of key
is returned.
Collection Donation - Functions
TFire.donate
— Methoddonate(col_receiver::Collection, col_donor::Collection;
dp::Union{DonationProtocol, Nothing}=nothing)
coldonor is donated to colreceiver such that a new collection is created
TFire.dp_all_to_all
— Methoddp_all_to_all(col_receiver::Collection, col_donor::Collection)
Returns a donation protocol where every ticker t in colreceiver links to a vector of all tickers in coldonor.
TFire.dp_same_tickers
— Methoddp_same_tickers(col::Collection)
Returns a donation protocol where every ticker t in col links to a vector of length one with the same ticker t.
Collection Plotting - Functions
TFire.plot_bar
— Methodplot_bar(x, y; name::String="",line_color::String="", show_legend=true, bargap=0.5)
Plots a bar chart with the given x and y data.
Args: x (Vector): The x-axis data. y (Vector): The y-axis data. name (String, optional): The name of the trace, used for the legend. Defaults to an empty string. linecolor (String, optional): The color of the bars, specified as a hex string. Defaults to an empty string. showlegend (Bool, optional): Whether to show the legend for this trace. Defaults to true. bargap (Float, optional): The gap between bars, as a fraction of the bar width. Defaults to 0.5.
Returns: The generated bar chart.
TFire.plot_compound_return_per_date
— Methodplot_compound_return_per_date(col::Collection, return_steps; window=1, col_compare=:no_compare)
Plots the compound return and number of assets per date for a given collection, with an optional comparison collection.
Arguments:
col::Collection
: The collection to plot the compound return and number of assets for.return_steps::Int
: The number of steps to use for the compound return calculations.
Optional Arguments:
window::Int
: The number of days to use for the rolling window of the compound return calculation. Default is 1.col_compare::Union{:no_compare,Collection}
: An optional collection to compare the compound return against. Default is:no_compare
.
Returns: A plot displaying the compound return and number of assets per date for the given collection, with an optional comparison collection.
TFire.plot_envelope
— Methodplot_envelope(col_select::Collection, col_reference::Collection, steps::Int)
Plots the compound return envelope for a reference collection and the mean compound return for a selected collection.
Arguments:
col_select::Collection
: The selected collection to plot the mean compound return for.col_reference::Collection
: The reference collection to plot the compound return envelope for.steps::Int
: The number of steps to use for the compound return calculations.
TFire.plot_line
— Methodplot_line(x, y; name::String="",line_color::String="", width::Int=2, show_legend=true)
Plots a line plot with the given x and y data.
Args: x (Vector): The x-axis data. y (Vector): The y-axis data. name (String, optional): The name of the trace, used for the legend. Defaults to an empty string. linecolor (String, optional): The color of the line, specified as a hex string. Defaults to an empty string. width (Int, optional): The width of the line in pixels. Defaults to 2. showlegend (Bool, optional): Whether to show the legend for this trace. Defaults to true.
Returns: The generated line plot.
TFire.plot_line
— Methodplot_line(y; name::String="",line_color::String="", width::Int=2, show_legend=true)
Plots a line plot with the given y data.
Args: y (Vector): The y-axis data. name (String, optional): The name of the trace, used for the legend. Defaults to an empty string. linecolor (String, optional): The color of the line, specified as a hex string. Defaults to an empty string. width (Int, optional): The width of the line in pixels. Defaults to 2. showlegend (Bool, optional): Whether to show the legend for this trace. Defaults to true.
Returns: The generated line plot.
TFire.plot_marker
— Methodplot_marker(x, y; name::String="",marker_color::String="", size::Int=5, show_legend=false)
Plots a scatter plot with the given x and y data.
Args: x (Vector): The x-axis data. y (Vector): The y-axis data. name (String, optional): The name of the trace, used for the legend. Defaults to an empty string. markercolor (String, optional): The color of the markers, specified as a hex string. Defaults to an empty string. size (Int, optional): The size of the markers in pixels. Defaults to 5. showlegend (Bool, optional): Whether to show the legend for this trace. Defaults to false.
Returns: The generated scatter plot.
TFire.plot_return_vs_parameter
— Methodplot_return_vs_parameter(col::Collection, x_vals::CDV;
xmin=nothing, xmax=nothing, resolution=48, steps=50, nobound=50, logresults=false, xlabel="X", ylabel="Return", plottype=:line, meantype=:arithmetic)
Plot the returns of a collection against a specified parameter.
Arguments
col::Collection
: The collection of data to analyze.x_vals::CDV
: The parameter values to plot against.
Optional Arguments
x_min::Union{Nothing,Number}
: The minimum value for the x-axis. If nothing, it's determined automatically.x_max::Union{Nothing,Number}
: The maximum value for the x-axis. If nothing, it's determined automatically.resolution::Int
: The number of bins to use for discretizing the x-axis. Default is 48.steps::Int
: The number of steps to use for the x-axis. Default is 50.no_bound::Int
: The maximum number of samples to consider for each bin. Default is 50.log_results::Bool
: Whether to apply log10 transformation to the results. Default is false.x_label::String
: The label for the x-axis. Default is "X".y_label::String
: The label for the y-axis. Default is "Return".plot_type::Symbol
: The type of plot to create. Can be :line or :bar. Default is :line.mean_type::Symbol
: The type of mean to use for aggregating returns. Default is :arithmetic.
Returns
A plot object displaying the returns against the specified parameter.
Description
This function creates a plot of returns versus a specified parameter for a given collection. It also includes a secondary y-axis showing the number of samples for each data point. The function supports both line and bar plots, and can optionally apply a log transformation to the results.
TFire.plot_return_vs_parameters_2d
— Methodplot_return_vs_parameters_2d(col::Collection, x_vals, y_vals; x_min=nothing, x_max=nothing,
y_min=nothing, y_max=nothing, resolution=48, steps=50,
no_bound=50, log_results=false, x_label="X", y_label="Y", mode=:return, mean_type=:arithmetic)
Create a 2D heatmap plot of returns versus two parameters.
Arguments
col::Collection
: The collection of data to analyze.x_vals
: The values for the x-axis parameter.y_vals
: The values for the y-axis parameter.
Optional Arguments
x_min::Union{Nothing,Number}
: The minimum value for the x-axis. If nothing, it's determined automatically.x_max::Union{Nothing,Number}
: The maximum value for the x-axis. If nothing, it's determined automatically.y_min::Union{Nothing,Number}
: The minimum value for the y-axis. If nothing, it's determined automatically.y_max::Union{Nothing,Number}
: The maximum value for the y-axis. If nothing, it's determined automatically.resolution::Int
: The number of bins to use for discretizing the x and y axes. Default is 48.steps::Int
: The number of steps to use for the x and y axes. Default is 50.no_bound::Int
: The maximum number of samples to consider for each bin. Default is 50.log_results::Bool
: Whether to apply log10 transformation to the results. Default is false.x_label::String
: The label for the x-axis. Default is "X".y_label::String
: The label for the y-axis. Default is "Y".mode::Symbol
: The type of heatmap to create. Can be :return, :noofsamples, or :adjusted_return. Default is :return.mean_type::Symbol
: The type of mean to use for aggregating returns. Default is :arithmetic.
Returns
A heatmap plot displaying the returns, number of samples, or adjusted returns versus the two specified parameters.
TFire.plot_graph
— Methodplot_graph(col::Collection{AssetsCon{A}}, ind::Integer; data_field=:default) where A <: Assets
Plots the graph for the first asset in the col
collection at the specified ind
index.
Arguments:
col::Collection{AssetsCon{A}}
: The collection of assets to plot.ind::Integer
: The index of the sample to plot. If negative, it is counted from the end of the asset.data_field=:default
: The field to use for the data to plot.
Returns: A graph plot of the asset and its layers.
TFire.plot_graph
— Methodplot_graph(col::Collection{AssetsCon{A}}, ticker::String, ind::Integer; data_field=:default) where A <: Assets
Plots the graph for the asset with the given ticker
at the specified ind
index within the col
collection.
Arguments:
col::Collection{AssetsCon{E}}
: The collection of assets to plot.ticker::String
: The ticker symbol of the asset to plot.ind::Integer
: The index of the sample to plot. If negative, it is counted from the end of the asset.data_field=:default
: The field to use for the data to plot.
Returns: A graph plot of the asset and its layers.
TFire.plot_graph
— Methodplot_graph(col::Collection{AssetsCon{A}}, ticker::String; data_field=:default) where A <: Assets
Plots the graph for the asset with the given ticker
in the col
collection.
Arguments:
col::Collection{AssetsCon{A}}
: The collection of assets to plot.ticker::String
: The ticker symbol of the asset to plot.data_field=:default
: The field to use for the data to plot.
Returns: A graph plot of the asset and its layers.
TFire.plot_graph
— Methodplot_graph(col::Collection{AssetsDisc{A}}, date::Date, ticker::String, ind::Integer; data_field=:default) where A <: Assets
Plots the graph for the asset with the given ticker
in the col
collection at the specified date
and ind
index.
Arguments:
col::Collection{AssetsDisc{A}}
: The collection of assets to plot.date::Date
: The date of the asset to plot.ticker::String
: The ticker symbol of the asset to plot.ind::Integer
: The index of the sample to plot. If negative, it is counted from the end of the asset.data_field=:default
: The field to use for the data to plot.
Returns: A graph plot of the asset and its layers.
TFire.plot_whole_graph
— Methodplot_whole_graph(col::Collection{AssetsCon{A}}, ticker::String; data_field=:default) where A <: Assets
Plots the complete graph for the asset with the given ticker
in the col
collection.
Arguments:
col::Collection{AssetsCon{A}}
: The collection of assets to plot.ticker::String
: The ticker symbol of the asset to plot.data_field=:default
: The field to use for the data to plot.
Returns: A graph plot showing the entire history of the asset and its layers.
TFire.set_color_theme
— Methodset_color_theme(theme::Symbol)
Sets the global color theme to the provided theme
, which should be a Symbol corresponding to a valid plotting theme. Currently valid themes are :light
and :dark
.