Skip to main content

Support Resistance Line

pypi

Installation

You can install from pypi using pip install support_resistance_line, or install from source using python3 setup.py install

How to Use

One-Liner

SupportResistanceLine(pd.Series(some_data)).plot_both()

example

Runnable Example

import numpy as np
import pandas as pd
from support_resistance_line import SupportResistanceLine


# Generate a random series
sr = pd.Series(np.random.random(size=250))
# ... moving avg to make it more trending
sr = sr.rolling(50).mean().dropna()

# Init. Index will be ignored
srl = SupportResistanceLine(sr, kind='support')

# Plot the best 3 support lines
srl.plot_top_lines()
# Plot the best 3 resistance lines
srl.twin.plot_top_lines()

# Plot the best support & resistance lines
srl.plot_both()

# View the logic steps if you want
srl.plot_steps()

Incentive

支撑线(support line)又称为抵抗线。当股价跌到某个价位附近时,股价停止下跌,甚至有可能还有回升,这是因为多方在此买入造成的。支撑线起阻止股价继续下跌的作用。这个起着阻止股价继续下跌或暂时阻止股价继续下跌的位置就是支撑线所在的位置。

压力线(resistance line)又称为阻力线。当股价上涨到某价位附近时,股价会停止上涨,甚至回落,这是因为空方在此抛出造成的。压力线起阻止股价继续上升的作用。这个起着阻止或暂时阻止股价继续上升的位置就是压力线所在的位置。

因为支撑线压力线的定义不够精确,有较强的主观差异,所以不同的人在同一条时间序列数据上可能会作出完全不同的支撑线压力线。

这里我们采用精确的数学算法来绘制支撑线压力线。

这套算法主要有四个步骤:多项式拟合、寻找极值、聚类分析、图像绘制。

Logic

1.多项式拟合

这里以30分之一序列长度作为窗口的移动平均线作为参考线,从项数取40分之一时间序列长度开始迭代,整体误差在移动平均线的0.6倍以内时停止迭代。

2.遍历多项式曲线取极值

不管画支撑线还是压力线都同时计算极大值和极小值。极值的计算采用一阶导数取零点、二阶导数区分的方式。以支撑线为例,遍历极小值,以任意一个极小值两边的极大值之内的区间,对原序列取最小值,作为支撑点。

3.邻近聚类

对极值聚类,把相距非常近的极值剔除。

4.找线

从最后一个支撑点出发,和其之前的所有支撑点连线。对斜率用Kmeans聚类,每类取最下方一条线,该类点个数为,该类所有点到该直线的平均距离为,该类所有点的横坐标标准差为,平均值为,评分公式为

最终线为所有聚类的线评分最小的。 对序列后四分之一的所有支撑点遍历以上过程,寻找最好的线。

Demo

Demo

Metadata

Release files for support-resistance-line 0.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for support-resistance-line 0.0.7
File Size Uploaded Provenance Actions
support_resistance_line-0.0.7.tar.gz 10.1 kB Without provenance Details for support_resistance_line-0.0.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for support-resistance-line 0.0.7
File Interpreter ABI Platform Actions
support_resistance_line-0.0.7-py3-none-any.whl Python 3 none any Details for support_resistance_line-0.0.7-py3-none-any.whl

Total release size: 19.1 kB

Release files / support_resistance_line-0.0.7.tar.gz

Download URL support_resistance_line-0.0.7.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
abe09b70415bebf5d6277106feba437934ab4a89575cfe06ecf0a864162382b7
BLAKE2b-256 checksum
How to use checksums
0ea422d8de545100fbc3116f2a5aa218d592b36a86629b19d6d739a2975397fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

Release files / support_resistance_line-0.0.7-py3-none-any.whl

Download URL support_resistance_line-0.0.7-py3-none-any.whl
Size 9.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c49d5f207977ab1886e9bdfd33b59da6a31de2fec6c3306e9e1dee0192492a0b
BLAKE2b-256 checksum
How to use checksums
e8a1d41336cac5a562b6c8de85bdf006e6706ffe47572fd59a3fb23166bf12ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

Security for support-resistance-line 0.0.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page