Esempio n. 1
0
                m = item
            else:
                m = (item - expection)/(deviation *(2 **0.5))
            
            #res = 0.5 * (1 + norm.cdf(m))
            res = 0.5 * (1 + special.erf(m))
            if preValue !=None :
                ret = res - preValue 
            else:
                preValue = res
                ret = res
        return ret

if __name__ == '__main__':
    import doctest
    SYS_HOME=os.path.join(LIB_HOME,"..","..")
    sys.path.insert(0,SYS_HOME)
    from lib.util import Log,Conf
    conf=Conf.load(\
            os.path.join(SYS_HOME,"conf","stock.yaml"),
            os.path.join(SYS_HOME,"conf","downloader.yaml")
        )
    conf["SYS_HOME"] = SYS_HOME
    logPath=os.path.join(SYS_HOME , conf.get("LOG_PATH",""))
    Log.set(logPath = logPath)

    gaussian = Gaussian()
    stock = Stock(conf)
    stock.date = '20111024'
    doctest.testmod()
Esempio n. 2
0
            pre="sz"
        else:
            pre="sh"
        symbol=pre+strNum
        formatDate=time.strftime("%Y%m%d",time.strptime(date,"%Y%m%d"))
        url=detailSource.get("qq2") %(symbol, formatDate)
        return url

def handleDetail(code,date,parser , conf):
    url=getUrl(num = code,date = date,conf=conf)
    fetchData=Fetcher.fetch(url)
    parseData=parser.parse(fetchData)
    path = Dumper.getPath(code = code , date = date ,dataType = "detail" ,conf = conf)
    Dumper.dump(path = path,data = parseData)
    return True

if __name__ == '__main__':
    import doctest
    SYS_HOME=os.path.join(__dir__,"..","..","..")
    sys.path.insert(0,SYS_HOME)
    from lib.util import Conf,Log
    conf=Conf.load(\
            os.path.join(SYS_HOME,"conf","stock.yaml"),
            os.path.join(SYS_HOME,"conf","downloader.yaml"))
    Fetcher.DEBUG=True
    logPath=os.path.join(SYS_HOME , conf.get("LOG_PATH",""))
    Log.set(logPath = logPath , printLevel=logging.DEBUG)
    conf["SYS_HOME"]=SYS_HOME
    conf["DEBUG"]=True
    doctest.testmod()
Esempio n. 3
0
        logging.error("No %s commands." % cmd_name)
    else:
        cmd = imp.load_module(cmd_name, fp, pathname, description)
        cmd.run(conf = conf)
    finally:
        if fp:
            fp.close()

if __name__=="__main__" :
    if sys.argv[1:]:
        conf=Conf.load(\
            os.path.join(SYS_HOME,"conf","stock.yaml"),
            os.path.join(SYS_HOME,"conf","downloader.yaml"))
        conf["SYS_HOME"]=SYS_HOME
        conf.update(parseArgs(conf))
        Log.set(os.path.join(SYS_HOME,conf.get("LOG_PATH")))
        action=conf.get("action","run")
        dates=conf.get("dates")   #如果指定多个日期,则按顺序启动实例一个一个运行
        stockCache = {} #@todo add stockCache
        if not dates  or len(dates)==0:
            conf['date']=Date.getDate()
            execute(cmd_name = action,conf=conf)
        elif len(dates)>=1:
            for sDate in dates:
                conf["date"]=sDate
                if stockCache:
                    conf['stock']=stockCache
                execute(cmd_name = action,conf=conf)
    else:
        print __doc__
Esempio n. 4
0
"""
"""
init 
"""
import os,sys,logging
from lib.stk.element import Stock,Date,Dumper
from lib.util import Log,Conf
__dir__ = os.path.realpath(os.path.dirname(__file__))
APP_HOME=os.path.join(__dir__,"..")
SYS_HOME=os.path.join(APP_HOME,"..")
SYS_LIB_HOME=os.path.join(SYS_HOME,"lib")
sys.path.insert(0,SYS_HOME)
conf=Conf.load(os.path.join(SYS_HOME,"conf","stock.yaml"),os.path.join(SYS_HOME,"conf","downloader.yaml"))
conf["SYS_HOME"] = SYS_HOME
logPath=os.path.join(SYS_HOME , conf.get("LOG_PATH",""))
Log.set(logPath = logPath,printLevel = logging.ERROR)
stock = Stock(conf)
###################### TRAIN
"""
训练 整体 statistics 和 strategic likelihood
用 element/statistics来载入这些数据
"""
TRAIN_DATA_PATH = os.path.join(SYS_HOME,"data","train")

#train all days data and gaussian data
from lib.stk.statistics.Gaussian import Gaussian
subject = [[-0.1,-0.09],[-0.09,-0.08],[-0.08,-0.07],[-0.07,-0.06],[-0.06,-0.05],[-0.05,-0.04],[-0.04,-0.03],[-0.03,-0.02],[-0.02,-0.01],[-0.01,0],[0,0.01],[0.01,0.02],[0.02,0.03],[0.03,0.04],[0.04,0.05],[0.05,0.06],[0.06,0.07],[0.07,0.08],[0.08,0.09],[0.09,0.1]]


# strategic likelihood
from lib.stk.element.Strategic import Strategic