Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

同样的代码用rqalpha跑,跟在ricequant.com上跑的结果不一样? #5

Closed
smilingpoplar opened this issue Aug 10, 2016 · 6 comments
Labels

Comments

@smilingpoplar
Copy link

smilingpoplar commented Aug 10, 2016

No description provided.

@smilingpoplar smilingpoplar changed the title 同样的代码用rqalpha跑的结果,跟在ricequant.com上跑不一样? 同样的代码用rqalpha跑,跟在ricequant.com上跑的结果不一样? Aug 10, 2016
@cedricporter
Copy link
Member

请问可以提供下具体代码吗?

@smilingpoplar
Copy link
Author

smilingpoplar commented Aug 11, 2016

@cedricporter 比如跑:
rqalpha run -f examples/multi_rsi.py -s 2006-08-01 -e 2016-08-08 -o result.pkl --plot

或者下面二八轮动的代码:

def init(context):
  context.stocks = ['000300.XSHG', '000905.XSHG', '000012.XSHG']

def handle_bar(context, bar_dict):
  [hs, zz, gz] = context.stocks
  history20 = history(20, '1d', 'close')
  hsIncrease = history20[hs][-1] - history20[hs][0]
  zzIncrease = history20[zz][-1] - history20[zz][0]
  positions = context.portfolio.positions
  [hsQuality, zzQuality, gzQuality] = [positions[hs].quantity, positions[zz].quantity, positions[gz].quantity]
  if hsIncrease < 0 and zzIncrease < 0:
    if hsQuality > 0: order_target_percent(hs, 0)
    if zzQuality > 0: order_target_percent(zz, 0)
    order_target_percent(gz, 1)
  elif hsIncrease < zzIncrease:
    if hsQuality > 0: order_target_percent(hs, 0)
    if gzQuality > 0: order_target_percent(gz, 0)
    order_target_percent(zz, 1)
  else:
    if zzQuality > 0: order_target_percent(zz, 0)
    if gzQuality > 0: order_target_percent(gz, 0)
    order_target_percent(hs, 1)
  logger.info("positions hs300: " + str(hsQuality) + ", zz500: " + str(zzQuality) + ", gz: " + str(gzQuality))

@cedricporter
Copy link
Member

cedricporter commented Aug 11, 2016

rqalpha run -f examples/multi_rsi.py -s 2006-08-01 -e 2016-08-08 -o result.pkl --plot 这个是一样的,不一样的话,可能是你本地的data bundle有点老,可以rqalpha update_bundle更新下。

qq20160811-0

二八轮动是因为购买了指数。而指数在 ricequant.com 的 lotsize 是1, rqalpha的 lotsize 是 100,因为钱不够开不了仓。后续会将 rqalpha 购买指数时的 lotsize 修改为 1。

@smilingpoplar
Copy link
Author

@cedricporter 嗯,运行multi_rsi.py是一样了。

lotsize是啥?我可以在哪儿改?

@cedricporter
Copy link
Member

指数的 lotsize 刚刚修改好了,您可以更新下 pip install -U rqalpha

@smilingpoplar
Copy link
Author

@cedricporter 好了,👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants