コード例 #1
0
ファイル: backTest.py プロジェクト: guanjunliu/OLP
def backTest():
    '''
    回测
    '''
    # 读入贷款协议数据,交易流水数据和签约产品数据
    reader = CMSBReader(cf.fieldName2fieldType)

    trnFeatLoanFilenames = [os.path.join(cf.loanDir, month) for month in cf.trnFeatMonths]
    trnFeatTransFilenames = [os.path.join(cf.transDir, month) for month in cf.trnFeatMonths]
    trnFeatProdFilenames = [os.path.join(cf.prodDir, month) for month in cf.trnFeatMonths]
    trnLabelLoanFilenames = [os.path.join(cf.loanDir, month) for month in cf.trnLabelMonths]
    tstFeatLoanFilenames = [os.path.join(cf.loanDir, month) for month in cf.tstFeatMonths]
    tstFeatTransFilenames = [os.path.join(cf.transDir, month) for month in cf.tstFeatMonths]
    tstFeatProdFilenames = [os.path.join(cf.prodDir, month) for month in cf.tstFeatMonths]
    tstLabelLoanFilenames = [os.path.join(cf.loanDir, month) for month in cf.tstLabelMonths]

    loanFieldName2Index, trnFeatLoans, trnFeatCustNum2ProtolNums = reader.readLoans(trnFeatLoanFilenames)
    transFieldName2Index, trnFeatTranss = reader.readTranss(trnFeatTransFilenames)
    prodFieldName2Index, trnFeatProds = reader.readProds(trnFeatProdFilenames)
    loanFieldName2Index, trnLabelLoans, trnLabelCustNum2ProtolNums = reader.readLoans(trnLabelLoanFilenames)
    loanFieldName2Index, tstFeatLoans, tstFeatCustNum2ProtolNums = reader.readLoans(tstFeatLoanFilenames)
    transFieldName2Index, tstFeatTranss = reader.readTranss(tstFeatTransFilenames)
    prodFieldName2Index, tstFeatProds = reader.readProds(tstFeatProdFilenames)
    loanFieldName2Index, tstLabelLoans, tstLabelCustNum2ProtolNums = reader.readLoans(tstLabelLoanFilenames)

    # 过滤贷款协议数据
    trnFeatLoans = filterLoans(cf.filterNames, loanFieldName2Index, trnFeatLoans, trnFeatCustNum2ProtolNums)
    tstFeatLoans = filterLoans(cf.filterNames, loanFieldName2Index, tstFeatLoans, tstFeatCustNum2ProtolNums)

    # ----------------------------------------------------------------------
    # 生成样本
    trn_samples_builder = SamplesBuilder(loanFieldName2Index, trnFeatLoans, trnFeatCustNum2ProtolNums, trnLabelLoans,
                                         transFieldName2Index, trnFeatTranss, prodFieldName2Index, trnFeatProds)
    tst_samples_builder = SamplesBuilder(loanFieldName2Index, tstFeatLoans, tstFeatCustNum2ProtolNums, tstLabelLoans,
                                         transFieldName2Index, tstFeatTranss, prodFieldName2Index, tstFeatProds)
    trn_samples = trn_samples_builder.buildSample()
    tst_samples = tst_samples_builder.buildSample()

    # ----------------------------------------------------------------------
    # 训练模型并预测
    fit_predict(cf.modelName, cf.modelParam, trn_samples, tst_samples)

    # 保存样本
    trn_samples.save(cf.trnSampFilename)
    tst_samples.save(cf.tstSampFilename)

    # 分析样本
    analyze_samples(trn_samples, tst_samples, 20, cf.analyFilename)

    # 计算评价指标
    gen_metrics(tst_samples, cf.metricFilename)
コード例 #2
0
ファイル: functionTest.py プロジェクト: i405817461/OLP
from OLP.Readers.CMSBReaders import CMSBReader
import config
from OLP.Readers.ReaderTools import UniPrinter
from OLP.Readers.FeatureBuilder import FeatureBuilder
from OLP.Readers.TransCounter import TransCounter
from OLP.Readers.ProdContactCounter import ProdContactCounter
from OLP.Readers.LoanCounter import LoanCounter

#tableObject = CMSBReader(config.fieldName2fieldType)
#table = tableObject.readProds(['prods.txt',])
#UniPrinter().pprint(table)
#tableFiltered = ProdContactCounter(table, config.trnFeatMonths[-1]+'/31').countProdContact()
#UniPrinter().pprint(tableFiltered)

tableObject = CMSBReader(config.fieldName2fieldType)
loanTable = tableObject.readLoans(['loan.txt','loan2.txt'])
loanCounter = LoanCounter(loanTable).countLoan()

transTable = tableObject.readTranss(['trans.txt',])
transCounter = TransCounter(transTable).countProp()

prodTable = tableObject.readProds(['prods.txt',])
prodCounter = ProdContactCounter(prodTable, config.trnFeatMonths[-1]+'/31').countProdContact()

UniPrinter().pprint(loanTable)
UniPrinter().pprint(transTable)
UniPrinter().pprint(prodTable)
print 'haha'
UniPrinter().pprint(loanCounter)
UniPrinter().pprint(transCounter)
UniPrinter().pprint(prodCounter)
コード例 #3
0
    return filter_


if __name__ == '__main__':
    '''
    main函数为测试代码,实际运行中不需要。
    '''

    from OLP.Readers.CMSBReaders import CMSBReader
    import config

    filenames = [
        '2014-02-28LoanInformation.txt', '2014-03-31LoanInformation.txt',
        '2014-04-30LoanInformation.txt', '2014-05-31LoanInformation.txt'
    ]
    s = CMSBReader(config.fieldName2fieldType)
    title2index, loans, custo2protol = s.readLoans(filenames)

    print(len(loans))
    print(custo2protol)
    filter1 = CleanedLoanFilter()
    filter2 = CustCodeFilter()
    filter3 = ThisMonthLoanFilter()

    title2index, loans, custo2protol = filter1.filter(title2index, loans,
                                                      custo2protol)
    title2index, loans, custo2protol = filter2.filter(title2index, loans,
                                                      custo2protol)
    title2index, loans, custo2protol = filter3.filter(title2index, loans,
                                                      custo2protol)
コード例 #4
0
ファイル: LoanFilter.py プロジェクト: i405817461/OLP
    mod = __import__(modName, globals(), locals(), [clsName], -1)
    cls = getattr(mod, clsName)
    filter_ = cls(**param)
    return filter_


if __name__ == '__main__':
    '''
    main函数为测试代码,实际运行中不需要。
    '''

    from OLP.Readers.CMSBReaders import CMSBReader
    import config

    filenames = ['2014-02-28LoanInformation.txt', '2014-03-31LoanInformation.txt', '2014-04-30LoanInformation.txt', '2014-05-31LoanInformation.txt']
    s = CMSBReader(config.fieldName2fieldType)
    title2index, loans, custo2protol = s.readLoans(filenames)

    print(len(loans))
    print(custo2protol)
    filter1 = CleanedLoanFilter()
    filter2 = CustCodeFilter()
    filter3 = ThisMonthLoanFilter()

    title2index, loans, custo2protol = filter1.filter(title2index, loans, custo2protol)
    title2index, loans, custo2protol = filter2.filter(title2index, loans, custo2protol)
    title2index, loans, custo2protol = filter3.filter(title2index, loans, custo2protol)

    #print loans
    print(len(loans))
    print(custo2protol)
コード例 #5
0
ファイル: functionTest.py プロジェクト: guanjunliu/OLP
from OLP.Readers.CMSBReaders import CMSBReader
import config
from OLP.Readers.ReaderTools import UniPrinter
from OLP.Readers.FeatureBuilder import FeatureBuilder
from OLP.Readers.TransCounter import TransCounter
from OLP.Readers.ProdContactCounter import ProdContactCounter
from OLP.Readers.LoanCounter import LoanCounter

#tableObject = CMSBReader(config.fieldName2fieldType)
#table = tableObject.readProds(['prods.txt',])
#UniPrinter().pprint(table)
#tableFiltered = ProdContactCounter(table, config.trnFeatMonths[-1]+'/31').countProdContact()
#UniPrinter().pprint(tableFiltered)

tableObject = CMSBReader(config.fieldName2fieldType)
loanTable = tableObject.readLoans(['loan.txt', 'loan2.txt'])
loanCounter = LoanCounter(loanTable).countLoan()

transTable = tableObject.readTranss([
    'trans.txt',
])
transCounter = TransCounter(transTable).countProp()

prodTable = tableObject.readProds([
    'prods.txt',
])
prodCounter = ProdContactCounter(prodTable, config.trnFeatMonths[-1] +
                                 '/31').countProdContact()

UniPrinter().pprint(loanTable)
UniPrinter().pprint(transTable)