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: datetime, high, low.
Fractals Chan.get_fractals() Top fractal and bottom fractal data (Fractal class).
Columns: datetime, high, low.
Strokes Chan.get_strokes() Constructed stroke data (Stroke class).
Column: datetime, stroke.
Segments Chan.get_segments() Constructed segment data (Segment class), a higher level of structural grouping.
Column: datetime, 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: datetime, end, high, low , level, and 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: datetime, end, open, close.
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: datetime, stroke (or segment) 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.7.tar.gz (10.3 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.7-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pychanlun-0.1.7.tar.gz
  • Upload date:
  • Size: 10.3 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.7.tar.gz
Algorithm Hash digest
SHA256 eedf71db1571ac9900e497d0fea627ec9c2169f8369503a40bb08c0b36404adc
MD5 76624861843d6f84f350f937ffa54452
BLAKE2b-256 64f027652fe5a528394d69b79a1daa8892539d9d822bb9691cfd35661757eaa7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pychanlun-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 13.3 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.7-py3-none-any.whl
Algorithm Hash digest
SHA256 f6a9a95cefc173a02d00463cae60d3d21677343c5b28aee0673be57ff9c6f72e
MD5 72f91956ca53769199008188571ecac6
BLAKE2b-256 bc16f128a165f3cbd0f7461593a7b942fcf652840074eedd41913f72ba469017

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