返回列表 发布新帖

这个在券商QMT运行后,打印出来的怎么会有2种不同的形式

1 金钱      回复本帖可获得 1 金钱奖励! 每人限 1 次(中奖概率 50%)
1079 2
发表于 2024-1-16 20:30:33 | 显示全部楼层 阅读模式

import statsmodels.formula.api as smf import statistics import numpy as np import pandas as pd

class G(): pass

g = G()

def init(ContextInfo): print('测试') g.gpc=['002601.SZ'] g.gpc.append('000300.SH')

def handlebar(ContextInfo):

global mean_turnover
dtime = ContextInfo.get_market_data_ex(['close'], stock_code =\
g.gpc,period = '1d',start_time='20230325',end_time='20230928', count=-1,\
dividend_type = 'follow',fill_data=True,subscribe=True)
if len(dtime['000300.SH'])>65:
    for i in dtime.keys():
        return_signal(dtime, 'close',i)
return

def return_signal(data:dict,field:str,code:str):

_index=data[list(data.keys())[0]].index.tolist()
_columns=list(data.keys())
df=pd.DataFrame(index=_index,columns=_columns)
for i in _columns:
   df[i]=data[i][field]
df1=data[code][-61:-1]
df=df.rename(columns={'000300.SH':'SH'})
df=df.rename(columns={code:'SZ'})
test_df = df.iloc[-61:-1]
test_df = (test_df/test_df.iloc[0]).apply(np.log) 
test_df['idd'] = np.array(range(60))/252.0
test_df=pd.DataFrame(test_df)
print(test_df.columns)
return

上面的代码运行后,如下图,不是应该只显示['SZ''SH''IDD']怎么还会打印出['002601.SZ']这一项 image.png

评论2

Willows
发表于 2024-1-17 11:18:02 | 显示全部楼层
统一下格式发吧,现在看着眼疼,看代码是不应该有002601,那有没有可能不是这里打印的
*******6371楼主
发表于 2024-1-17 13:43:15 | 显示全部楼层
Willows 发表于 2024-1-17 11:18
统一下格式发吧,现在看着眼疼,看代码是不应该有002601,那有没有可能不是这里打印的 ...

这个是代码,辛苦您看一下
  1. # -*- coding: gbk -*-
  2. #import statsmodels.api as sm
  3. import statsmodels.formula.api as smf
  4. import statistics
  5. import numpy as np
  6. import pandas as pd
  7. import matplotlib.pyplot as plt
  8. import sys,os
  9. from pylab import mpl

  10. class G():
  11.         pass

  12. g = G()

  13. g.r = 0.04
  14. g.dtt = 1/255.0

  15. g.code_dict = {}
  16. g.date_dict = {}

  17. g.SHORT_POINT = 1.25
  18. g.COVER_POINT = 0.75
  19. g.SELL_POINT = -0.5
  20. g.BUY_POINT = -1.25

  21. g.SUPER_SHORT = u"超卖区域"
  22. g.SHORTING = u"卖方力量"
  23. g.XUWU = u"中间区域"
  24. g.BUYING = u"买方力量"
  25. g.SUPER_BUY = u"超买区域"

  26. g.SHORT = "SHORT"
  27. g.COVER = "COVER"
  28. g.SELL = "SELL"
  29. g.BUY = "BUY"

  30. g.DLONG = "DLONG"
  31. g.DSHORT = "DSHORT"
  32. g.DNOPE = "DNOPE"

  33. def init(ContextInfo):
  34.         print('测试')
  35.         g.gpc=['002601.SZ']
  36.         g.gpc.append('000300.SH')
  37.         g.weight=[0.1]*10
  38.         g.capital=1000000
  39.         g.accountID='309919124048'
  40.         commissionList=[0,0.001,0.0002,0.0002,0,5]
  41.         ContextInfo.set_commission(0,commissionList)
  42.         ContextInfo.set_universe(g.gpc)
  43. def handlebar(ContextInfo):

  44.         global mean_turnover
  45.         dtime = ContextInfo.get_market_data_ex(['close'], stock_code =\
  46.         g.gpc,period = '1d',start_time='20230325',end_time='20230928', count=-1,\
  47.         dividend_type = 'follow',fill_data=True,subscribe=True)
  48.         if len(dtime['000300.SH'])>65:
  49.                 for i in dtime.keys():
  50.                         return_signal(dtime, 'close',i)
  51.         return
  52.        
  53. def return_signal(data:dict,field:str,code:str):
  54.         """i是第几天,code是哪只票,返回信号和分数"""
  55.         _index=data[list(data.keys())[0]].index.tolist()
  56.         _columns=list(data.keys())
  57.         df=pd.DataFrame(index=_index,columns=_columns)
  58.         for i in _columns:
  59.                 df[i]=data[i][field]
  60.         df=df.rename(columns={'000300.SH':'SH'})
  61.         df=df.rename(columns={code:'SZ'})
  62.         test_df = df.iloc[-61:-1]
  63.         test_df = (test_df/test_df.iloc[0]).apply(np.log)
  64.         test_df['idd'] = np.array(range(60))/252.0
  65.         test_df=pd.DataFrame(test_df)
  66.         print(test_df.columns)
  67.         return
  68.         result=smf.ols('code~SH+idd',test_df).fit()#
  69.         print(result.summary())
  70.         return
复制代码

回复

您需要登录后才可以回帖 登录 | 立即注册

客服专线

400-080-8112

用思考的速度交易,用真诚的态度合作,我们是认真的!
  • 关注公众号
  • 添加微信客服
Copyright © 2001-2025 迅投QMT社区 版权所有 All Rights Reserved. 蜀ICP备19002686号-2
关灯 快速发帖
扫一扫添加微信客服
QQ客服返回顶部
快速回复 返回顶部 返回列表