等级: 免费版
- 注册:
- 2023-1-30
- 曾用名:
|
楼主 |
发表于 2023-7-18 22:01
|
显示全部楼层
我写的代码。烦请技术帮忙斧正,感激不尽。
from PythonApi import *
import talib
import numpy as np
def init(context):
#收盘价获取
#股票代码 = context.run_info.base_book_id
股票代码 = "sz301357"
#print(股票代码)#SH510050
K线数量 =500#越多误差越小,最少34
收盘价 = history_bars(股票代码, K线数量, 'self', 'close',True)#某一合约历史数据
#print(收盘价)
if len(收盘价) < 34 :
print('K线数量不足')
#talib.MACDEXT不同类型:
diff,dea,macd = talib.MACDEXT(收盘价 , fastperiod = 12, slowperiod = 26, signalperiod = 9)
print(f'默认是0:\n{macd}') #1.05220566e-01
diff,dea,macd = talib.MACDEXT(收盘价 , fastperiod = 12, fastmatype=0,slowperiod = 26, slowmatype=0, signalperiod = 9,signalmatype=0)
print(f'0:SMA:\n{macd}')#1.05220566e-01
diff,dea,macd = talib.MACDEXT(收盘价 , fastperiod = 12, fastmatype=1,slowperiod = 26, slowmatype=1, signalperiod = 9,signalmatype=1)
print(f'1:EMA:\n{macd}')#7.09681680e-02
diff,dea,macd = talib.MACD(收盘价 , fastperiod = 12, slowperiod = 26, signalperiod = 9)#______________MACD_____________
print(f'___MACD___:\n{macd}') #7.09681680e-02
diff,dea,macd = talib.MACDEXT(收盘价 , fastperiod = 12, fastmatype=2,slowperiod = 26, slowmatype=2, signalperiod = 9,signalmatype=2)
print(f'2:WMA:\n{macd}')#9.71633499e-02
diff,dea,macd = talib.MACDEXT(收盘价 , fastperiod = 12, fastmatype=3,slowperiod = 26, slowmatype=3, signalperiod = 9,signalmatype=3)
print(f'3:DEMA:\n{macd}')#0.03097076
diff,dea,macd = talib.MACDEXT(收盘价 , fastperiod = 12, fastmatype=4,slowperiod = 26, slowmatype=4, signalperiod = 9,signalmatype=4)
print(f'4:TEMA:\n{macd}') #-3.41443015e-02
diff,dea,macd = talib.MACDEXT(收盘价 , fastperiod = 12, fastmatype=5,slowperiod = 26, slowmatype=5, signalperiod = 9,signalmatype=5)
print(f'5:TRIMA:\n{macd}')#2.05966702e-01
diff,dea,macd = talib.MACDEXT(收盘价 , fastperiod = 12, fastmatype=6,slowperiod = 26, slowmatype=6, signalperiod = 9,signalmatype=6)
print(f'6:KAMA:\n{macd}')#5.62658020e-02
diff,dea,macd = talib.MACDEXT(收盘价 , fastperiod = 12, fastmatype=7,slowperiod = 26, slowmatype=7, signalperiod = 9,signalmatype=7)
print(f'7:MAMA:\n{macd}') #0
diff,dea,macd = talib.MACDEXT(收盘价 , fastperiod = 12, fastmatype=8,slowperiod = 26, slowmatype=8, signalperiod = 9,signalmatype=8)
print(f'8:T3:\n{macd}')#1.05628403e-01
#金字塔
提取pel公式指标数据 = get_indicator(股票代码, 'MACD','MACD1', '26,12,9', 'self', K线数量)
print(f'公式输出:\n{提取pel公式指标数据}')#1.41936336e-01 #0.0421463077e
#通达信:越多误差越小:-0.05 #0.042149 金字塔通达信误差很小 |
|