Cycle Indicator Functions cycle indicator function

  Hilbert transform (Hilbert Transform) is an integral transformation, has been widely used in signal processing, for processing the narrowband digital signals often works. Non-periodic fluctuations in financial markets, not the law, but as long as there is volatility, you can look for its "cyclical" by Hilbert transform. For stock prices, generally can be divided into: long-term trends, short-term cyclical fluctuations and noise. In the case of the removal of the long-term trend, you can use the Hilbert transform short-term cyclical fluctuations are analyzed.

HT_DCPERIOD: Hilbert Transform-Dominant Cycle Period Hilbert transform - dominant cycle:

ta.HT_DCPERIOD (close), the price calculation cycle position, when used as a basis of the selection.

HT_DCPHASE: Hilbert Transform-Dominant Cycle Phase Hilbert transform - dominant cycle stages:

ta.HT_DCPHASE(close)

HT_PHASOR: Hilbert Transform-Phasor Components Hilbert transform - phase constituted:

inphase, quadrature = ta.HT_PHASOR (close), is decomposed into in-phase and quadrature components

HT_SINE: Hilbert Transform-SineWave Hilbert transform - sine:

older, leadsine = ta.HT_SINE (close)

HT_TRENDMODE: Hilbert Transform-Trend vs Cycle Mode Hilbert transform - Trend and cycle mode

ta.HT_TRENDMODE(close)

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import talib as ta
import tushare as ts

plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False

def get_data(code, start='2015-01-01'):
    df = ts.get_k_data(code, start)
    df.index = pd.to_datetime(df.date)
    df = df.sort_index()
    return df

df = get_data('sh')[['open','close','high','low']]
df['dcperiod'] = ta.HT_DCPERIOD(df.close)
df['dcphase'] = ta.HT_DCPHASE(df.close)
df['inhpase'], df['quadrature'] = ta.HT_PHASOR(df.close)
df['sine'], df['leadsine'] = sine, leadsine = ta.HT_SINE(df.close)
df['trendmode'] = ta.HT_TRENDMODE(df.close)

df[['close','dcperiod','dcphase','inhpase',
    'quadrature','sine','leadsine','trendmode']
    ].plot(figsize=(20,18), subplots=True, layout=(4,2))
plt.subplots_adjust(wspace=0, hspace=0.2)

sdafsd

 

Guess you like

Origin www.cnblogs.com/wintalau/p/11617805.html