Processing

PlanarCore.Data.propagate_ohlcv!Function

Updates OHLCV data across multiple time frames.

propagate_ohlcv!(
    data::SortedDict{TimeFrames.TimeFrame, DataFrames.DataFrame}
) -> Union{Nothing, SortedDict{TimeFrames.TimeFrame, DataFrames.DataFrame}, SortedDict{_A, _B, Base.Order.ForwardOrdering} where {_A, _B}}
propagate_ohlcv!(
    data::SortedDict{TimeFrames.TimeFrame, DataFrames.DataFrame},
    update_func::Function
) -> Union{Nothing, SortedDict{TimeFrames.TimeFrame, DataFrames.DataFrame}, SortedDict{_A, _B, Base.Order.ForwardOrdering} where {_A, _B}}

This function takes a dictionary data and an aggregation function update_func. It updates the OHLCV data from the base time frame to the higher time frames in data, using update_func to aggregate the OHLCV values from the base to the target time frame. The function modifies data in place and returns it. If the base time frame data frame in data is empty, the function clears all the higher time frames data frames. Otherwise, it asynchronously updates each higher time frame data frame and ensures that the timestamps are synchronized across all time frames.

source
PlanarCore.Data.propagate_ohlcv!Method

Resamples OHLCV data between different time frames.

propagate_ohlcv!(
    src::DataFrames.DataFrame,
    dst::DataFrames.DataFrame;
    src_tf,
    dst_tf,
    strict
) -> DataFrames.DataFrame

This function resamples the OHLCV data from a source DataFrame to a destination DataFrame with different timeframes. If the latest timestamp in the destination DataFrame is earlier than the earliest timestamp in the resampled source DataFrame, the function appends the resampled data to the destination DataFrame. If not, the function returns the destination DataFrame as is. Both the source and destination DataFrames must have columns named 'timestamp', 'open', 'high', 'low', 'close', and 'volume'. The source and destination timeframes must be suitable for the resampling operation.

source
PlanarCore.Processing._deltasMethod

Computes the deltas for a given transformation.

_deltas(
    data,
    to_tf
) -> Union{Tuple{Float64, Float64, Float64, Any}, Tuple{Integer, Any, Any, Nothing}}

This function takes a data vector and a target transformation function, and computes the deltas (changes) in the data that would result from applying the transformation.

source
PlanarCore.Processing._left_and_rightMethod

Returns the left and right indices for a given frame.

_left_and_right(
    data,
    frame_size,
    src_td,
    td
) -> Tuple{Int64, Any}

This function takes a data vector, frame size, source time delta, and target time delta, and computes the left and right indices for the frame based on these parameters.

source
PlanarCore.Processing.cleanup_ohlcv!Method

Cleans up OHLCV data in a ZArray.

cleanup_ohlcv!(
    z::Zarr.ZArray,
    timeframe::AbstractString
) -> Union{Nothing, Zarr.ZArray}

This function takes a ZArray z and a string timeframe. It cleans up the OHLCV data in z by removing any incomplete candles based on timeframe and filling any missing candles using the specified filling strategy.

source
PlanarCore.Processing.cleanup_ohlcv_dataMethod

Cleans up OHLCV data in a DataFrame.

cleanup_ohlcv_data(
    data,
    tf::TimeFrames.TimeFrame;
    col,
    fill_missing
) -> Any

This function takes a DataFrame data, a TimeFrame tf, and optionally a column index col and a filling strategy fill_missing. It cleans up the OHLCV data in data by removing any incomplete candles based on tf, filling any missing candles using the specified filling strategy, and sorting the data by the specified column.

source
PlanarCore.Processing.fill_missing_candlesMethod

Fills missing candles in a DataFrame.

fill_missing_candles(
    df,
    timeframe::AbstractString;
    strategy
) -> Any

This function takes a DataFrame df, a string timeframe, and optionally a filling strategy strategy. It identifies the missing candles in df based on the timeframe, and fills them using the specified strategy.

filling strategies:

  • :close: fill with the close price of the previous candle.
  • :open: fill with the open price of the next candle.
  • :linear: linearly interpolate between the close price of the previous candle and the open price of the next candle.
source
PlanarCore.Processing.islastMethod

Checks if the last row of a smaller DataFrame is also the last row of a larger DataFrame.

islast(
    larger::DataFrames.DataFrame,
    smaller::DataFrames.DataFrame
) -> Any
source
PlanarCore.Processing.maptfMethod

Apply a function over data, resampling data to each timeframe in tfs.

maptf(
    tfs::AbstractVector{T} where T<:String,
    data,
    f::Function;
    tfsum,
    kwargs...
) -> Any
  • f: signature is (data; kwargs...)::DataFrame
  • tfsum: sum the scores across multiple timeframes for every pair.
source
PlanarCore.Processing.resampleFunction

Resamples data based on transformation functions.

resample(data, from_tf, to_tf) -> Any
resample(data, from_tf, to_tf, cleanup) -> Any
resample(data, from_tf, to_tf, cleanup, style) -> Any
resample(data, from_tf, to_tf, cleanup, style, chop)

This function takes a data vector, a source transformation function from_tf, a target transformation function to_tf, and optionally a boolean cleanup and a style style. It resamples the data from the source time frame to the target time frame. If cleanup is true, it removes any invalid data points after resampling. The resampling style is determined by style. If chop is true, it removes the leftovers at the end of the data that can't fill a complete frame.

source
PlanarCore.Processing.resampleFunction
resample(
    df::DataFrames.AbstractDataFrame,
    tf::TimeFrames.TimeFrame;
    ...
) -> Any
resample(
    df::DataFrames.AbstractDataFrame,
    tf::TimeFrames.TimeFrame,
    b::Bool,
    args...;
    kwargs...
) -> Any

. See resample.

source
PlanarCore.Processing.resampleMethod

Resamples data, and saves to storage.

resample(args...; exc_name, name, dosave) -> Any
Usually not worth it

Resampling is quite fast, so it is simpler to keep only the smaller timeframe on storage, and resample the longer ones on demand.

source
PlanarCore.Processing.resample_styleMethod

Resamples a style based on a transformation function.

resample_style(style, tf) -> Any

This function takes a style and a transformation function tf, and resamples the style based on the transformation.

source
PlanarCore.Processing.trail!Method

Applies trailing operation on a DataFrame based on a time frame.

trail!(df, tf::TimeFrames.TimeFrame; to, from, cap)

This function takes a DataFrame df, a TimeFrame tf, and optionally a timestamp to, a timestamp from, and a cap cap. It applies a trailing window operation on df for the specified tf. The operation starts from the timestamp specified by from (default is the last timestamp in the DataFrame) and ends at the timestamp specified by to. The cap argument determines the maximum number of rows to keep in the dataframe.

source
PlanarCore.Processing.upsampleMethod

Upsample OHLCV DataFrame from a larger timeframe to a smaller one.

Arguments:

  • df: DataFrame with OHLCV columns and a regular, contiguous timeframe (large_tf)
  • large_tf: TimeFrame of the input DataFrame
  • smalltf: TimeFrame to upsample to (must be a divisor of largetf)

Returns:

  • DataFrame with OHLCV columns at the smaller timeframe, where each large candle is expanded into N small candles (N = largetf.period ÷ smalltf.period), with open/high/low/close flat-filled, and volume divided equally.
source
PlanarCore.Processing.upsample_intervalMethod

Compute the number of intervals of tf between dt1 and dt2.

upsample_interval(tf"1m", DateTime(2024,1,1,0,0), DateTime(2024,1,1,0,5)) == 5
upsample_interval(tf"5m", DateTime(2024,1,1,0,0), DateTime(2024,1,1,0,10)) == 2

Throws ArgumentError if dt1 >= dt2.

source