コード例 #1
0
def k_strategy(code,
               filename,
               start_date,
               end_date,
               account_stock,
               benchmark="000300.XSHG"):
    config = {
        "base": {
            "start_date": start_date,
            "end_date": end_date,
            "benchmark": benchmark,
            "accounts": {
                "stock": account_stock
            }
        },
        "extra": {
            "log_level": "verbose",
        },
        "mod": {
            "sys_analyser": {
                "enabled":
                True,
                "output_file":
                "Z:/Hello/Work/Data/QT/Rqalpha_test/HHH/app/static/test-result/"
                + filename
            }
        }
    }
    #"plot_save_file": "Z:/Hello/Work/Data/QT/Rqalpha_test/HHH/app/static/test-result/" + filename ,

    run_code(code, config)
コード例 #2
0
ファイル: run_code_demo.py プロジェクト: we87/rqalpha
    pass


def handle_bar(context, bar_dict):
    if not context.fired:
        # order_percent并且传入1代表买入该股票并且使其占有投资组合的100%
        order_percent(context.s1, 1)
        context.fired = True
"""

config = {
    "base": {
        "start_date": "2016-06-01",
        "end_date": "2016-12-01",
        "securities": ['stock'],
        "stock_starting_cash": 100000,
        "benchmark": "000300.XSHG"
    },
    "extra": {
        "log_level": "verbose",
    },
    "mod": {
        "sys_analyser": {
            "enabled": True,
            "plot": False
        }
    }
}

run_code(code, config)
コード例 #3
0
#exit(0)
from redis_queue import StrategyQueue, ResultQueue
import json
import codecs
#with codecs.open("../examples/buy_and_hold.py", encoding="utf-8") as f:
#    source_code = f.read()
while True:
    result = StrategyQueue.get_wait()
    if not result:
        # result=run_code(code=source_code, config=config)
        break
    result = json.loads(result)
    if 'config' in result and 'plot' in result['config']:
        result['config']['plot'] = False
    print("\n\nrecieve a strategy ")
    raw_result = run_code(code=result['source_code'], config=result['config'])
    try:
        x_list = raw_result['sys_analyser']['portfolio'].index.strftime(
            '%Y-%m-%d').tolist()
    except Exception:
        continue
    portfolio_list = raw_result['sys_analyser'][
        'portfolio'].loc[:, 'market_value'].tolist()
    benchmark_list = raw_result['sys_analyser'][
        'benchmark_portfolio'].loc[:, 'market_value'].tolist()
    last_day = raw_result['sys_analyser']['stock_positions'].index[-1]
    stock_positions = raw_result['sys_analyser']['stock_positions'].loc[
        last_day, 'order_book_id']
    if isinstance(stock_positions, str):
        stock_positions_list = [
            stock_positions,
コード例 #4
0
ファイル: run_code_demo.py プロジェクト: 8dspaces/rqalpha

def handle_bar(context, bar_dict):
    if not context.fired:
        # order_percent并且传入1代表买入该股票并且使其占有投资组合的100%
        order_percent(context.s1, 1)
        context.fired = True
"""

config = {
  "base": {
    "start_date": "2016-06-01",
    "end_date": "2016-12-01",
    "benchmark": "000300.XSHG",
    "accounts": {
      "stock": 100000
    }
  },
  "extra": {
    "log_level": "verbose",
  },
  "mod": {
    "sys_analyser": {
      "enabled": True,
      "plot": False
    }
  }
}

run_code(code, config)