Esempio n. 1
0
def run(conf = {}):
    """
    传入日期,读入projects和传入日期的statistics.进行计算,得到符合条件的strategic和股票code
    例如一个report的project为“短线股票池”,里面定义了多少天内上涨概率大于多少的公式。如果某策略的统计数据符合该公式,则返回该策略的股票代码及其他相关信息。
    >> reporter.run({"statistics":case['statistics']})
    
    更新 statistics => probability
    注:这里statistics主要指统计得到的bayes值.
    """
    logging.info("Report program start.")
    logging.debug("Report config %s"%str(conf))

    conf['REPORTER_PROJECT_PATH']=os.path.join(\
        conf.get("SYS_HOME",""),\
        conf.get("REPORTER_PROJECT_PATH",REPORTER_PROJECT_PATH))

    options={}
    options.update(conf)
    options.update(conf)
    conf=options
    date=conf.get('date',Date.getDate())
    check = Check.Check(conf = conf)
    if not check.checkReporterCondition(date = date):
        logging.warning("Reporter is invailable.date:%s" % date)
        return False
    #get statistics
    path = os.path.join(conf.get("SYS_HOME"),\
        conf.get("BAYES_DATA_PATH",BAYES_DATA_PATH),\
        date+SUFFIX)
    statistics = conf.get("statistics" , Reader.read(path = path)) #载入指定日期的监控策略
    if not statistics:
        logging.warning("Reporter not find statistics data.Exit it.")
        return None

    #filter by conditions
    strategic = Strategic(date = date ,conf = conf)
    report = Report(conf = conf)
    report.compute(strategic,statistics)

    #dump result
    if report != False:
        path = os.path.join(conf.get("SYS_HOME",""),\
            conf.get("REPORTER_DATA_PATH",REPORTER_DATA_PATH),date+SUFFIX)
        Dumper.dump(path = path , data = report.data)
        logging.info("Reporter result : %s" % str(report.data))
    else:
        logging.info("Reporter run fail.")
    return report
Esempio n. 2
0
def run(conf={}):
    date = Date.getInstantDate() #instant date 应该Date.getDate +1,key的编码问题
    conf['date']=date

    logging.info("start downloading instant data.Date is %s" % conf['date'])
    downloader = Downloader(conf = conf)
    downloader.download("instant")

    logging.info("start computing instant data.Date is %s"% conf['date'])
    stock=Stock(conf)
    extract = Extract(conf = conf)
    extract.extract(project = "instant", stock = stock, date = date)

    logging.info("start instant strategic data.Date is %s" %conf['date'])
    strategic_conf ={}
    strategic_conf.update(conf)
    strategic_conf['stock']=stock
    strategic = Strategic(conf = strategic_conf)
    strategicResult = strategic.compute()
    Dumper.dump(path = os.path.join(conf.get("SYS_HOME"),conf.get("INSTANT_DATA_PATH"),"strategic.json"),data = strategicResult)

    logging.info("Start Bayes statistics.Date is %s"% conf['date'])
    conf['strategic']=strategic
    bayesHandler = Bayes(conf)
    bayes = bayesHandler.posterior()
    Dumper.dump(path = os.path.join(conf.get("SYS_HOME"),conf.get("INSTANT_DATA_PATH"),"bayes.json"),data = bayes)

    logging.info("Start report.Date is %s"% conf['date'])
    report = Report(conf = conf)
    report.compute(strategic = strategic , statistics = bayes)
    print report

    #profile
    profile_conf =  {"stock":stock,"date":date}
    profile_conf.update(conf)
    profile = Profile(profile_conf)
    profile.viewProfile()

    path = os.path.join(conf.get("SYS_HOME"),conf.get("INSTANT_REPORT_DATA_PATH"))
    Dumper.dump(path = path,data = report.data)
    return report.data
Esempio n. 3
0
def run(conf={}):
    """
    传入日期,读入projects和传入日期的statistics.进行计算,得到符合条件的strategic和股票code
    例如一个report的project为“短线股票池”,里面定义了多少天内上涨概率大于多少的公式。如果某策略的统计数据符合该公式,则返回该策略的股票代码及其他相关信息。
    >> reporter.run({"statistics":case['statistics']})
    
    更新 statistics => probability
    注:这里statistics主要指统计得到的bayes值.
    """
    logging.info("Report program start.")
    logging.debug("Report config %s" % str(conf))
    if not "stock" in conf:
        conf["stock"] = Stock(conf)
    if not "date" in conf:
        conf["date"] = Date.getDate()

    # load train/statistics data
    if "statistics" in conf:
        statistics = conf.get("statistics")  # 载入指定日期的监控策略
    else:
        path = os.path.join(conf.get("SYS_HOME"), conf.get("BAYES_DATA_PATH", BAYES_DATA_PATH), conf["date"] + SUFFIX)
        statistics = Reader.read(path=path)

    # predict
    logging.info("Start strategic app.Date is %s" % conf["date"])
    strategic = Strategic(conf=conf)
    strategic.check()
    strategic.compute()
    strategic.dump()
    logging.info("Finish strategic compute of date %s " % conf["date"])

    # generate report
    report = Report(conf=conf)
    report.compute(strategic, statistics)
    report.check()
    report.dump()
    return report