StrategyStats

Library for common strategy signals generation.

StrategyStats.bbands!Method

Adds Bollinger Bands to a DataFrame.

bbands!(
    df::DataFrames.AbstractDataFrame;
    kwargs...
) -> DataFrames.AbstractDataFrame

The bbands! function takes the following parameters:

  • df: an AbstractDataFrame to which the Bollinger Bands will be added.
  • kwargs: a variable number of optional keyword arguments that allow you to specify additional parameters for the Bollinger Bands.

The function calculates the Bollinger Bands for the data in df based on the specified parameters in kwargs. Bollinger Bands are a type of statistical chart characterizing the prices and volatility over time of a financial instrument or commodity, using a formulaic method propounded by John Bollinger in the 1980s. The function modifies the input DataFrame df in place by adding the calculated Bollinger Bands.

StrategyStats.diffnMethod
diffn(x::Vector{T}; n::Int=1)::Vector{T} where {T<:Real}
diffn(X::Matrix; n::Int=1)::Matrix = hcat([diffn(X[:,j], n=n) for j in 1:size(X,2)]...)

Lagged differencing

StrategyStats.filterminmaxMethod

Filters and sorts a list of pairs using a predicate function.

filterminmax(
    pred::Function,
    pairs::AbstractDict,
    min_v::Real,
    max_v::Real
) -> Vector{Tuple{AbstractFloat, Data.PairData}}

This function takes a list of pairs and a predicate function. It filters the list by applying the predicate function to each pair and keeping only those pairs for which the function returns a Real number. The function then sorts the filtered list based on the returned Real numbers.

StrategyStats.find_bottomedMethod

Finds pairs that have bottomed out in the given data for long positions.

find_bottomed(
    pairs::AbstractVector{Data.PairData};
    bb_thresh,
    up_thresh,
    n,
    mn,
    mx
) -> Dict{Any, Any}

The find_bottomed function takes the following parameters:

  • pairs: an AbstractVector of PairData objects that represent pair data.
  • bb_thresh (optional, default is 0.05): a threshold value which the Bollinger Bands value must exceed to be considered a bottom.
  • up_thresh (optional, default is 0.05): a threshold value which the price change must exceed to be considered an uptrend.
  • n (optional, default is 12): an integer that represents the number of periods to consider for the bottom and uptrend detection.
  • mn (optional, default is 1.0): a minimum value for the price to be considered a bottom.
  • mx (optional, default is 90.0): a maximum value for the price to be considered a bottom.

The function scans through the pairs in the pairs vector and determines which pairs have bottomed out based on the specified criteria.

The function returns a list of pairs that have bottomed out for long positions.

StrategyStats.fltsummaryMethod

Generates a summary of a vector of tuples containing Floats and PairData.

fltsummary(
    flt::AbstractVector{Tuple{AbstractFloat, Data.PairData}}
) -> Any

This function takes a vector flt of tuples, where each tuple contains an AbstractFloat and a PairData. It generates a summary of flt, providing insights into the characteristics of the Floats and PairData in the vector.

StrategyStats.gridbbandsMethod

Generates a grid of Bollinger Bands with varying parameters.

gridbbands(
    df::DataFrames.AbstractDataFrame;
    n_range,
    sigma_range,
    corr
) -> Tuple{Dict{Any, Any}, DataFrames.DataFrame}

The gridbbands function takes the following parameters:

  • df: an AbstractDataFrame that represents historical market data.
  • n_range (optional, default is 2:2:100): a range that represents the range of possible values for the number of periods to calculate the moving average over.
  • sigma_range (optional, default is [1.0]): an array that represents the range of possible values for the number of standard deviations to calculate the bands at.
  • corr (optional, default is :corke): a symbol that represents the correlation method to use.

The function generates a grid of Bollinger Bands based on the input DataFrame df and the specified parameters. Each band in the grid uses a different combination of n_range and sigma_range.

The function returns a DataFrame that represents the grid of Bollinger Bands.

StrategyStats.gridrenkoMethod

Generates a grid of Renko charts with varying parameters.

gridrenko(
    data::DataFrames.AbstractDataFrame;
    head_range,
    tail_range,
    n_range
) -> Vector{Any}

The gridrenko function takes the following parameters:

  • data: an AbstractDataFrame that represents historical market data.
  • head_range (optional, default is 1:10): a range that represents the range of possible values for the head in the Renko chart. The head is the most recent part of the chart.
  • tail_range (optional, default is 1:3): a range that represents the range of possible values for the tail in the Renko chart. The tail is the oldest part of the chart.
  • n_range (optional, default is 10:10:200): a range that represents the range of possible values for the number of periods to calculate the Average True Range (ATR) over.

The function generates a grid of Renko charts based on the input DataFrame data and the specified parameters. Each chart in the grid uses a different combination of head_range, tail_range, and n_range. The function returns a DataFrame that represents the grid of Renko charts.

StrategyStats.is_bottomedMethod

Determines if a bottom has occurred in the OHLCV data.

is_bottomed(ohlcv::DataFrames.DataFrame; thresh, n) -> Bool

The is_bottomed function takes the following parameters:

  • ohlcv: a DataFrame that represents OHLCV (Open, High, Low, Close, Volume) data.
  • thresh (optional, default is 0.05): a threshold value which the price change must exceed to be considered a bottom.
  • n (optional, default is 26): an integer that represents the number of periods to consider for the bottom detection.

The function determines if a bottom has occurred in the OHLCV data based on the specified threshold and number of periods. A bottom is considered to have occurred when the price change exceeds the threshold within the given number of periods. The function returns a boolean that indicates whether a bottom has occurred.

StrategyStats.is_peakedMethod

Determines if a peak has occurred in the OHLCV data.

is_peaked(ohlcv::DataFrames.DataFrame; thresh, n) -> Bool

The is_peaked function takes the following parameters:

  • ohlcv: a DataFrame that represents OHLCV (Open, High, Low, Close, Volume) data.
  • thresh (optional, default is 0.05): a threshold value which the price change must exceed to be considered a peak.
  • n (optional, default is 26): an integer that represents the number of periods to consider for the peak detection.
StrategyStats.is_slopebetweenMethod

Checks if slope of a DataFrame is within certain bounds.

is_slopebetween(
    ohlcv::DataFrames.DataFrame;
    mn,
    mx,
    n
) -> Bool

This function takes a DataFrame ohlcv and optionally three integers mn (default is 5), mx (default is 90), and n (default is 26). It checks if the slope of a linear regression line fit to the last n data points in ohlcv is between mn and mx.

StrategyStats.is_uptrendMethod

Determines if an uptrend has occurred in the OHLCV data.

is_uptrend(ohlcv::DataFrames.DataFrame; thresh, n) -> Bool

The is_uptrend function takes the following parameters:

  • ohlcv: a DataFrame that represents OHLCV (Open, High, Low, Close, Volume) data.
  • thresh (optional, default is 0.05): a threshold value which the price change must exceed to be considered an uptrend.
  • n (optional, default is 26): an integer that represents the number of periods to consider for the uptrend detection.

The function determines if an uptrend has occurred in the OHLCV data based on the specified threshold and number of periods. An uptrend is considered to have occurred when the price change exceeds the threshold within the given number of periods.

StrategyStats.isrenkoentryMethod

Determines if the current state in a Renko chart indicates an entry point.

isrenkoentry(data::AbstractDict; kwargs...) -> Vector{Bool}

The isrenkoentry function takes the following parameters:

  • data: an AbstractDict that represents the current state in a Renko chart.
  • kwargs: a variable number of optional keyword arguments that allow you to specify additional criteria for an entry point.

The function determines if the current state in the Renko chart represented by data indicates an entry point based on the specified criteria. An entry point in a Renko chart is typically determined by a change in the direction of the bricks (or boxes).

The function returns a boolean that indicates whether the current state represents an entry point.

StrategyStats.maxminMethod

Identifies maximum and minimum points in a DataFrame.

maxmin(df; order, threshold, window) -> Any

The maxmin function takes the following parameters:

  • df: a DataFrame in which to identify maxima and minima.
  • order (optional, default is 1): an integer specifying how many points on each side of a point to use for the comparison to consider the point as a maximum or minimum. For example, if order=3, a point will be considered a maximum if it has three datapoints in either direction that are smaller than it.
  • threshold (optional, default is 0.0): a threshold value which the datapoint must exceed to be considered a maximum or minimum.
  • window (optional, default is 100): a window size to apply a moving maximum/minimum filter.

The function identifies maximum and minimum points in the DataFrame df based on the specified order, threshold, and window. It then returns a DataFrame with the identified maxima and minima.

StrategyStats.renkodfMethod

Generates a Renko chart DataFrame.

renkodf(df; box_size, use_atr, n) -> Any

The renkodf function takes the following parameters:

  • df: a DataFrame that represents historical market data.
  • box_size (optional, default is 10.0): a float that represents the box size for the Renko chart. This is the minimum price change required to form a new brick in the chart.
  • use_atr (optional, default is false): a boolean that indicates whether to use the Average True Range (ATR) to determine the box size. If true, the function will calculate the ATR over n periods and use this as the box size.
  • n (optional, default is 14): an integer that represents the number of periods to calculate the ATR over if use_atr is true.

The function generates a Renko chart DataFrame based on the input DataFrame df and the specified parameters. Renko charts are price charts with rising and falling bricks (or boxes) that are based on changes in price, not time, unlike most charts. They help filter out market noise and can be a useful tool in technical analysis. The function returns a DataFrame that represents the Renko chart.

StrategyStats.slopeangleMethod

Calculates the slope angle for a given array.

slopeangle(arr; n) -> Any

This function takes an array arr and optionally an integer n (default is 10). It calculates the slope angle of a linear regression line fit to the last n data points in arr.

StrategyStats.slopefilterFunction

Applies a slope filter to a dataset.

slopefilter(
;
    ...
) -> Vector{Tuple{AbstractFloat, Data.PairData}}
slopefilter(
    timeframe;
    qc,
    minv,
    maxv,
    window
) -> Vector{Tuple{AbstractFloat, Data.PairData}}

This function applies a slope filter to a dataset. It checks whether the slope of a linear regression line fit to the data meets certain criteria, and retains only those data points that pass the filter.

StrategyStats.supresMethod

Identifies support and resistance levels in a DataFrame.

supres(df; order, threshold, window) -> Any

The supres function takes the following parameters:

  • df: a DataFrame in which to identify support and resistance levels.
  • order (optional, default is 1): an integer specifying how many points on each side of a point to use for the comparison to consider the point as a support or resistance level. For example, if order=3, a point will be considered a support/resistance level if it has three datapoints in either direction that are smaller/larger than it.
  • threshold (optional, default is 0.0): a threshold value which the datapoint must exceed to be considered a support or resistance level.
  • window (optional, default is 16): a window size to apply a moving maximum/minimum filter.

The function identifies support and resistance levels in the DataFrame df based on the specified order, threshold, and window. It then returns a DataFrame with the identified support and resistance levels.

StrategyStats.up_successrateMethod

Calculates the success rate of given column against the next candle.

up_successrate(
    df,
    bcol::Union{String, Symbol};
    threshold
) -> Any

The up_successrate function takes the following parameters:

  • df: a DataFrame that represents historical market data.
  • bcol: a Symbol or String that represents the column name in df to calculate the success rate against.
  • threshold (optional, default is 0.05): a threshold value which the price change must exceed to be considered a success.

The function calculates the success rate of a particular strategy indicated by bcol for buying or selling. A trade is considered successful if the price change in the next candle exceeds the threshold. The direction of the trade (buy or sell) is determined by the bcol column: true for buy and false for sell.

The function returns a float that represents the success rate of the strategy.