Skip to main content

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:

  1. Sticks (Stick)
  2. Fractals (Fractal)
  3. Strokes (Stroke)
  4. Segments (Segment)
  5. Pivots (Pivot)
  6. 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 Source class.
  • 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 Source class 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 .SZ or .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

pychanlun-0.1.6.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pychanlun-0.1.6-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file pychanlun-0.1.6.tar.gz.

File metadata

  • Download URL: pychanlun-0.1.6.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for pychanlun-0.1.6.tar.gz
Algorithm Hash digest
SHA256 b040a279e4d9b7f68c92030c5e5259822883d1d1f30f8bed1378ac740950967d
MD5 ec92eb2a41154c1738cf1a648d343155
BLAKE2b-256 4d2a235fff53957cfc60d6eeac440ee92ac06596e9a74ff80061fa669f4d753d

See more details on using hashes here.

File details

Details for the file pychanlun-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: pychanlun-0.1.6-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

Hashes for pychanlun-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 31c665d736519c09dd79f49e90d481e953662e79bcb02d8376913122257e267b
MD5 5daa113672772af59bf35806a9379596
BLAKE2b-256 a23e054f2c7d45a82b0aa28f1f9eaf927cfa144a2d81ef6b9efe9de2b6523172

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page