Applying the Chan Theory (Chan Lun) to analyze stock trading information.
Project description
PyChanLun
Applying the Chan Theory (Chan Lun) to analyze stock trading information.
What is PyChanLun?
PyChanLun is a Python library designed to perform technical analysis on stock market data using the principles of Chan Theory.
It implements a hierarchical structure of core Chan Theory concepts, starting from raw price data and building up through:
- Sticks (
Stick) - Fractals (
Fractal) - Strokes (
Stroke) - Segments (
Segment) - Pivots (
Pivot) - Signals (
Signal)
The library processes time-series data to identify key structural components and generate trading-related data like pivots, trend levels, and trading signals, combining price action with indicators like MACD.
Where is the data coming from?
PyChanLun uses the yfinance library to download historical stock data.
- The data acquisition logic is encapsulated in the
Sourceclass. - It fetches OHLCV (Open, High, Low, Close, Volume) data for a given stock symbol across various time intervals (
1m,5m,30m,1d,1wk,1mo). - The
Sourceclass also calculates common technical indicators like Moving Averages (MA), MACD (Moving Average Convergence Divergence), and Bollinger Bands (BB) on the raw data. - Special handling is included for filtering trading hours for Chinese stock markets (symbols ending in
.SZor.SS) for intraday intervals.
What data does PyChanLun create?
PyChanLun generates several layers of processed data based on the original OHLCV information, with the main entry point being the Chan class, which acts as a data retriever.
| Data Type | Class/Method | Description |
|---|---|---|
| Sources | Chan.get_sources() |
Raw OHLCV data with MA, MACD, BB calculated. |
| Sticks | Chan.get_sticks() |
Chan Theory (Chan Lun) stick data (Stick class). Columns: date, top (high) and bottom (low). |
| Fractals | Chan.get_fractals() |
Top fractal and bottom fractal data (Fractal class). Columns: date, top (high) and bottom (low). |
| Strokes | Chan.get_strokes() |
Constructed stroke data (Stroke class). Column: date, stroke. |
| Segments | Chan.get_segments() |
Constructed segment data (Segment class), a higher level of structural grouping. Column: date, segment. |
| Pivots (Stroke/Segment) | Chan.get_stroke_pivots() Chan.get_segment_pivots() |
Identified pivot (Pivot class) data based on the stroke or segment data. Columns: entry, exit, high, low , entry MACD, exit MACD, trend level, and divergence status. |
| Trends (Stroke/Segment) | Chan.get_stroke_pivot_trends() Chan.get_segment_pivot_trends() |
Pivot trend data (Trend class) summarizing the price movement between alternating pivots. Columns: entry, exit, entry price, exit price. |
| Signals (Stroke/Segment) | Chan.get_stroke_pivot_signals() Chan.get_segment_pivot_signals() |
Trading signal data (Signal class) generated based on the pivots and MACD divergence. Columns: date, price and signal. |
How to use PyChanLun?
The primary way to interact with PyChanLun is through the Chan class, providing a unified interface to access all generated data for a specific stock symbol.
1. Initialization
Instantiate the Chan object with the stock symbol and source data you want to analyze. It will trigger structural analysis across all time intervals of the source data (1m, 5m, 30m, 1d, 1wk, 1mo).
from pychanlun.chan import Chan
# Initialize the Chan object for Apple (AAPL)
chan = Chan('AAPL', source)
2. Accessing Data
Use the various get_* methods, specifying the desired time interval as a string argument (e.g., 1m, 1d). The methods return a Pandas DataFrame containing the analyzed data.
# Get the Stick data for the 1-minute interval
sticks_df = chan.get_sticks('1m')
print("Sticks Data (1m):\n", sticks_df.head())
# Get the Stroke Pivot data for the 30-minute interval
stroke_pivots_df = chan.get_stroke_pivots('30m')
print("\nStroke Pivots (30m):\n", stroke_pivots_df.head())
# Get Segment-level trading signals for the 1-day interval
segment_signals_df = chan.get_segment_pivot_signals('1d')
print("\nSegment Signals (1d):\n", segment_signals_df.head())
Project details
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pychanlun-0.1.5.tar.gz.
File metadata
- Download URL: pychanlun-0.1.5.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a6ebffa3246d1b397c32aac5f6263ba7e0513f32a5867faab97fcaf52ecc601
|
|
| MD5 |
8c849ed26e5fb7b1a00d3da3b7f08068
|
|
| BLAKE2b-256 |
3e29c0e2149262ada8636c9210d0b3fdd6970825df5c9bd4ecb3995b2ed68418
|
File details
Details for the file pychanlun-0.1.5-py3-none-any.whl.
File metadata
- Download URL: pychanlun-0.1.5-py3-none-any.whl
- Upload date:
- Size: 13.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef46b57d57e2a7eb93487120a696b62e81c5e949bcbd6435a2a2cb515ea16ad1
|
|
| MD5 |
65d3cdc0cbe14598bdf4c4835a18c0d0
|
|
| BLAKE2b-256 |
134c18f74d2773dae173bb07c7f3154bda0d10b8b380ab6cc119d210079b1f30
|