Esempio n. 1
0
def main(modelPath,outpath,dt=None):
    df = dataio.getLabelAndFeature(config.LABEL,config.FEATURE_SELECT);
    turnoverFilter = dataio.getTurnoverRankFilter();
    maxContinousCloseDayFilter = dataio.getMaxContinousCloseDayFilter();
    secFilter = turnoverFilter & maxContinousCloseDayFilter;
    idxFilter = np.asarray([True if st in secFilter else False \
                            for st in df.index]);

    df = df[idxFilter]

    
    dts = df.index.get_level_values('tradeDate').values;
    if dt is None:
        dt = np.max(dts);
        pass;
    
    df = df[dts==dt];


    feature = df[config.FEATURE_SELECT].values;
    cls = pickle.load(open(modelPath));
    #pred = np.squeeze(cls.predict_proba(feature)[:,cls.classes_==1]);
    pred = np.squeeze(cls.predict(feature));

    dfout = pd.DataFrame(pred,
                         index=df.index,
                         columns = ['score']);
    
    dfout = dfout[dfout.index.map(lambda i:i[0] not in config.BLACK_LIST).get_values()]
    dfout.sort_values(['score'],inplace=True,ascending=False);

    dfout.to_csv(outpath,float_format='%g');
    pass;
Esempio n. 2
0
def main(modelPath,startDt,endDt,initMoney,strategy,reportPath,testStartDt):
    df = dataio.getLabelAndFeature(config.LABEL,config.FEATURE_SELECT);
    turnoverFilter = dataio.getTurnoverRankFilter();
    maxContinousCloseDayFilter = dataio.getMaxContinousCloseDayFilter();
    secFilter = turnoverFilter & maxContinousCloseDayFilter;
    idxFilter = np.asarray([True if st in secFilter else False \
                            for st in df.index]);

    df = df[idxFilter]
    
    feature = df[config.FEATURE_SELECT].values;
    dts = df.index.get_level_values('tradeDate');
    index = df.index.values;

    dt = startDt;
    while dt<=endDt:
        print(dt);
        filename = 'xgb_' + dt;
        stdout = sys.stdout;

        with open(os.path.join(reportPath,filename),'w') as fout:
            sys.stdout = fout;
            daily_test(feature,dts,index,initMoney,testStartDt,
                       os.path.join(modelPath,filename),
                       strategy);
            sys.stdout = stdout;
            pass;
        dt = utils_common.dtAdd(dt,1);
    pass;
Esempio n. 3
0
def main(modelPath, outpath, dt=None):
    df = dataio.getLabelAndFeature(config.LABEL, config.FEATURE_SELECT)
    turnoverFilter = dataio.getTurnoverRankFilter()
    maxContinousCloseDayFilter = dataio.getMaxContinousCloseDayFilter()
    secFilter = turnoverFilter & maxContinousCloseDayFilter
    idxFilter = np.asarray([True if st in secFilter else False \
                            for st in df.index])

    df = df[idxFilter]

    dts = df.index.get_level_values('tradeDate').values
    if dt is None:
        dt = np.max(dts)
        pass

    df = df[dts == dt]

    feature = df[config.FEATURE_SELECT].values
    cls = pickle.load(open(modelPath))
    #pred = np.squeeze(cls.predict_proba(feature)[:,cls.classes_==1]);
    pred = np.squeeze(cls.predict(feature))

    dfout = pd.DataFrame(pred, index=df.index, columns=['score'])

    dfout = dfout[dfout.index.map(
        lambda i: i[0] not in config.BLACK_LIST).get_values()]
    dfout.sort_values(['score'], inplace=True, ascending=False)

    dfout.to_csv(outpath, float_format='%g')
    pass
Esempio n. 4
0
def main(modelPath, startDt, endDt, initMoney, strategy, reportPath,
         testStartDt):
    df = dataio.getLabelAndFeature(config.LABEL, config.FEATURE_SELECT)
    turnoverFilter = dataio.getTurnoverRankFilter()
    maxContinousCloseDayFilter = dataio.getMaxContinousCloseDayFilter()
    secFilter = turnoverFilter & maxContinousCloseDayFilter
    idxFilter = np.asarray([True if st in secFilter else False \
                            for st in df.index])

    df = df[idxFilter]

    feature = df[config.FEATURE_SELECT].values
    dts = df.index.get_level_values('tradeDate')
    index = df.index.values

    dt = startDt
    while dt <= endDt:
        print(dt)
        filename = 'xgb_' + dt
        stdout = sys.stdout

        with open(os.path.join(reportPath, filename), 'w') as fout:
            sys.stdout = fout
            daily_test(feature, dts, index, initMoney, testStartDt,
                       os.path.join(modelPath, filename), strategy)
            sys.stdout = stdout
            pass
        dt = utils_common.dtAdd(dt, 1)
    pass
Esempio n. 5
0
def loadDataReg():
    df = dataio.getLabelAndFeature(config.LABEL, config.FEATURE_SELECT)
    df = df[df[config.LABEL] > -1]
    turnoverFilter = dataio.getTurnoverRankFilter();
    maxContinousCloseDayFilter = dataio.getMaxContinousCloseDayFilter();
    secFilter = turnoverFilter & maxContinousCloseDayFilter;
    idxFilter = np.asarray([True if st in secFilter else False \
                            for st in df.index]);

    df = df[idxFilter]

    dts = df.index.get_level_values('tradeDate')

    label = np.squeeze(df[[config.LABEL]].values)
    feature = df[config.FEATURE_SELECT].values
    return label, feature, dts
Esempio n. 6
0
def loadDataReg():
    df = dataio.getLabelAndFeature(config.LABEL, config.FEATURE_SELECT)
    df = df[df[config.LABEL] > -1]
    turnoverFilter = dataio.getTurnoverRankFilter()
    maxContinousCloseDayFilter = dataio.getMaxContinousCloseDayFilter()
    secFilter = turnoverFilter & maxContinousCloseDayFilter
    idxFilter = np.asarray([True if st in secFilter else False \
                            for st in df.index])

    df = df[idxFilter]

    dts = df.index.get_level_values('tradeDate')

    label = np.squeeze(df[[config.LABEL]].values)
    feature = df[config.FEATURE_SELECT].values
    return label, feature, dts
Esempio n. 7
0
from config import dataio;
import config;
import numpy as np;
import pandas as pd;
import sys;

if __name__=='__main__':
    df = dataio.getLabelAndFeature(config.LABEL,config.FEATURE_SELECT);
    df = df[df[config.LABEL]>-1];
    turnoverFilter = dataio.getTurnoverRankFilter();
    maxContinousCloseDayFilter = dataio.getMaxContinousCloseDayFilter();
    secFilter = turnoverFilter & maxContinousCloseDayFilter;
    idxFilter = np.asarray([True if st in secFilter else False \
                            for st in df.index]);

    df.rename(columns = {config.LABEL:'label'}, inplace=True);
    #df = df[idxFilter]

    df.to_csv(sys.argv[1]);
    pass;
Esempio n. 8
0
from config import dataio
import config
import numpy as np
import pandas as pd
import sys

if __name__ == '__main__':
    df = dataio.getLabelAndFeature(config.LABEL, config.FEATURE_SELECT)
    df = df[df[config.LABEL] > -1]
    turnoverFilter = dataio.getTurnoverRankFilter()
    maxContinousCloseDayFilter = dataio.getMaxContinousCloseDayFilter()
    secFilter = turnoverFilter & maxContinousCloseDayFilter
    idxFilter = np.asarray([True if st in secFilter else False \
                            for st in df.index])

    df.rename(columns={config.LABEL: 'label'}, inplace=True)
    #df = df[idxFilter]

    df.to_csv(sys.argv[1])
    pass