Skip to content

Instantly share code, notes, and snippets.

@shihyu
Forked from dear983604/Talib_practice.py
Created July 27, 2019 16:09
Show Gist options
  • Save shihyu/c5b614807047c48f146fe21ff502d217 to your computer and use it in GitHub Desktop.
Save shihyu/c5b614807047c48f146fe21ff502d217 to your computer and use it in GitHub Desktop.
TA-Lab套件教學
#導入套件
%matplotlib inline
import datetime
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
#專門做『技術分析』的套件
from talib import abstract
#專門抓台股的套件
import twstock
#設定爬蟲股票代號
sid = '2330'
data=twstock.Stock(sid)
#用fetch_from抓取資料,指定日期放入dataframe裡
df = pd.DataFrame(data.fetch_from(2018,1))
#設定index
df.set_index('date', inplace = True)
#------------------------------------------
#畫收盤價
df['close'].plot(figsize=(16, 8))
#畫技術指標-KD值
abstract.STOCH(df).plot(figsize=(16,8))
#畫技術指標-MACD值
abstract.MACD(df).plot(figsize=(16,8))
#畫技術指標-RSI值
abstract.RSI(df).plot(figsize=(16,8))
df['close'].plot(figsize=(16,8),secondary_y=True)
#畫技術指標-WILLR值
abstract.WILLR(df).plot(figsize=(16,8))
df['close'].plot(figsize=(16,8),secondary_y=True)
#----------------------------------------
#用get_function()找指標內容
import talib
print(talib.get_functions())
print(len(talib.get_functions()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment