DataFrame utils

Data.DFUtilsModule

Utilities for DataFrames.jl, prominently timeframe based indexing.

Data.DFUtils._mutatemax!Method

Mutates v to df ensuring the dataframe never grows larger than maxlen.

_mutatemax!(df, v, maxlen, n, mut; cols)
Data.DFUtils.addcols!Method

Inserts rows in src to dst, zeroing columns not present in dst.

addcols!(dst, src)
Data.DFUtils.colnamesMethod

Get the column names for dataframe as symbols.

colnames(df::DataFrames.AbstractDataFrame) -> Any
Data.DFUtils.copysubs!Method

Replaces subarrays with arrays.

copysubs!(df::DataFrames.AbstractDataFrame) -> Any
copysubs!(df::DataFrames.AbstractDataFrame, copyfunc) -> Any
copysubs!(
    df::DataFrames.AbstractDataFrame,
    copyfunc,
    elsefunc
) -> Any
Data.DFUtils.dateindexMethod

Get the position of date in the :timestamp column of the dataframe based on timeframe arithmentics.

dateindex(
    df::DataFrames.AbstractDataFrame,
    date::Dates.DateTime,
    _::Val{:timeframe}
) -> Any
Data.DFUtils.dateindexMethod

Get the position of date in the :timestamp column of the dataframe.

dateindex(
    df::DataFrames.AbstractDataFrame,
    date::Dates.DateTime
) -> Union{Int64, DataStructures.Tokens.IntSemiToken}
Data.DFUtils.daterangeMethod

Get the date range of a DataFrame.

daterange(
    df::DataFrames.AbstractDataFrame
) -> TimeTicks.DateRange
daterange(
    df::DataFrames.AbstractDataFrame,
    tf
) -> TimeTicks.DateRange
daterange(
    df::DataFrames.AbstractDataFrame,
    tf,
    rightofs
) -> TimeTicks.DateRange

Used to get the date range of a DataFrame df. It takes in the DataFrame df, an optional timeframe tf (default is the current timeframe of the DataFrame), and an optional rightofs parameter. The rightofs parameter specifies the number of steps to shift the date range to the right. For example, if rightofs is set to 1, the date range will be shifted one step to the right. This can be useful for calculating future date ranges based on the current date range. Returns the date range of the DataFrame df based on the specified timeframe tf and rightofs parameter.

Data.DFUtils.getdateMethod

Get the date-based subset of a DataFrame.

getdate(
    df::DataFrames.AbstractDataFrame,
    dr::Union{TimeTicks.DateRange, StepRange{Dates.DateTime, <:Dates.Period}},
    cols
) -> Any
getdate(
    df::DataFrames.AbstractDataFrame,
    dr::Union{TimeTicks.DateRange, StepRange{Dates.DateTime, <:Dates.Period}},
    cols,
    tf
) -> Any

Indexing by date ranges allows to query ohlcv using the timestamp column as index, assuming that the data has no missing values and is already sorted.

Examples: df[dtr"1999-.."] # Starting from 1999 up to the end df[dtr"..1999-"] # From the beginning up to 1999 df[dtr"1999-..2000-"] # The Year 1999

Data.DFUtils.getdateMethod

Get the specified columns based on given date (used as index).

getdate(
    df::DataFrames.AbstractDataFrame,
    idx::Dates.DateTime,
    cols
) -> Any
getdate(
    df::DataFrames.AbstractDataFrame,
    idx::Dates.DateTime,
    cols,
    tf::TimeFrames.TimeFrame
) -> Any

While indexing ohlcv data we have to consider the time of arrival of a candle. In general candles collect the price up to its timestamp. E.g. the candle at time 2000-01-01 would have tracked time from 1999-12-31T00:00:00 to 2000-01-01T00:00:00. Therefore what we return is always the left adjacent timestamp of the queried one.

Data.DFUtils.setcols!Function

Set the values of specific columns in one DataFrame from another DataFrame.

setcols!(dst, src, cols)
setcols!(dst, src, cols, idx)

Used to set the values of specific columns in one DataFrame dst from another DataFrame src. It takes in the destination DataFrame dst, the source DataFrame src, the columns to set cols, and optional indices idx to specify the rows to set. The cols parameter specifies the columns in the destination DataFrame dst that will be set with the corresponding values from the source DataFrame src. The idx parameter specifies the indices of the rows in the destination DataFrame dst that will be set. By default, it sets all rows. It mutates the destination DataFrame dst by setting the values of the specified columns cols with the corresponding values from the source DataFrame src.

Data.DFUtils.viewfromMethod

Create a view of an OHLCV DataFrame starting from a specific index.

viewfrom(ohlcv, from::Integer; offset, cols) -> Any

Used to create a view of an OHLCV DataFrame ohlcv starting from a specific index from. It takes in the OHLCV DataFrame ohlcv, the starting index from as an integer, and optional parameters offset and cols. The offset parameter specifies the number of rows to offset the view from the starting index. The default value is 0, indicating no offset. The cols parameter specifies the columns to include in the view. By default, all columns are included. Returns a view of the original OHLCV DataFrame ohlcv starting from the specified index from, with an optional offset and specified columns.

Misc.afterFunction

Get the subset of a DataFrame containing rows after a specific date.

after(
    df::DataFrames.DataFrame,
    dt::Dates.DateTime
) -> DataFrames.SubDataFrame{DataFrames.DataFrame, DataFrames.Index, UnitRange{Int64}}
after(
    df::DataFrames.DataFrame,
    dt::Dates.DateTime,
    cols
) -> Any

This function is used to get the subset of a DataFrame df that contains rows after a specific date dt. It takes in the DataFrame df, the specific date dt as a DateTime object, and optional columns cols to include in the subset. If cols is not specified, the function includes all columns in the subset. If cols is specified, only the columns listed in cols will be included in the subset. This function returns a DataFrameView that contains only the rows of df that occur after the specified date dt and the specified columns cols.

TimeTicks.timeframe!Method

Infer the dataframe's timeframe from the timestamp column of the dataframe and sets it.

TimeTicks.timeframeMethod

Returns the timeframe of a dataframe according to its metadata.

timeframe(
    df::DataFrames.AbstractDataFrame
) -> TimeFrames.TimeFrame

If the value is not found in the metadata, infer it by timestamp column of the dataframe. If the timeframe can't be inferred, a TimeFrame(0) is returned. NOTE: slow func, for speed use timeframe!(::DataFrame)