import yfinance as yf
import pandas_ta as pa
import plotly.graph_objects as go
import numpy as np
def get_data(symbol: str):
data = yf.download(tickers=symbol, period='1000d', interval='1d')
data.reset_index(inplace=True)
return data
# Get the data
data = get_data('BTC-USD')
添加拒绝(rejection)信号
def identify_rejection(data):
# Create a new column for shooting star
data['rejection'] = data.apply(lambda row: 2 if (
( (min(row['Open'], row['Close']) - row['Low']) > (1.5 * abs(row['Close'] - row['Open']))) and
(row['High'] - max(row['Close'], row['Open'])) < (0.8 * abs(row['Close'] - row['Open'])) and
(abs(row['Open'] - row['Close']) > row['Open'] * 0.001)
) else 1 if (
(row['High'] - max(row['Open'], row['Close'])) > (1.5 * abs(row['Open'] - row['Close'])) and
(min(row['Close'], row['Open']) - row['Low']) < (0.8 * abs(row['Open'] - row['Close'])) and
(abs(row['Open'] - row['Close']) > row['Open'] * 0.001)
) else 0, axis=1)
return data
data = identify_rejection(data)
data['rejection'] = 2的形态,就是不管实体abs(open-close)颜色,关心的是下长影线是实体长度的1.5倍,并且上长影线小于实体的0.8倍,实体长度大于open的0.001倍。(倒锤线)
data['rejection']