In [ ]:
#coding=utf-8

from rqalpha.api import *
import traceback
from datetime import *
from sqlalchemy import create_engine
import pandas as pd
from rqalpha.utils.logger import user_log
from numpy import log

def dependency():
    return ['market_value']

def market(market=90):
    if market == 83:
        return 'XSHG'
    elif market == 90:
        return 'XSHE'
    else:
        return ""

def compute(startdt,enddt,context):
    '''
    对数市值
    '''
    #context.config 对应配置的extra部分
    from rqalpha.mod.rqalpha_mod_alphaStar_factors.factor_data import DependingData
    dData = DependingData(context)
    return dData.getDependingData("market_value",startdt,enddt).applymap(log)

In [ ]:
# test
config= {"extra":{"jydb":{"host":"172.18.44.5","port":3306,"user":"liangh","passwd":"huaxun!@#db","db":"jydb"}}
         ,"factor_data_path":"../../factor_data","factor_data_init_date": "2017-01-01"}
from rqalpha.utils import RqAttrDict
conf = RqAttrDict(config)
from rqalpha.mod.rqalpha_mod_alphaStar_factors.factor_context import FactorContext
context = FactorContext(conf)
context.registerDepending(dependency())
res =  compute(datetime(2017,1,1),datetime(2017,2,1),context)
res

In [1]:
# evaluateFileDemo
from rqalpha.mod.rqalpha_mod_alphaStar_factors import evaluate_file

config = {
  "base": {
    "start_date": "2010-01-01",
    "end_date": "2018-04-01",
  },
}

factor_file_path = "./market_value_log.ipynb"

evaluate_file(factor_file_path=factor_file_path,config=config,config_file = "../config_factor.yml")


WARNING: better_exceptions will only inspect code from the command line
         when using: `python -m better_exceptions'. Otherwise, only code
         loaded from files will be inspected!
[2018-05-09 16:58:40.865346] DEBUG: system_log: evaluateRun
2010-01-04 INFO factor:market_value_log compute,startdt:2010-01-04 00:00:00,enddt:2018-03-30
[2018-05-09 16:58:41.657065] INFO: system_log: get factor value success
没有 000003.XSHE 相关数据
没有 000013.XSHE 相关数据
没有 000015.XSHE 相关数据
没有 000047.XSHE 相关数据
没有 000405.XSHE 相关数据
没有 000412.XSHE 相关数据
没有 000508.XSHE 相关数据
没有 000542.XSHE 相关数据
没有 000556.XSHE 相关数据
没有 000588.XSHE 相关数据
没有 000621.XSHE 相关数据
没有 000653.XSHE 相关数据
没有 000658.XSHE 相关数据
没有 000660.XSHE 相关数据
没有 000675.XSHE 相关数据
没有 000689.XSHE 相关数据
没有 000730.XSHE 相关数据
没有 002257.XSHE 相关数据
没有 002525.XSHE 相关数据
没有 002710.XSHE 相关数据
没有 002720.XSHE 相关数据
没有 300361.XSHE 相关数据
没有 300454.XSHE 相关数据
没有 300646.XSHE 相关数据
没有 300728.XSHE 相关数据
没有 300742.XSHE 相关数据
没有 300745.XSHE 相关数据
没有 600349.XSHG 相关数据
没有 600625.XSHG 相关数据
没有 600632.XSHG 相关数据
没有 600646.XSHG 相关数据
没有 600669.XSHG 相关数据
没有 600670.XSHG 相关数据
没有 600709.XSHG 相关数据
没有 600813.XSHG 相关数据
没有 600878.XSHG 相关数据
没有 601206.XSHG 相关数据
没有 601990.XSHG 相关数据
没有 603013.XSHG 相关数据
没有 603045.XSHG 相关数据
没有 603259.XSHG 相关数据
没有 603302.XSHG 相关数据
没有 603587.XSHG 相关数据