python_大智慧SAR指标编写
生活随笔
收集整理的這篇文章主要介紹了
python_大智慧SAR指标编写
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
import pandas as pd
import numpy as np
import datetime
import time
#獲取數據
df=pd.read_csv('C:/Users/HXWD/Desktop/000001.csv',encoding='gbk')
df.columns=['date','code','name','close','high','low','open','preclose',
'change','change_per','volume','amt']
df=df[['date','open','high','low','close','volume','amt']]
df.head()
def get_SAR(df,N=10,step=2,maxp=20):sr_value=[]sr_up=[]ep_up=[]af_up=[]sr_down=[]ep_down=[]af_down=[]for i in range(len(df)):if i >=N:if len(sr_up)==0 and len(sr_down)==0:if df.ix[i,'close']>df.ix[0,'close']:#標記為上漲趨勢sr0=df['low'][0:i].min()af0=0.02ep0=df.ix[i,'high']sr_up.append(sr0)ep_up.append(ep0)af_up.append(af0)sr_value.append(sr0)if df.ix[i,'close']<=df.ix[0,'close']:#標記為上漲趨勢sr0=df['high'][0:i].max()af0=0.02ep0=df.ix[i,'high']sr_down.append(sr0)ep_down.append(ep0)af_down.append(af0)sr_value.append(sr0)if len(sr_up)>0:if df.ix[i-1,'low']>sr_up[-1]:sr0=sr_up[-1]ep0=df['high'][-len(sr_up):].max()if df.ix[i,'high']>df['high'][-(len(sr_up)-1):].max() :af0=af_up[-1]+0.02if df.ix[i,'high']<=df['high'][-(len(sr_up)-1):].max() :af0=af_up[-1]sr=sr0+af0*(ep0-sr0)sr_up.append(sr)ep_up.append(ep0)af_up.append(af0)sr_value.append(sr)print('上漲sr0={},ep0={},af0={},sr={}'.format(sr0,ep0,af0,sr))if df.ix[i-1,'low']<=sr_up[-1]:ep0=df['high'][-len(sr_up):].max()sr0=ep0af0=0.02sr_down.append(sr0)ep_down.append(ep0)af_down.append(af0)sr_value.append(sr0)sr_up=[]ep_up=[]af_up=[]if len(sr_down)>0:if df.ix[i-1,'high']<sr_down[-1]:sr0=sr_down[-1]ep0=df['low'][-len(sr_down):].max()if df.ix[i,'low']<df['low'][-(len(sr_down)-1):].max() :af0=af_down[-1]+0.02if df.ix[i,'low']>=df['low'][-(len(sr_down)-1):].max() :af0=af_down[-1]sr=sr0+af0*(ep0-sr0)sr_down.append(sr)ep_down.append(ep0)af_down.append(af0)sr_value.append(sr)print('下跌sr0={},ep0={},af0={},sr={}'.format(sr0,ep0,af0,sr))if df.ix[i-1,'high']>=sr_down[-1]:ep0=df['low'][-len(sr_up):].max()sr0=ep0af0=0.02sr_up.append(sr0)ep_up.append(ep0)af_up.append(af0)sr_value.append(sr0)sr_down=[]ep_down=[]af_down=[]return sr_value
sar=get_SAR(df)
#測試下來看,似乎中間邏輯有問題,有時間進一步修改
注:需要單獨編寫文華財經,金字塔,大智慧,通達信,TB,Python平臺的指標、策略等,請聯系扣扣1733505732,兼職時間:工作日下午18:00-22:00,節假日。
總結
以上是生活随笔為你收集整理的python_大智慧SAR指标编写的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: lisp 焊接符号标注_焊接符号标注及表
- 下一篇: VBS教程--摘自百度百科