TA library for Pandas
Project description
bamboo-ta
The Bamboo TA Indicators module provides a comprehensive suite of technical analysis tools for trading. This module imports various submodules, each dedicated to a specific category of technical indicators.
Installation
Stable version
Install bamboo-ta from Pypi with:
pip install bamboo-ta
Or you can install this directly from the Github repository with the following command:
$ pip install -U git+https://github.com/DutchCryptoDad/bamboo-ta
Development version
The bleeding edge development version can be installed with:
$ pip install -U git+https://github.com/DutchCryptoDad/bamboo-ta.git@development
How to Use This Module
Using the complete module all at once.
-
Importing the complete library: Import the library into your Python scripts or Notebook.
import bamboo_ta as bta
-
Applying Indicators: Use the imported indicators on your data.
df['lsma'] = bta.calculate_lsma(df, 14)
Or individual indicators.
-
Importing Indicators: Import the necessary submodules or individual indicators directly from
bamboo_ta
.from bamboo_ta.trend import AlligatorBands, BollingerTrend, EMA, HMA, LSMA, SMA, WMA, ZLEMA
-
Applying Indicators: Use the imported indicators on your data.
result = AlligatorBands(df, "high", 13, 8, 5, jaw_shift=8, teeth_shift=5, lips_shift=3)
-
Combining Indicators: Combine multiple indicators for comprehensive analysis.
df['ema'] = EMA(df, "close", 21) df['sma'] = SMA(df, "close", 50)
Bamboo TA Indicators Module
Submodules
-
candles
- Description: Contains indicators related to candlestick patterns.
- Indicators:
- HeikinAshi: Heikin Ashi candlesticks with optional pre and post smoothing.
- Usage:
ha_df = HeikinAshi(df, pre_smoothing_period=14, post_smoothing_period=14) df['HA_Close'] = ha_df['HA_Close'] df['HA_Open'] = ha_df['HA_Open'] df['HA_High'] = ha_df['HA_High'] df['HA_Low'] = ha_df['HA_Low']
- Usage:
- LinRegCandles: Linear Regression Candles with optional signal line.
- Usage:
lr_df = LinRegCandles(df, linreg_length=11, sma_signal=True, signal_length=11) df['LRC_Open'] = lr_df['bopen'] df['LRC_High'] = lr_df['bhigh'] df['LRC_Low'] = lr_df['blow'] df['LRC_Close'] = lr_df['bclose'] df['LRC_Signal'] = lr_df['signal']
- Usage:
- HeikinAshi: Heikin Ashi candlesticks with optional pre and post smoothing.
-
cycles
- Description: Includes indicators for cycle analysis.
-
momentum
- Description: Provides momentum-based indicators.
- Indicators:
- EWO: Elliott Wave Oscillator.
- Usage:
df['ewo'] = EWO(df, "close", 5, 35)
- Usage:
- MACD: Moving Average Convergence Divergence.
- Usage:
macd_result = MACD(df, "close", 12, 26, 9) df['macd'] = macd_result['MACD'] df['macd_signal'] = macd_result['MACD_signal'] df['macd_histogram'] = macd_result['MACD_histogram']
- Usage:
- RSI: Relative Strength Index.
- Usage:
df['rsi'] = RSI(df, "close", 14)
- Usage:
- EWO: Elliott Wave Oscillator.
-
performance
- Description: Contains performance-related indicators.
-
statistics
- Description: Statistical indicators for trading analysis.
-
trend
- Description: Includes trend-based indicators.
- Indicators:
- AlligatorBands: Bill Williams Alligator Indicator.
- Usage:
alligator_result = AlligatorBands(df, "high", 13, 8, 5, jaw_shift=8, teeth_shift=5, lips_shift=3) df['jaw'] = alligator_result['jaw'] df['teeth'] = alligator_result['teeth'] df['lips'] = alligator_result['lips']
- Usage:
- BollingerTrend: Bollinger Trend Indicator.
- Usage:
df['BBTrend'] = BollingerTrend(df, "close", 20, 50, 2.0)
- Usage:
- BollingerTrendFastWithMA: Bollinger Trend Indicator with selectable Moving Average.
- Usage:
result = BollingerTrendFastWithMA(df, column="close", short_length=10, long_length=50, short_stddev=1.0, long_stddev=2.0, ma_type="SMA", ma_length=14) df['BBTrend'] = result['BBTrend'] df['BBTrendMA'] = result['BBTrendMA']
- Usage:
- EMA: Exponential Moving Average.
- Usage:
df['ema'] = EMA(df, "close", 21)
- Usage:
- HMA: Hull Moving Average.
- Usage:
df['hma'] = HMA(df, "close", 9)
- Usage:
- LSMA: Least Squares Moving Average.
- Usage:
df['lsma'] = LSMA(df, "close", 50)
- Usage:
- SMA: Simple Moving Average.
- Usage:
df['sma'] = SMA(df, "close", 50)
- Usage:
- WMA: Weighted Moving Average.
- Usage:
df['wma'] = WMA(df, "close", 9)
- Usage:
- ZLEMA: Zero Lag Exponential Moving Average.
- Usage:
df['zlema'] = ZLEMA(df, "close", 21)
- Usage:
- AlligatorBands: Bill Williams Alligator Indicator.
-
utility
- Description: Utility functions and helper methods for technical analysis.
-
volatility
- Description: Volatility indicators.
- Indicators:
- BollingerBands: Calculates Bollinger Bands (upper, middle, lower bands).
- Usage:
bb_result = BollingerBands(df, "close", 21, 2, 0) df['bb_upper'] = bb_result['BB_upper'] df['bb_middle'] = bb_result['BB_middle'] df['bb_lower'] = bb_result['BB_lower']
- Usage:
- BollingerBands: Calculates Bollinger Bands (upper, middle, lower bands).
-
volume
- Description: Indicators related to trading volume.
Practical example
Example script:
# -*- coding: utf-8 -*-
# Import necessary libraries
import pandas_ta as pta
import bamboo_ta as bta
import pandas as pd
from pandas import DataFrame
import numpy as np
# create dataframe and read the json data in the datasets directory
df = pd.read_json("./testdata/BTC_USDT-1d.json")
# name the columns that are loaded into the dataframe
df.columns = ['date', 'open', 'high', 'low', 'close', 'volume']
# the date column consists of unix time in milliseconds, so this command changes this data into human readable form.
df['date'] = (pd.to_datetime(df['date'], unit='ms'))
print(df) # This command outputs the dataframe
# Using the pandas_ta library
df['imi_ema'] = pta.ema(close=df['close'], length=7)
df['lsma'] = bta.calculate_lsma(df, 14) # Using the bamboo_ta library
print(df)
Output:
➜ python test.py
date open high low close volume
0 2017-08-17 4261.48 4485.39 4200.74 4285.08 795.150377
1 2017-08-18 4285.08 4371.52 3938.77 4108.37 1199.888264
2 2017-08-19 4108.37 4184.69 3850.00 4139.98 381.309763
3 2017-08-20 4120.98 4211.08 4032.62 4086.29 467.083022
4 2017-08-21 4069.13 4119.62 3911.79 4016.00 691.743060
... ... ... ... ... ... ...
1967 2023-01-05 16850.36 16879.82 16753.00 16831.85 163473.566410
1968 2023-01-06 16831.85 17041.00 16679.00 16950.65 207401.284150
1969 2023-01-07 16950.31 16981.91 16908.00 16943.57 104526.568800
1970 2023-01-08 16943.83 17176.99 16911.00 17127.83 135155.896950
1971 2023-01-09 17127.83 17398.80 17104.66 17178.26 266211.527230
[1972 rows x 6 columns]
date open high low close volume imi_ema lsma
0 2017-08-17 4261.48 4485.39 4200.74 4285.08 795.150377 NaN NaN
1 2017-08-18 4285.08 4371.52 3938.77 4108.37 1199.888264 NaN NaN
2 2017-08-19 4108.37 4184.69 3850.00 4139.98 381.309763 NaN NaN
3 2017-08-20 4120.98 4211.08 4032.62 4086.29 467.083022 NaN NaN
4 2017-08-21 4069.13 4119.62 3911.79 4016.00 691.743060 NaN NaN
... ... ... ... ... ... ... ... ...
1967 2023-01-05 16850.36 16879.82 16753.00 16831.85 163473.566410 16737.537534 16633.800286
1968 2023-01-06 16831.85 17041.00 16679.00 16950.65 207401.284150 16790.815651 16678.202286
1969 2023-01-07 16950.31 16981.91 16908.00 16943.57 104526.568800 16829.004238 16746.722286
1970 2023-01-08 16943.83 17176.99 16911.00 17127.83 135155.896950 16903.710678 16816.734571
1971 2023-01-09 17127.83 17398.80 17104.66 17178.26 266211.527230 16972.348009 16930.485143
[1972 rows x 8 columns]
Creating the Python pip package (personal notes)
After creating and testing the code, make a Python pip package as follows:
Update the file setup.py
and update version number.
In the library folder, create the package
python3 setup.py sdist bdist_wheel
Before uploading the package to Pypi it is wise to test the package on your system.
Load the package to the system with:
pip install .
After you've checked that everything is worknig correctly, then use the following command to upload to Pypi.
You'll have to install twine for this (pip install twine
or sudo apt install twine
).
# Check first
twine check dist/*
# Test upload first
twine upload -r testpypi dist/*
# Upload to Pypi
twine upload dist/*
Note: uploading new versions requires to delete the older versions from the /dist folder.
Another option is to use the --skip-existing
option like this:
twine upload -r --skip-existing testpypi dist/*
twine upload --skip-existing dist/*
Uploading with 2FA enabled
First create an API token (at https://test.pypi.org/manage/account/token/).
Create a file .pypirc in your home folder (e.g. nano $HOME/.pypirc
)
Add the given token to the file like this:
[testpypi]
username = __token__
password = pypi-AgENdalaljdljhdalkHTaddsdSQtMjBjOS00ZjgxLWIyZDMtYWViMDAwOTk3MWZmAAIqWzMsImU3YjkzMGVmLWQzMFmZkZCJdAAAGIB6NZ-rSrzc8UXj38ijwCRmZwkFLnhhNP
Save the file and reload environment if necessary.
Now you an upload libraries without having to use the password.
Other sources
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file bamboo-ta-0.0.5.tar.gz
.
File metadata
- Download URL: bamboo-ta-0.0.5.tar.gz
- Upload date:
- Size: 15.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b2315ef21d36b90166cada40e6379256dc74180f296913efb39c9bcb10524b8 |
|
MD5 | 56aced4d6eabd3cd020af9b70e215c4d |
|
BLAKE2b-256 | 1ba1701b7b2b24c6b3a35a1ebee3f31b3b76fb59dec1a6d0ddfdad77b7477130 |
File details
Details for the file bamboo_ta-0.0.5-py3-none-any.whl
.
File metadata
- Download URL: bamboo_ta-0.0.5-py3-none-any.whl
- Upload date:
- Size: 14.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b688226b94bfe0752faf2a138e80ed2a80c3ef4c162a071e097e84b613209a6 |
|
MD5 | ab288d105fbbd8902f3b735db407c3c4 |
|
BLAKE2b-256 | 3f20b8198cc944fdec51468ca1a250d5c37018b78bac53d198be6fcc71fceedf |