如何修改這個模型 [金字塔]
-
咨詢內容:
# 本Python代碼主要用于策略交易# 可以自己import我們平臺支持的第三方python模塊,比如pandas、numpy等。from PythonApi import *import time# 參數定義區,這里定義的參數可以直接在context對象中獲取。--(選擇實現)#def parameter():# input_par("myvalues1",5,1,20,1)# input_par("myvalues2",10,1,20,1)
# 在這個方法中編寫任何的初始化邏輯。context對象將會在你的算法策略的任何方法之間做傳遞。--(必須實現)def init(context):? ? # 在context中保存全局變量? ? context.s = get_blocks ('自選股',1)? ? context.n = 7? ? # print("策略啟動") #調試打印輸出? ??
# before_trading此函數會在每天基準合約的策略交易開始前被調用,當天只會被調用一次。--(選擇實現)def before_trading(context):? ? pass
# 你選擇的品種的數據更新將會觸發此段邏輯,例如日或分鐘歷史數據切片或者是實時數據切片更新。--(必須實現)def handle_bar(context):? ? # 開始編寫你的主要的算法邏輯。? ??? ? #使用buy_open、sell_close等方法下單? ? #下單示例:? ? #buy_open(context.s1, "Market", volume = 100) # 市價開多? ? #buy_open(context.s1, "Limit", 25.45, 100) # 限價開多? ? #print('開始')? ? #print(time.asctime( time.localtime(time.time()) ))? ? ZF = {}? ? for i in context.s:? ? ? ? price_now = get_dynainf(i,7)? ? ? ? price_last = get_dynainf(i,62)? ? ? ??? ? ? ? ZF[i] = (price_now - price_last)/price_last? ? df = sorted(ZF.items(),key = lambda x:x[1],reverse=True)? ? init_num = 0? ? for j in df:? ? ? ? if init_num >= context.n:? ? ? ? ? ? break? ? ? ? code = j[0]? ? ? ? cond = get_indicator(code,'AAAA','ZB','','1m',1500)? ? ? ? if cond[-1]:? ? ? ? ? ? portfolio=get_portfolio (code, 0)? ? ? ? ? ? if portfolio.buy_quantity == 0:? ? ? ? ? ? ? ? buy_open(code, "Market", volume = 1)?? ? ? ? ? ? init_num = init_num+1? ? ? ? else:? ? ? ? ? ? break? ??? ? df_short = df[::-1]? ? init_num = 0? ? for j in df_short:? ? ? ? if init_num >= context.n:? ? ? ? ? ? break? ? ? ? code = j[0]? ? ? ? cond = get_indicator(code,'AAAA','ZB','','1m',1500)? ? ? ? if cond[-1]:? ? ? ? ? ? portfolio=get_portfolio (code, 0)? ? ? ? ? ? if portfolio.sell_quantity == 0:? ? ? ? ? ? ? ? sell_open(code, "Market", volume = 1)?? ? ? ? ? ? init_num = init_num+1? ? ? ? else:? ? ? ? ? ? break? ? #get_indicator('sh600000','my_test','ma5','30','1d',10)? ??? ? #print('結束')? ? #print(time.asctime( time.localtime(time.time()) ))# after_trading函數會在每天交易結束后被調用,當天只會被調用一次。 --(選擇實現)def after_trading(context):? ? pass? ??? ??# order_status當委托下單,成交,撤單等與下單有關的動作時,該方法就會被調用。---(選擇實現)#def order_status(context,order):# pass
# order_action當查詢交易接口信息時返回的通知---(選擇實現)#def order_action(context,type, account, datas)# pass
# exit函數會在測評結束或者停止策略運行時會被調用。---(選擇實現)#def exit(context):# pass?
?來源: CXH99.COM
-
金字塔客服:
能不能幫我把漲幅排序改成按照指標ZB大小排序,進場是排序多頭前四,而且ZB=1,做空是最小的后四位,且ZB=-10000 2018/11/16 11:28:32不用檢查賬戶和持倉,0000 2018/11/16 11:32:01只要符合條件進場是排序多頭前四,而且ZB=1,做空是最小的后四位,且ZB=-1
?
-
用戶回復:
0000(372566119) 2018/11/16 14:18:27ZB就是這里的值cond = get_indicator(code,'AAAA','ZB','','1m',1500)0000(372566119) 2018/11/16 14:19:39ZB就是我自編的一個指標AAAA在一分鐘周期下的一個變動的數值
?
- 網友回復: ?????????????????????????
有思路,想編寫各種指標公式,程序化交易模型,選股公式,預警公式的朋友
可聯系技術人員 QQ: 511411198 進行 有償 編寫!(不貴!點擊查看價格!)
相關文章
-
沒有相關內容