quantlib.diamond package

Submodules

quantlib.diamond.analyzer module

class quantlib.diamond.analyzer.Analyzer(config: AnalyzerConfig)

Bases: object

property end_plot_idx: int
property first_considered_bar_idx: int
plot(plot_index: bool = False) BarPlot

Plot final line pair

Parameters:

plot_index (bool, optional) – plot index instead of time, this can be used for debugging, defaults to False

Returns:

The plot

Return type:

BarPlot

plot_round1(plot_index: bool = False, plot_intersection: bool = False)
round1(lines: list[Line], search_distance: int) tuple[list[Line], Line | None]

Given a search distance, select the best line a group of lines

Parameters:
  • lines (list[Line]) – Candidate lines

  • search_distance (int) – search distance

Raises:

ValueError – Invalid Selection Method

Returns:

lines and best line selected

Return type:

tuple[list[Line], Line | None]

round2(round1_result_dict: dict[int, Round1Result]) LinePair

From lines selected from different search ranges, select the one that is the smoothest :param round1_result_dict: results from round 1 :return: winner line pair

property start_plot_idx: int
verify()

Verify if analysis has by run, as some features like plots require existing analysis results to continue. This helper function checks if history cache and analysis result exists.

Raises:

ValueError – Missing dataloading

quantlib.diamond.config module

class quantlib.diamond.config.AnalyzerConfig(lower_search_range: int, upper_search_range: int, selection_method: quantlib.constant.enum.RSSPSelectionMethod, allow_negative_support: bool, allow_positive_resistance: bool, optimal_slope_range_checker: quantlib.diamond.criterion.OptimalSlopeChecker, distance_required: Callable[[int], int] = <function default_distance_required at 0x1293b1800>, n_bars_to_plot_before: int = 10, n_bars_to_plot_after_current: int = 10)

Bases: object

allow_negative_support: bool
allow_positive_resistance: bool
distance_required() int
lower_search_range: int
n_bars_to_plot_after_current: int = 10
n_bars_to_plot_before: int = 10
optimal_slope_range_checker: OptimalSlopeChecker
selection_method: RSSPSelectionMethod
to_dict() dict
upper_search_range: int
quantlib.diamond.config.default_distance_required(distance: int) int

quantlib.diamond.criterion module

class quantlib.diamond.criterion.OptimalSlopeChecker(optimal_slope_range: OptimalSlopeRange, normalize_factor: float)

Bases: object

check(line: Line, bar_history: BarHistory, current_bar_idx: int, time_interval: TimeInterval) bool
class quantlib.diamond.criterion.OptimalSlopeRange(resistance: dict[quantlib.constant.enum.TimeInterval, quantlib.diamond.criterion.SlopeRange], support: dict[quantlib.constant.enum.TimeInterval, quantlib.diamond.criterion.SlopeRange])

Bases: object

resistance: dict[TimeInterval, SlopeRange]
support: dict[TimeInterval, SlopeRange]
class quantlib.diamond.criterion.SlopeRange(left: float, right: float)

Bases: object

contains(slope: float) bool
property high: float
left: float
property low: float
reversed() SlopeRange
right: float
quantlib.diamond.criterion.get_optimal_slope_checker_from_mode(mode: OptimalSlopeMode) OptimalSlopeChecker
quantlib.diamond.criterion.get_slope_range_by_line_mode_and_time_interval(optimal_slope_range: OptimalSlopeRange, line_mode: LineMode, time_interval: TimeInterval) SlopeRange

Retrieve slope range by line mode and time interval. Helper function to simplify logic in main program. Extract the line mode checks and error handling in a separate function

Parameters:
Raises:

ValueError – Handle unexpected case that line mode is invalid

Returns:

_description_

Return type:

dict[TimeInterval, SlopeRange]

quantlib.diamond.linesfilter module

class quantlib.diamond.linesfilter.LinesFilter(lines: list[Line])

Bases: object

As the name implies, this class is for filtering lines in a method chaining/fluent interface pattern Not only filtering, methods could also be used to modify properties in lines (set flags), e.g. optimal Filtered lines should be saved back to self.lines, and each method should return self instead of the filtered lines Filtered lines can be accessed by the lines property Sample Usage: resulting_lines = LinesFilter(initial_lines).filter_by_gap(…).filter_by_slope_sign(…).lines

fill_optimal_property(optimal_slope_range_checker: OptimalSlopeChecker, bar_history: BarHistory, current_bar_idx: int, time_interval: TimeInterval) LinesFilter

Fill optimal property of lines by slope range specified in optimal_slope_range

filter_by_gap(distance_required: Callable[[int], int], search_distance: int) LinesFilter

Filter out lines that has no gap or small gaps between 2 bars

Parameters:
  • distance_required (Callable[[int], int]) – a function takes in a search distance int, and return a minimum gap required

  • search_distance (int) – Lookback Search Distance

Returns:

self

Return type:

LinesFilter

filter_by_slope_sign(analyzer_config: AnalyzerConfig) LinesFilter

Filter lines by slope sign config

Parameters:

analyzer_config (AnalyzerConfig) – analyzer configuration which contains the allow_positive_resistance and allow_negative_support bool flag

Returns:

self

Return type:

LinesFilter

quantlib.diamond.utils module

quantlib.diamond.utils.fill_optimal(lines: list[Line], optimal_slope_range: OptimalSlopeRange, time_interval: TimeInterval) list[Line]
quantlib.diamond.utils.select_by_max_distance(lines: list[Line]) Line | None
quantlib.diamond.utils.select_by_smoothness(lines: list[Line]) Line | None

Module contents