### Install Kand with Pip Source: https://kand-ta.github.io/kand/install Installs the Kand library from PyPI using pip. This method is recommended for users with Python 3.8+ and pip installed, offering precompiled wheels for quick setup on various platforms. ```shell pip install kand ``` -------------------------------- ### Build and Run Custom Kand Docker Image Source: https://kand-ta.github.io/kand/install Builds a custom Docker image tagged as 'my-kand-app' from the current directory and then runs it interactively. This is useful for custom configurations or development. ```shell docker build -t my-kand-app . docker run -it --rm my-kand-app ``` -------------------------------- ### Install Kand with Pip Source: https://kand-ta.github.io/kand/about This command demonstrates the simple installation process for the Kand library using pip, replacing the complex C setup often required by TALib. ```shell pip install kand ``` -------------------------------- ### Pull Kand Docker Image Source: https://kand-ta.github.io/kand/install Pulls the latest official Docker image for Kand. This allows users to run Kand within a containerized environment without local installation. ```shell docker pull ghcr.io/rust-ta/kand:latest ``` -------------------------------- ### Run Kand Docker Container Source: https://kand-ta.github.io/kand/install Runs the Kand Docker container interactively. This command launches the container, allowing direct interaction with Kand, and automatically removes the container upon exit. ```shell docker run -it --rm ghcr.io/rust-ta/kand:latest ``` -------------------------------- ### Clone Kand Repository Source: https://kand-ta.github.io/kand/advance Clones the official Rust-TA Kand repository from GitHub to your local machine, which is the first step for building from source. ```Shell git clone https://github.com/rust-ta/kand.git cd kand ``` -------------------------------- ### Build Kand with Custom Features (Develop) Source: https://kand-ta.github.io/kand/advance Builds and installs the Kand library in editable mode with specified features like floating-point precision (f32), integer type (i64), and validation level (check). This is useful for development. ```Shell maturin develop --features f32,i64,check ``` -------------------------------- ### Build Kand with Custom Features (Release) Source: https://kand-ta.github.io/kand/advance Builds an optimized release version of the Kand library with specified features such as floating-point precision (f64), integer type (i64), and validation level (check). ```Shell maturin build --release --features f64,i64,check ``` -------------------------------- ### Compute VEGAS Indicator Over NumPy Arrays Source: https://kand-ta.github.io/kand/api Computes the VEGAS (Volume and EMA Guided Adaptive Scaling) indicator over a 1-D NumPy array of prices. VEGAS is a trend-following indicator that uses multiple Exponential Moving Averages (EMAs) to define channels and boundaries. The function returns four arrays representing Channel Upper, Channel Lower, Boundary Upper, and Boundary Lower EMAs. ```python import numpy as np import kand prices = np.array([44.34, 44.09, 44.15, 43.61, 44.33]) ch_upper, ch_lower, b_upper, b_lower = kand.vegas(prices) ``` -------------------------------- ### Simplify release workflow and customize changelog footer Source: https://kand-ta.github.io/kand/changelog This refactoring effort simplifies the release workflow and customizes the changelog footer. ```ci # _(ci)_ Simplify release workflow and customize changelog footer ``` -------------------------------- ### Refactor release CI Source: https://kand-ta.github.io/kand/changelog This refactoring effort simplifies the release CI process. ```ci # _(ci:release)_ Refactor release ci ``` -------------------------------- ### Python EMA Performance Benchmarking Source: https://kand-ta.github.io/kand/performance This snippet outlines the Python scripts used for benchmarking EMA computation performance. It includes separate scripts for single-threaded and multi-threaded tests, utilizing TA-Lib and Kand libraries respectively. The tests involve varying dataset sizes and a fixed EMA period, with multiple iterations to ensure accurate average execution time. ```Python bench_ema.py: Single-thread performance testing ``` ```Python bench_ema_mt.py: Multi-thread performance testing ``` -------------------------------- ### Incrementally Calculate TRIMA Source: https://kand-ta.github.io/kand/api Provides an incremental calculation for the next TRIMA value, optimizing performance by using previous calculations. It requires previous SMA values, the new price, the old price dropping out, the old SMA1 value, and the smoothing period. ```Python import kand trima, sma1 = kand.trima_inc( 35.5, # prev_sma1 35.2, # prev_sma2 36.0, # new_price 35.0, # old_price 35.1, # old_sma1 5 # period ) ``` -------------------------------- ### Calculate Incremental Bollinger Bands Source: https://kand-ta.github.io/kand/api Calculates the next Bollinger Bands values incrementally using previous calculations and the latest price data. It requires the current price, previous SMA, sums, old price, period, and deviation parameters. Returns upper, middle, and lower bands, along with updated SMA, sum, and sum of squares. ```Python import kand upper, middle, lower, sma, sum, sum_sq = kand.bbands_inc( 10.0, # price 9.5, # prev_sma 28.5, # prev_sum 272.25, # prev_sum_sq 9.0, # old_price 3, # period 2.0, # dev_up 2.0 # dev_down ) ``` -------------------------------- ### Resolve Clippy warnings for float comparisons Source: https://kand-ta.github.io/kand/changelog This entry addresses Clippy warnings related to strict float comparisons, improving code quality and adherence to linting standards. ```rust # _(willr)_ Resolve Clippy warnings for strict float comparisons ``` ```rust # _(stats)_ Resolve Clippy warnings for strict float comparisons in max/min ``` -------------------------------- ### Fix makefile and add params for gen_stub.py Source: https://kand-ta.github.io/kand/changelog This entry includes fixes for the 'makefile' and adds parameters for the 'gen_stub.py' script. ```makefile # _(makefile)_ Fix uv-sync, add params for gen_stub.py ``` -------------------------------- ### Calculate OBV Incrementally Source: https://kand-ta.github.io/kand/api Calculates the next OBV value incrementally using the previous OBV value and current price/volume data. This function provides an optimized way to update OBV. ```python import kand curr_close = 12.0 prev_close = 10.0 volume = 150.0 prev_obv = 100.0 result = kand.obv_inc(curr_close, prev_close, volume, prev_obv) print(result) ``` -------------------------------- ### Fix publish-rust CI Source: https://kand-ta.github.io/kand/changelog This entry addresses a bug fix related to the 'publish-rust' CI process. ```ci # _(ci)_ Fix publish-rust ``` -------------------------------- ### Python TA-Lib EMA Single-Threaded Execution Source: https://kand-ta.github.io/kand/performance This code snippet represents the single-threaded execution of EMA calculations using the TA-Lib library. It serves as a baseline for performance comparison against multi-threaded implementations. The tests are configured with specific dataset sizes and EMA periods. ```Python # Example of using talib.EMA (single-threaded) import talib import numpy as np # Assume data is a numpy array of prices data = np.random.rand(1000000) period = 30 # Calculate EMA using talib ema_talib = talib.EMA(data, timeperiod=period) ``` -------------------------------- ### Update rust documentation Source: https://kand-ta.github.io/kand/changelog This entry updates the documentation for the Rust project. ```rustdoc # Update rust doc ``` -------------------------------- ### Update publish-doc CI Source: https://kand-ta.github.io/kand/changelog This entry updates the 'publish-doc' CI process. ```ci # _(ci:publish-doc)_ Update publish-doc ``` -------------------------------- ### Update makefile Source: https://kand-ta.github.io/kand/changelog This entry updates the 'makefile'. ```makefile # _(makefile)_ Update makefile ``` -------------------------------- ### Calculate Incremental Weighted Close Price (WCLPRICE) Source: https://kand-ta.github.io/kand/api Calculates a single Weighted Close Price (WCLPRICE) value incrementally from the latest price data. It requires the latest high, low, and close prices and returns the calculated WCLPRICE value. ```Python import kand wclprice = kand.wclprice_inc(15.0, 11.0, 14.0) ``` -------------------------------- ### Calculate Incremental Balance of Power (BOP) Source: https://kand-ta.github.io/kand/api Calculates a single Balance of Power (BOP) value for the latest price data. This function is useful for real-time calculations where only the current period's data is available. It requires the current open, high, low, and close prices. ```Python import kand bop = kand.bop_inc(10.0, 12.0, 8.0, 11.0) ``` -------------------------------- ### Calculate RMA Incrementally Source: https://kand-ta.github.io/kand/api The rma_inc function calculates the next RMA value incrementally, optimizing for streaming data without requiring full price history. It takes the current price, previous RMA, and the smoothing period as input. ```python import kand new_rma = kand.rma_inc(10.0, 9.5, 14) ``` -------------------------------- ### Python Kand EMA Multi-Threaded Execution Source: https://kand-ta.github.io/kand/performance This code snippet demonstrates the multi-threaded execution of EMA calculations using the Kand library. It highlights Kand's ability to leverage multiple CPU cores for improved performance. The tests are configured to run with varying thread counts (2, 4, 6) depending on the hardware, across different dataset sizes. ```Python # Example of using kand.ema (multi-threaded) import kand import numpy as np # Assume data is a numpy array of prices data = np.random.rand(1000000) period = 30 num_threads = 4 # Calculate EMA using kand with multiple threads ema_kand = kand.ema(data, period=period, nthreads=num_threads) ``` -------------------------------- ### Calculate Incremental VWAP Source: https://kand-ta.github.io/kand/api Calculates a single VWAP value incrementally using the latest price and volume data. It requires the latest high, low, close prices, volume, and the previous cumulative price-volume product and volume. It returns the new cumulative PV, new cumulative volume, and the new VWAP. ```Python import kand new_cum_pv, new_cum_vol, vwap = kand.vwap_inc(15.0, 11.0, 14.0, 200.0, 1000.0, 150.0) ``` -------------------------------- ### Add missing error documentation for lowest_bars and highest_bars Source: https://kand-ta.github.io/kand/changelog This documentation update adds missing error documentation for the 'lowest_bars' and 'highest_bars' functions. ```rustdoc # _(helper)_ Add missing error documentation for lowest_bars and highest_bars functions ``` -------------------------------- ### Calculate Balance of Power (BOP) for NumPy Arrays Source: https://kand-ta.github.io/kand/api Computes the Balance of Power (BOP) indicator for multiple data points using NumPy arrays. BOP measures the strength between buyers and sellers by comparing the closing price to the opening price, normalized by the trading range. Requires input arrays for open, high, low, and close prices. ```Python import numpy as np import kand open = np.array([10.0, 11.0, 12.0, 13.0]) high = np.array([12.0, 13.0, 14.0, 15.0]) low = np.array([8.0, 9.0, 10.0, 11.0]) close = np.array([11.0, 12.0, 13.0, 14.0]) bop = kand.bop(open, high, low, close) ``` -------------------------------- ### Optimize T::from(100).unwrap() conversion Source: https://kand-ta.github.io/kand/changelog This entry optimizes the conversion of T::from(100).unwrap() to use safe conversion with ok_or(KandError::ConversionError)?. ```rust # _(cdl_gravestone_doji)_ Optimize T::from(100).unwrap() to T::from(100).ok_or(KandError::ConversionError)? ``` -------------------------------- ### Add f32 floating-point precision support Source: https://kand-ta.github.io/kand/changelog This entry introduces support for f32 floating-point precision, enhancing the project's numerical capabilities. It is associated with issue #10. ```rust # _(precision)_ Add f32 floating-point precision support (#10) ``` -------------------------------- ### Fix test-rust CI Source: https://kand-ta.github.io/kand/changelog This entry addresses a bug fix for the 'test-rust' CI process. ```ci # _(ci)_ Fix test-rust ``` -------------------------------- ### Fix .editorconfig path Source: https://kand-ta.github.io/kand/changelog This entry addresses a bug fix related to the '.editorconfig' file path. ```editorconfig # _(.editorconfig)_ Fix path ``` -------------------------------- ### Calculate +DI Incrementally with Kand Source: https://kand-ta.github.io/kand/api The plus_di_inc function calculates the next +DI value incrementally, utilizing previous smoothed values and current price data for real-time updates. It returns the latest +DI, new smoothed +DM, and new smoothed TR. ```Python import kand plus_di, smoothed_plus_dm, smoothed_tr = kand.plus_di_inc( 10.5, # high 9.5, # low 10.0, # prev_high 9.0, # prev_low 9.5, # prev_close 15.0, # prev_smoothed_plus_dm 20.0, # prev_smoothed_tr 14 # period ) ``` -------------------------------- ### Incrementally Calculate Directional Movement Index (DX) Source: https://kand-ta.github.io/kand/api Calculates the latest Directional Movement Index (DX) value incrementally, optimizing for real-time scenarios by using previous smoothed values. This function requires the current high and low prices, previous high, low, and close prices, and previous smoothed +DM, -DM, and TR values, along with the calculation period. ```Python import kand high, low = 24.20, 23.85 prev_high, prev_low, prev_close = 24.07, 23.72, 23.95 prev_smoothed_plus_dm = 0.5 prev_smoothed_minus_dm = 0.3 prev_smoothed_tr = 1.2 period = 14 dx, plus_dm, minus_dm, tr = kand.dx_inc( high, low, prev_high, prev_low, prev_close, prev_smoothed_plus_dm, prev_smoothed_minus_dm, prev_smoothed_tr, period ) ``` -------------------------------- ### Calculate Weighted Close Price (WCLPRICE) Source: https://kand-ta.github.io/kand/api Calculates the Weighted Close Price (WCLPRICE) for a series of price data. This indicator gives more weight to the closing price compared to high and low prices. It requires high, low, and close prices as 1-D NumPy arrays and returns an array of WCLPRICE values. ```Python import numpy as np import kand high = np.array([10.0, 12.0, 15.0]) low = np.array([8.0, 9.0, 11.0]) close = np.array([9.0, 11.0, 14.0]) wclprice = kand.wclprice(high, low, close) ``` -------------------------------- ### Compute Stochastic Oscillator (Python) Source: https://kand-ta.github.io/kand/api Computes the Stochastic Oscillator indicator, which includes %K (fast and slow) and %D lines. This momentum indicator compares the closing price to its price range over a given period. It requires high, low, and close price arrays, along with periods for %K and %D calculations. ```Python import numpy as np import kand high = np.array([10.0, 12.0, 15.0, 14.0, 13.0]) low = np.array([8.0, 9.0, 11.0, 10.0, 9.0]) close = np.array([9.0, 11.0, 14.0, 12.0, 11.0]) fast_k, k, d = kand.stoch(high, low, close, 3, 2, 2) ``` -------------------------------- ### Calculate Aroon Oscillator Incrementally Source: https://kand-ta.github.io/kand/api Calculates the next Aroon Oscillator value incrementally. It requires current and previous high/low prices, days since high/low, and the lookback period. Returns the Aroon Oscillator value and updated highest/lowest prices and days counts. ```Python import kand osc, high, low, days_high, days_low = kand.aroonosc_inc( 15.0, # high 12.0, # low 14.0, # prev_high 11.0, # prev_low 2, # days_since_high 1, # days_since_low 14 # period ) ``` -------------------------------- ### Compute On Balance Volume (OBV) Source: https://kand-ta.github.io/kand/api Computes the On Balance Volume (OBV) over NumPy arrays. OBV is a momentum indicator that uses volume flow to predict stock price changes. It requires close prices and volume data as input. ```python import numpy as np import kand close = np.array([10.0, 12.0, 11.0, 13.0]) volume = np.array([100.0, 150.0, 120.0, 200.0]) result = kand.obv(close, volume) print(result) ``` -------------------------------- ### Replace unwrap with safe conversion Source: https://kand-ta.github.io/kand/changelog This entry replaces the use of 'unwrap' with safe conversion using 'ok_or(KandError::ConversionError)?' for error handling. ```rust # _(var)_ Replace unwrap with safe conversion using ok_or(KandError::ConversionError)? ``` -------------------------------- ### Calculate ADXR Incrementally Source: https://kand-ta.github.io/kand/api Calculates the latest ADXR value incrementally. It requires current and previous price data, previous ADX, smoothed DM, and smoothed TR values, along with the calculation period. ```Python import kand adxr, adx, plus_dm, minus_dm, tr = kand.adxr_inc( 24.20, # high 23.85, # low 24.07, # prev_high 23.72, # prev_low 23.95, # prev_close 25.0, # prev_adx 20.0, # prev_adx_period_ago 0.5, # prev_smoothed_plus_dm 0.3, # prev_smoothed_minus_dm 1.2, # prev_smoothed_tr 14 # period ) ``` -------------------------------- ### Add changelog CI Source: https://kand-ta.github.io/kand/changelog This entry adds CI functionality for managing the changelog. ```ci # _(ci)_ Add changelog ci. ``` -------------------------------- ### Detect Doji Candlestick Patterns Source: https://kand-ta.github.io/kand/api Detects Doji candlestick patterns in price data. It takes open, high, low, and close prices, along with parameters for body size and shadow equality percentages. Returns an array of pattern signals. ```Python import numpy as np import kand >>> open = np.array([10.0, 10.5, 10.2]) >>> high = np.array([11.0, 11.2, 10.8]) >>> low = np.array([9.8, 10.1, 9.9]) >>> close = np.array([10.3, 10.4, 10.25]) >>> signals = kand.cdl_doji(open, high, low, close, 5.0, 100.0) ``` -------------------------------- ### Calculate VWAP using High, Low, Close, and Volume Source: https://kand-ta.github.io/kand/api Calculates the Volume Weighted Average Price (VWAP) for a series of price data. It requires high, low, close prices, and volume as 1-D NumPy arrays. The function returns VWAP values, cumulative price-volume products, and cumulative volumes. ```Python import numpy as np import kand high = np.array([10.0, 12.0, 15.0]) low = np.array([8.0, 9.0, 11.0]) close = np.array([9.0, 10.0, 12.0]) volume = np.array([100.0, 150.0, 200.0]) vwap, cum_pv, cum_vol = kand.vwap(high, low, close, volume) ``` -------------------------------- ### Calculate Typical Price Incrementally Source: https://kand-ta.github.io/kand/api Calculates a single Typical Price value incrementally using the high, low, and close prices of the current period. Typical Price is often used as an intermediate step in calculating other indicators. ```python import kand typ_price = kand.typprice_inc(24.20, 23.85, 23.89) print(typ_price) ``` -------------------------------- ### Optimize precision conversion with T::from Source: https://kand-ta.github.io/kand/changelog This bug fix optimizes precision conversion by replacing the 'as' keyword with 'T::from' for improved type safety. ```rust # _(aroonosc)_ Optimize precision conversion by replacing 'as' with 'T::from' for safety ``` -------------------------------- ### Calculate Expanded Camarilla Levels (ECL) with NumPy Source: https://kand-ta.github.io/kand/api Computes the Expanded Camarilla Levels (ECL) for multiple support and resistance levels using NumPy arrays for high, low, and close prices. The function returns ten arrays corresponding to H5, H4, H3, H2, H1, L1, L2, L3, L4, and L5 levels, with the first element of each array being NaN. ```Python import numpy as np import kand high = np.array([24.20, 24.07, 24.04, 23.87, 23.67]) low = np.array([23.85, 23.72, 23.64, 23.37, 23.46]) close = np.array([23.89, 23.95, 23.67, 23.78, 23.50]) h5,h4,h3,h2,h1,l1,l2,l3,l4,l5 = kand.ecl(high, low, close) ``` -------------------------------- ### Calculate Momentum Incrementally (MOM Inc) Source: https://kand-ta.github.io/kand/api Provides an incremental calculation for the Momentum (MOM) indicator. This function is optimized for streaming data, requiring only the current price and the price from 'n' periods ago to compute the latest MOM value. ```Python import kand momentum = kand.mom_inc(10.0, 6.0) print(momentum) 4.0 ``` -------------------------------- ### Incrementally Calculate Expanded Camarilla Levels (ECL) Source: https://kand-ta.github.io/kand/api Computes the latest Expanded Camarilla Levels (ECL) values incrementally, providing an efficient method for updating ECL calculations without reprocessing historical data. This function takes the previous period's high, low, and close prices as input and returns a tuple of ten ECL values. ```Python import kand h5,h4,h3,h2,h1,l1,l2,l3,l4,l5 = kand.ecl_inc(24.20, 23.85, 23.89) ``` -------------------------------- ### Incrementally Calculate TRIX Source: https://kand-ta.github.io/kand/api Calculates a single new TRIX value incrementally, improving efficiency by reusing previous EMA calculations. It requires the current price, previous EMA values (EMA1, EMA2, EMA3), and the calculation period. ```Python import kand trix, ema1, ema2, ema3 = kand.trix_inc( 100.0, # price 98.0, # prev_ema1 97.0, # prev_ema2 96.0, # prev_ema3 14 # period ) ``` -------------------------------- ### Calculate Williams %R Incrementally Source: https://kand-ta.github.io/kand/api Incrementally calculates Williams %R using previous period's data. This optimized function takes previous highest high, lowest low, high, low, and current close, high, low prices to compute the current Williams %R value, along with the updated highest high and lowest low for the next period. ```Python import kand willr, high, low = kand.willr_inc(15.0, 10.0, 14.0, 11.0, 12.0, 13.0, 11.0) ``` -------------------------------- ### Detect Gravestone Doji Candlestick Patterns Source: https://kand-ta.github.io/kand/api Detects Gravestone Doji candlestick patterns in historical price data. Requires opening, high, low, and closing prices, along with a body percentage threshold. Returns signals indicating pattern detection. ```Python import numpy as np import kand open = np.array([100.0, 101.0, 102.0]) high = np.array([102.0, 103.0, 104.0]) low = np.array([98.0, 99.0, 100.0]) close = np.array([101.0, 102.0, 103.0]) signals = kand.cdl_gravestone_doji(open, high, low, close, 5.0) ``` -------------------------------- ### Detect Doji Pattern Incrementally Source: https://kand-ta.github.io/kand/api Detects a Doji candlestick pattern in a single candlestick. This function requires the open, high, low, and close prices, along with body and shadow percentage parameters. Returns a signal value. ```Python import kand >>> signal = kand.cdl_doji_inc(10.0, 11.0, 9.8, 10.3, 5.0, 100.0) ``` -------------------------------- ### Calculate Aroon Incrementally Source: https://kand-ta.github.io/kand/api Calculates the next Aroon values incrementally. This function updates Aroon Up, Aroon Down, highest/lowest prices, and days since high/low based on current and previous period data. ```Python import kand aroon_up, aroon_down, new_high, new_low, days_high, days_low = kand.aroon_inc( 15.0, # high 12.0, # low 14.0, # prev_high 11.0, # prev_low 2, # days_since_high 1, # days_since_low 14 # period ) ``` -------------------------------- ### Calculate Bollinger Bands Source: https://kand-ta.github.io/kand/api Calculates Bollinger Bands for a NumPy array, including upper, middle, and lower bands, SMA, variance, sum, and sum of squares. It requires price data, period, and standard deviation multipliers for upper and lower bands. Returns seven arrays with initial NaN values. ```Python import numpy as np import kand price = np.array([10.0, 11.0, 12.0, 13.0, 14.0]) upper, middle, lower, sma, var, sum, sum_sq = kand.bbands(price, 3, 2.0, 2.0) ``` -------------------------------- ### Replace as f64 with f64::from for type conversion Source: https://kand-ta.github.io/kand/changelog This refactoring replaces direct type casting using 'as f64' with the safer 'f64::from(u8::try_from(i).unwrap())' for type conversion. ```rust # _(tpo)_ Replace as f64 with f64::from(u8::try_from(i).unwrap()) for type conversion ``` -------------------------------- ### Detect Marubozu Pattern in Single Candlestick (Kand) Source: https://kand-ta.github.io/kand/api Detects a Marubozu pattern in a single candlestick. It takes OHLC prices, previous body average, EMA period, and maximum shadow percentage as input. Returns a signal (1.0 for bullish, -1.0 for bearish, 0.0 for none) and the updated EMA of body sizes. ```Python import kand signal, body_avg = kand.cdl_marubozu_inc(100.0, 102.0, 98.0, 100.1, 0.5, 14, 5.0) ``` -------------------------------- ### Calculate NATR Incrementally Source: https://kand-ta.github.io/kand/api Calculates the next NATR value incrementally using previous ATR and current price data. This function optimizes the calculation by avoiding a full series recalculation. ```python import kand natr = kand.natr_inc( 15.0, # high 11.0, # low 14.0, # close 12.0, # prev_close 3.0, # prev_atr 3 # period ) ``` -------------------------------- ### Detect Marubozu Candlestick Patterns (Kand) Source: https://kand-ta.github.io/kand/api Detects Marubozu candlestick patterns (Bullish and Bearish) in price data. It requires OHLC prices, EMA period, and maximum shadow percentage. Returns pattern signals (1.0 for bullish, -1.0 for bearish, 0.0 for none) and EMA values of body sizes. ```Python import numpy as np import kand open = np.array([100.0, 101.0, 102.0]) high = np.array([102.0, 103.0, 104.0]) low = np.array([98.0, 99.0, 100.0]) close = np.array([101.0, 102.0, 103.0]) signals, body_avg = kand.cdl_marubozu(open, high, low, close, 14, 5.0) ``` -------------------------------- ### Calculate CCI Incrementally Source: https://kand-ta.github.io/kand/api Calculates the next Commodity Channel Index (CCI) value incrementally. This function requires the previous SMA of typical prices, new and old high, low, and close prices, the period, and a buffer of typical prices. ```Python import kand >>> prev_sma_tp = 100.0 >>> new_high = 105.0 >>> new_low = 95.0 >>> new_close = 100.0 >>> old_high = 102.0 >>> old_low = 98.0 >>> old_close = 100.0 >>> period = 14 >>> tp_buffer = [100.0] * period >>> next_cci = kand.cci_inc(prev_sma_tp, new_high, new_low, new_close, ... old_high, old_low, old_close, period, tp_buffer) ``` -------------------------------- ### Detect Single Gravestone Doji Candlestick Pattern Source: https://kand-ta.github.io/kand/api Detects a Gravestone Doji pattern in a single candlestick. Takes opening, high, low, and closing prices, along with a body percentage threshold. Returns a signal value indicating pattern detection. ```Python import kand signal = kand.cdl_gravestone_doji_inc(100.0, 102.0, 98.0, 100.1, 5.0) ``` -------------------------------- ### Calculate TEMA Incrementally Source: https://kand-ta.github.io/kand/api Calculates the next TEMA value incrementally, processing the latest price and previous EMA values. It returns the current TEMA and updated EMA values. ```Python import kand tema, ema1, ema2, ema3 = kand.tema_inc( 10.0, # new_price 9.0, # prev_ema1 8.0, # prev_ema2 7.0, # prev_ema3 3 # period ) ``` -------------------------------- ### Calculate ATR Incrementally Source: https://kand-ta.github.io/kand/api Calculates the next Average True Range (ATR) value incrementally. It requires current high/low prices, previous close price, previous ATR value, and the lookback period. Returns the calculated ATR value. ```Python import kand atr = kand.atr_inc( 15.0, # high 11.0, # low 12.0, # prev_close 3.0, # prev_atr 14 # period ) ``` -------------------------------- ### Calculate ROCP Incrementally Source: https://kand-ta.github.io/kand/api The rocp_inc function calculates a single ROCP value incrementally, designed for streaming data scenarios. It takes the current price and the price from n periods ago as input. ```python import kand rocp = kand.rocp_inc(11.5, 10.0) print(rocp) ``` -------------------------------- ### Incrementally calculate ADX Source: https://kand-ta.github.io/kand/api Calculates the latest ADX value incrementally, requiring previous period's data. This function is useful for real-time calculations. It takes current and previous high, low, close prices, along with previous ADX and smoothed DM/TR values, and the calculation period. It returns the new ADX, smoothed +DM, smoothed -DM, and smoothed TR. ```Python import kand adx, plus_dm, minus_dm, tr = kand.adx_inc( 24.20, # current high 23.85, # current low 24.07, # previous high 23.72, # previous low 23.95, # previous close 25.0, # previous ADX 0.5, # previous smoothed +DM 0.3, # previous smoothed -DM 1.2, # previous smoothed TR 14 # period ) ``` -------------------------------- ### Detect Single Hammer Candlestick Pattern Source: https://kand-ta.github.io/kand/api Detects a Hammer pattern in a single candlestick. Takes opening, high, low, and closing prices, the previous EMA value of body sizes, a period for EMA calculation, and a factor for shadow to body ratio. Returns the signal value and the updated EMA value. ```Python import kand signal, body_avg = kand.cdl_hammer_inc(100.0, 102.0, 98.0, 100.1, 0.5, 14, 2.0) ``` -------------------------------- ### Calculate Triangular Moving Average (TRIMA) Source: https://kand-ta.github.io/kand/api Calculates the Triangular Moving Average (TRIMA) for a given series of prices. TRIMA is a double-smoothed moving average that emphasizes the middle of the price series. It requires input prices and a smoothing period. ```Python import numpy as np import kand prices = np.array([1.0, 2.0, 3.0, 4.0, 5.0]) sma1, trima = kand.trima(prices, 3) ``` -------------------------------- ### Calculate Momentum (MOM) Source: https://kand-ta.github.io/kand/api Computes the Momentum (MOM) indicator, which measures the price change over a specified period. It takes a NumPy array of price data and a lookback period, returning MOM values with leading NaNs. ```Python import numpy as np import kand data = np.array([2.0, 4.0, 6.0, 8.0, 10.0]) result = kand.mom(data, 2) print(result) [nan, nan, 4.0, 4.0, 4.0] ``` -------------------------------- ### Detect Hammer Candlestick Patterns Source: https://kand-ta.github.io/kand/api Detects Hammer candlestick patterns in historical price data. Requires opening, high, low, and closing prices, a period for EMA calculation, and a factor for shadow to body ratio. Returns pattern signals and EMA values of candle body sizes. ```Python import numpy as np import kand open = np.array([100.0, 101.0, 102.0]) high = np.array([102.0, 103.0, 104.0]) low = np.array([98.0, 99.0, 100.0]) close = np.array([101.0, 102.0, 103.0]) signals, body_avg = kand.cdl_hammer(open, high, low, close, 14, 2.0) ``` -------------------------------- ### Compute True Range (TR) Source: https://kand-ta.github.io/kand/api Computes the True Range (TR) over NumPy arrays, measuring market volatility by considering the current high-low range and the previous close price. ```Python import numpy as np import kand high = np.array([10.0, 12.0, 15.0]) low = np.array([8.0, 9.0, 11.0]) close = np.array([9.0, 11.0, 14.0]) result = kand.trange(high, low, close) print(result) ``` -------------------------------- ### Calculate Midpoint Incrementally Source: https://kand-ta.github.io/kand/api Calculates the next Midpoint value incrementally, offering an optimized method for updating the Midpoint value with new data without a full series recalculation. It requires the current price, previous highest and lowest values, and the time period. ```Python import kand midpoint, new_highest, new_lowest = kand.midpoint_inc( 15.0, # current price 16.0, # previous highest 14.0, # previous lowest 14 # period ) ``` -------------------------------- ### Calculate Plus DM Incrementally with Kand Source: https://kand-ta.github.io/kand/api The plus_dm_inc function calculates the next Plus DM value incrementally using previous values and current price data. This allows for real-time calculation without recalculating the entire series. It returns the latest Plus DM value. ```Python import kand new_plus_dm = kand.plus_dm_inc( 10.5, # high 10.0, # prev_high 9.8, # low 9.5, # prev_low 0.45, # prev_plus_dm 14 # period ) ``` -------------------------------- ### Calculate Midpoint Price Incrementally Source: https://kand-ta.github.io/kand/api Calculates the next Midpoint Price value incrementally, providing an optimized way to update the indicator when new data arrives without recalculating the entire series. It requires the current high and low prices, previous highest and lowest values, and the time period. ```Python import kand midprice, new_highest, new_lowest = kand.midprice_inc( 10.5, # current high 9.8, # current low 10.2, # previous highest high 9.5, # previous lowest low 14 # period ) ``` -------------------------------- ### Incrementally Calculate Simple Moving Average (SMA) Source: https://kand-ta.github.io/kand/api Incrementally calculates the next SMA value without recalculating the entire series. This function takes the previous SMA, new price, old price, and the period to efficiently update the SMA. ```Python import kand prev_sma = 4.0 new_price = 10.0 old_price = 2.0 period = 3 next_sma = kand.sma_inc(prev_sma, new_price, old_price, period) print(next_sma) ``` -------------------------------- ### Calculate Latest Accumulation/Distribution (A/D) Value Incrementally Source: https://kand-ta.github.io/kand/api Computes the latest Accumulation/Distribution (A/D) value incrementally. This function is efficient as it only calculates the newest A/D value using the previous A/D value, avoiding a full series recalculation. It takes the latest price and volume data along with the previous A/D value. ```Python import kand high = 15.0 low = 11.0 close = 13.0 volume = 200.0 prev_ad = 25.0 result = kand.ad_inc(high, low, close, volume, prev_ad) print(result) ``` -------------------------------- ### Calculate Simple Moving Average (SMA) Source: https://kand-ta.github.io/kand/api Computes the Simple Moving Average (SMA) over a NumPy array. It calculates the arithmetic mean of a window of values that moves across the input array. Requires input data and a period for the window size. ```Python import numpy as np import kand data = np.array([1.0, 2.0, 3.0, 4.0, 5.0]) result = kand.sma(data, 3) print(result) ``` -------------------------------- ### Calculate Aroon Indicator Source: https://kand-ta.github.io/kand/api Calculates the Aroon indicator using high and low prices over a specified period. The indicator helps identify trend beginnings and reversals. It returns Aroon Up, Aroon Down, and related historical values. ```Python import numpy as np import kand high = np.array([10.0, 12.0, 15.0, 14.0, 13.0]) low = np.array([8.0, 9.0, 11.0, 10.0, 9.0]) aroon_up, aroon_down, prev_high, prev_low, days_high, days_low = kand.aroon(high, low, 3) ``` -------------------------------- ### Calculate RSI incrementally Source: https://kand-ta.github.io/kand/api Calculates a single RSI value incrementally. This function provides an optimized way to calculate the latest RSI value when streaming data is available, without needing the full price history. ```Python import kand rsi, avg_gain, avg_loss = kand.rsi_inc(45.42, 45.10, 0.24, 0.14, 14) ``` -------------------------------- ### Suppress Clippy warnings for expect_used Source: https://kand-ta.github.io/kand/changelog This entry adds #[allow(clippy::expect_used)] to suppress Clippy warnings related to the use of 'expect'. ```rust # _(bench)_ Added #[allow(clippy::expect_used)] to suppress clippy warnings ``` -------------------------------- ### Compute Plus Directional Indicator (+DI) Source: https://kand-ta.github.io/kand/api Computes the Plus Directional Indicator (+DI) over NumPy arrays. +DI measures the strength of an upward price trend and is used in ADX calculation. It requires high, low, close prices, and a period. ```python import numpy as np import kand high = np.array([10.0, 12.0, 11.5, 11.0]) low = np.array([9.0, 10.0, 10.0, 9.5]) close = np.array([9.5, 11.0, 10.5, 10.0]) plus_di, smoothed_plus_dm, smoothed_tr = kand.plus_di(high, low, close, 2) ``` -------------------------------- ### Detect Inverted Hammer Candlestick Pattern (Kand) Source: https://kand-ta.github.io/kand/api Detects an Inverted Hammer candlestick pattern. It takes OHLC prices, previous body average, EMA period, and shadow-to-body ratio as input. Returns a signal (100 for bullish, 0 for no pattern) and the updated EMA of body sizes. ```Python import kand signal, body_avg = kand.cdl_inverted_hammer_inc(100.0, 102.0, 98.0, 100.1, 0.5, 14, 2.0) ``` -------------------------------- ### Detect Long Shadow Pattern in Single Candlestick (Kand) Source: https://kand-ta.github.io/kand/api Detects a Long Shadow pattern in a single candlestick. It takes OHLC prices, previous body average, EMA period, and shadow factor as input. Returns a signal (100 for bullish lower, -100 for bearish upper, 0 for none) and the updated EMA of body sizes. ```Python import kand signal, body_avg = kand.cdl_long_shadow_inc(100.0, 102.0, 98.0, 100.1, 0.5, 14, 75.0) ```