# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python [conda env:rqalpha]
#     language: python
#     name: conda-env-rqalpha-py
# ---

# +
from rqalpha.api import *

# 在这个方法中编写任何的初始化逻辑。context对象将会在你的算法策略的任何方法之间做传递。
def init(context):
    logger.info("init")

def before_trading(context):
    pass

# 你选择的证券的数据更新将会触发此段逻辑，例如日或分钟历史数据切片或者是实时数据切片更新
def handle_bar(context, bar_dict):
    _fvalue = get_factors("pe",context.now.date(),context.now.date()).iloc[0]
    _fvalue = _fvalue[_fvalue>0]
#     print(context.now,_fvalue.sort_values())
    #买入低估值排名前10的票
    buy_codes = list(_fvalue.sort_values().index[:10])
#     holdings = [code for code in context.portfolio.positions]
#     print(buy_codes)
    equalWeight_order(buy_codes,context)


# +
from rqalpha import run_file

config = {
    "base": {
        "start_date": "2017-01-01",
        "end_date": "2017-01-31",
    },
    "mod": {
        "sys_analyser": {
            "enabled": True,
            "plot": True
        }
    }
}

file_path = "./testStrategy.ipynb"
run_file(file_path, config,config_file = "../config.yml")
# run_func(,config,config_file=)
# -

# %load_ext rqalpha

# %rqalpha -s 20170101 -e 20170131 --config ../config.yml -f ./testStrategy.ipynb -p

StarcoderdataJupyterScriptsDedupFiltered