Skip to content

Commit

Permalink
add optimizing parameters examples in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricporter committed Apr 7, 2017
1 parent 0362212 commit 78f98ef
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions docs/source/intro/optimizing_parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,36 @@
参数调优
==================

对于以下双均线策略,我们希望对其进行参数调优,我们可以通过命令行参数 :code:`--extra-vars` 或者通过配置 :code:`extra.context_vars` 传递变量到 :code:`context` 对象中。

.. code-block:: python
from rqalpha.api import *
import talib
def init(context):
context.s1 = "000001.XSHE"
context.SHORTPERIOD = 20
context.LONGPERIOD = 120
def handle_bar(context, bar_dict):
prices = history_bars(context.s1, context.LONGPERIOD+1, '1d', 'close')
short_avg = talib.SMA(prices, context.SHORTPERIOD)
long_avg = talib.SMA(prices, context.LONGPERIOD)
cur_position = context.portfolio.positions[context.s1].quantity
shares = context.portfolio.cash / bar_dict[context.s1].close
if short_avg[-1] - long_avg[-1] < 0 and short_avg[-2] - long_avg[-2] > 0 and cur_position > 0:
order_target_value(context.s1, 0)
if short_avg[-1] - long_avg[-1] > 0 and short_avg[-2] - long_avg[-2] < 0:
order_shares(context.s1, shares)
通过函数调用传递参数
====================================
Expand Down

0 comments on commit 78f98ef

Please sign in to comment.