支撐阻力指標_使用k表示聚類以創建支撐和阻力

支撐阻力指標

Note from Towards Data Science’s editors: While we allow independent authors to publish articles in accordance with our rules and guidelines, we do not endorse each author’s contribution. You should not rely on an author’s works without seeking professional advice. See our Reader Terms for details.

Towards Data Science編輯的注意事項: 盡管我們允許獨立作者按照我們的 規則和指南 發表文章 ,但我們不認可每位作者的貢獻。 您不應在未征求專業意見的情況下依賴作者的作品。 有關 詳細信息, 請參見我們的 閱讀器條款

Support and resistance are some of the most talked-about concepts when it comes to technical analysis. Support and resistance are used as price barriers, in which the price “bounces” off of. In this article, I will use the K-means clustering algorithm to find these different support and resistance channels, and trade with these insights.

在技??術分析中,支撐和阻力是最受關注的概念。 支撐和阻力被用作價格壁壘,價格從中反彈。 在本文中,我將使用K-means聚類算法找到這些不同的支撐和阻力通道,并利用這些見解進行交易。

支撐和阻力: (Support and Resistance:)

To understand how best to implement something, we should first understand the thing that we want to implement.

要了解如何最好地實現某件事,我們應該首先了解我們想要實現的那件事。

Image for post
Self-drawn support and resistance levels. Image By Author
自繪支撐和阻力位。 圖片作者

Support and Resistance, are two lines that are drawn on a graph, to form a channel, in which the price exists within.

支撐線和阻力線是在圖形上繪制的兩條線,形成價格存在于其中的通道。

Support and resistance are resultant of a security not being able to decrease or increase anymore, due to pressure from sellers or buyers. A good rule of thumb is that the more times a price is deflected against a support or resistance line, the less likely it will work again.

支持和阻力是由于賣方或買方的壓力導致證券不再能夠減少或增加的結果。 一條好的經驗法則是,價格相對于支撐線或阻力線偏轉的次數越多,其再次發揮作用的可能性就越小。

Support and resistance give good insight into entry points and selling points, as the support and resistance lines are theoretically the lowest and highest points for that limited time period.

支撐位和阻力位可以很好地了解切入點和賣出點,因為理論上,支撐位和阻力位是該有限時間段內的最低和最高點。

Downsides of the support and resistance strategy is that it works for an unknown period of time, and the lines are subjective and are therefore subject to human error.

支持和抵抗策略的缺點是,它在未知的時間段內都可以正常工作,并且線路是主觀的,因此容易遭受人為錯誤的影響。

程序概念: (Program Concept:)

The K-means clustering algorithm, finds different sections of the time series data, and groups them into a defined number of groups. This number (K) can be optimized. The highest and lowest value of each group is then defined as the support and resistance values for the cluster.

K-均值聚類算法,查找時間序列數據的不同部分,并將其分組為定義的組數。 此數字(K)可以優化。 然后將每個組的最高和最低值定義為群集的支撐和阻力值。

Now that we know how the program is intended, let’s try to recreate it in Python!

現在我們知道了程序的意圖,讓我們嘗試在Python中重新創建它!

代碼: (The Code:)

import yfinance
df = yfinance.download('AAPL','2013-1-1','2020-1-1')
X = np.array(df['Close'])

This script is to access data for the Apple stock price. For this example, we are implementing the support and resistance only on the closing price.

該腳本用于訪問Apple股票價格的數據。 對于此示例,我們僅對收盤價實施支撐和阻力。

from sklearn.cluster import KMeans
import numpy as np
from kneed import DataGenerator, KneeLocator
sum_of_squared_distances = []
K = range(1,15)
for k in K:
km = KMeans(n_clusters=k)
km = km.fit(X.reshape(-1,1))
sum_of_squared_distances.append(km.inertia_)
kn = KneeLocator(K, sum_of_squared_distances,S=1.0, curve="convex", direction="decreasing")
kn.plot_knee()
# plt.plot(sum_of_squared_distances)

This script is to test the different values of K to find the best value:

該腳本用于測試K的不同值以找到最佳值:

Image for post

The K-value of 2 creates support and resistance lines that will never be reached for a long time.

K值2會創建支撐線和阻力線,這些支撐線和阻力線將永遠不會達到。

Image for post

A K-value of 9 creates support and resistance that are far too common and make it difficult to make predictions.

K值為9時會產生太常見的支撐和阻力,因此很難進行預測。

Therefore, we have to find the best value of K, calculated by the elbow point when comparing variance between K values. The elbow point is the biggest improvement, given a certain movement.

因此,當比較K值之間的方差時,我們必須找到由彎頭計算出的K的最佳值。 給定一定的移動量,肘點是最大的改善。

Image for post

Based on the kneed library, the elbow point is at 4. This means that the optimum K value is 4.

根據膝蓋庫,肘點為4。這意味著最佳K值為4。

kmeans = KMeans(n_clusters= kn.knee).fit(X.reshape(-1,1))
c = kmeans.predict(X.reshape(-1,1))
minmax = []
for i in range(kn.knee):
minmax.append([-np.inf,np.inf])
for i in range(len(X)):
cluster = c[i]
if X[i] > minmax[cluster][0]:
minmax[cluster][0] = X[i]
if X[i] < minmax[cluster][1]:
minmax[cluster][1] = X[i]

This script finds the minimum and maximum value for the points that reside in each cluster. These, when plotted, become the support and resistance lines.

該腳本查找每個群集中的點的最小值和最大值。 當繪制這些線時,它們將成為支撐線和阻力線。

from matplotlib import pyplot as plt
for i in range(len(X)):
colors = ['b','g','r','c','m','y','k','w']
c = kmeans.predict(X[i].reshape(-1,1))[0]
color = colors[c]
plt.scatter(i,X[i],c = color,s = 1)for i in range(len(minmax)):
plt.hlines(minmax[i][0],xmin = 0,xmax = len(X),colors = 'g')
plt.hlines(minmax[i][1],xmin = 0,xmax = len(X),colors = 'r')

This script plots the support and resistance, along with the actual graph of the prices, which are color coded based on the cluster. Unfortunately, I think that the colors are limited, meaning that there is a limited K value in which the data can be color coded.

該腳本繪制了支撐和阻力以及價格的實際圖形,這些圖形根據集群進行了顏色編碼。 不幸的是,我認為顏色是有限的,這意味著可以對數據進行顏色編碼的K值有限。

Image for post

This is the result of the program, a set of support and resistance lines. Keep in mind that the lines are most accurate, when the values fall back into the channel. Additionally, the final resistance line would be the least accurate ,as it takes the last value into account, without considering any other values.

這是程序的結果,是一組支撐線和阻力線。 請記住,當值回落到通道中時,線條最準確。 另外,最終的阻力線將是最不準確的,因為它將最后一個值考慮在內,而不考慮任何其他值。

感謝您閱讀我的文章! (Thank you for reading my article!)

翻譯自: https://towardsdatascience.com/using-k-means-clustering-to-create-support-and-resistance-b13fdeeba12

支撐阻力指標

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/389568.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/389568.shtml
英文地址,請注明出處:http://en.pswp.cn/news/389568.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

高版本(3.9版本)python在anaconda安裝opencv庫及skimage庫(scikit_image庫)諸多問題解決辦法

今天開始CV方向的學習&#xff0c;然而剛拿到基礎代碼的時候發現 from skimage.color import rgb2gray 和 import cv2標紅&#xff08;這里是因為我已經配置成功了&#xff0c;所以沒有紅標&#xff09;&#xff0c;我以為是單純兩個庫沒有下載&#xff0c;去pycharm中下載ski…

python 實現斐波那契數列

# coding:utf8 __author__ blueslidef fun(arg1,arg2,stop):if arg10:print(arg1,arg2)arg3 arg1arg2print(arg3)if arg3<stop:arg3 fun(arg2,arg3,stop)fun(0,1,100)轉載于:https://www.cnblogs.com/bluesl/p/9079705.html

單機安裝ZooKeeper

2019獨角獸企業重金招聘Python工程師標準>>> zookeeper下載、安裝以及配置環境變量 本節介紹單機的zookeeper安裝&#xff0c;官方下載地址如下&#xff1a; https://archive.apache.org/dist/zookeeper/ 我這里使用的是3.4.11版本&#xff0c;所以找到相應的版本點…

均線交易策略的回測 r_使用r創建交易策略并進行回測

均線交易策略的回測 rR Programming language is an open-source software developed by statisticians and it is widely used among Data Miners for developing Data Analysis. R can be best programmed and developed in RStudio which is an IDE (Integrated Development…

opencv入門課程:彩色圖像灰度化和二值化(采用skimage庫和opencv庫兩種方法)

用最簡單的辦法實現彩色圖像灰度化和二值化&#xff1a; 首先采用skimage庫&#xff08;skimage庫現在在scikit_image庫中&#xff09;實現&#xff1a; from skimage.color import rgb2gray import numpy as np import matplotlib.pyplot as plt""" skimage庫…

SVN中Revert changes from this revision 跟Revert to this revision

譬如有個文件&#xff0c;有十個版本&#xff0c;假定版本號是1&#xff0c;2&#xff0c;3&#xff0c;4&#xff0c;5&#xff0c;6&#xff0c;7&#xff0c;8&#xff0c;9&#xff0c;10。Revert to this revision&#xff1a; 如果是在版本6這里點擊“Revert to this rev…

歸 [拾葉集]

歸 心歸故鄉 想象行走在 鄉間恬靜小路上 讓那些疲憊的夢 都隨風飛散吧&#xff01; 不去想那些世俗 人來人往 熙熙攘攘 秋日午后 陽光下 細數落葉 來日方長 世上的路 有詩人、浪子 歌詠吟唱 世上的人 在欲望、信仰中 彷徨 彷徨又迷茫 親愛的人兒 快結束那 無休止的獨自流浪 莫要…

instagram分析以預測與安的限量版運動鞋轉售價格

Being a sneakerhead is a culture on its own and has its own industry. Every month Biggest brands introduce few select Limited Edition Sneakers which are sold in the markets according to Lottery System called ‘Raffle’. Which have created a new market of i…

opencv:用最鄰近插值和雙線性插值法實現上采樣(放大圖像)與下采樣(縮小圖像)

上采樣與下采樣 概念&#xff1a; 上采樣&#xff1a; 放大圖像&#xff08;或稱為上采樣&#xff08;upsampling&#xff09;或圖像插值&#xff08;interpolating&#xff09;&#xff09;的主要目的 是放大原圖像,從而可以顯示在更高分辨率的顯示設備上。 下采樣&#xff…

CSS魔法堂:那個被我們忽略的outline

前言 在CSS魔法堂&#xff1a;改變單選框顏色就這么吹毛求疵&#xff01;中我們要模擬原生單選框通過Tab鍵獲得焦點的效果&#xff0c;這里涉及到一個常常被忽略的屬性——outline&#xff0c;由于之前對其印象確實有些模糊&#xff0c;于是本文打算對其進行稍微深入的研究^_^ …

初創公司怎么做銷售數據分析_初創公司與Faang公司的數據科學

初創公司怎么做銷售數據分析介紹 (Introduction) In an increasingly technological world, data scientist and analyst roles have emerged, with responsibilities ranging from optimizing Yelp ratings to filtering Amazon recommendations and designing Facebook featu…

opencv:灰色和彩色圖像的像素直方圖及直方圖均值化的實現與展示

直方圖及直方圖均值化的理論&#xff0c;實現及展示 直方圖&#xff1a; 首先&#xff0c;我們來看看什么是直方圖&#xff1a; 理論概念&#xff1a; 在圖像處理中&#xff0c;經常用到直方圖&#xff0c;如顏色直方圖、灰度直方圖等。 圖像的灰度直方圖就描述了圖像中灰度分…

mysql.sock問題

Cant connect to local MySQL server through socket /tmp/mysql.sock 上述提示可能在啟動mysql時遇到&#xff0c;即在/tmp/mysql.sock位置找不到所需要的mysql.sock文件&#xff0c;主要是由于my.cnf文件里對mysql.sock的位置設定導致。 mysql.sock默認的是在/var/lib/mysql,…

交換機的基本原理配置(一)

1、配置主機名 在全局模式下輸入hostname 名字 然后回車即可立馬生效&#xff08;在生產環境交換機必須有自己唯一的名字&#xff09; Switch(config)#hostname jsh-sw1jsh-sw1(config)#2、顯示系統OS名稱及版本信息 特權模式下&#xff0c;輸入命令 show version Switch#show …

opencv:卷積涉及的基礎概念,Sobel邊緣檢測代碼實現及Same(相同)填充與Vaild(有效)填充

濾波 線性濾波可以說是圖像處理最基本的方法&#xff0c;它可以允許我們對圖像進行處理&#xff0c;產生很多不同的效果。 卷積 卷積的概念&#xff1a; 卷積的原理與濾波類似。但是卷積卻有著細小的差別。 卷積操作也是卷積核與圖像對應位置的乘積和。但是卷積操作在做乘…

機器學習股票_使用概率機器學習來改善您的股票交易

機器學習股票Note from Towards Data Science’s editors: While we allow independent authors to publish articles in accordance with our rules and guidelines, we do not endorse each author’s contribution. You should not rely on an author’s works without seek…

BZOJ 2818 Gcd

傳送門 題解&#xff1a;設p為素數 &#xff0c;則gcd(x/p,y/p)1也就是說求 x&#xff0f;p以及 y&#xff0f;p的歐拉函數。歐拉篩前綴和就可以解決 #include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <map&…

LeetCode387-字符串中的第一個唯一字符(查找,自定義數據結構)

一開始想用HashMap&#xff0c;把每個字符放進去&#xff0c;然后統計出現的次數。 使用LinkedHashMap的話&#xff0c;鍵值對的順序都是不會變的。 LinkedHashMap<Character,Integer> map new LinkedHashMap<>();map.put(i,1111);map.put(j,2222);map.put(k,3333…

r psm傾向性匹配_南瓜香料指標psm如何規劃季節性廣告

r psm傾向性匹配Retail managers have been facing an extraordinary time with the COVID-19 pandemic. But the typical plans to prepare for seasonal sales will be a new challenge. More seasonal products have been introduced over the years, making August the bes…

主成分分析:PCA的思想及鳶尾花實例實現

主成份分析算法PCA 非監督學習算法 PCA的實現&#xff1a; 簡單來說&#xff0c;就是將數據從原始的空間中轉換到新的特征空間中&#xff0c;例如原始的空間是三維的(x,y,z)&#xff0c;x、y、z分別是原始空間的三個基&#xff0c;我們可以通過某種方法&#xff0c;用新的坐…