Example #1
0
def select_money(funddf):

    fund_sharpe = fi.fund_sharp_annual(funddf)
    codes = []
    tag = {}
    tag['sharpe1'] = fund_sharpe[0][0]
    codes.append(fund_sharpe[0][0])
    tag['sharpe2'] = fund_sharpe[1][0]
    codes.append(fund_sharpe[0][0])

    return codes, tag
Example #2
0
def select_bond(funddf, fund_tags):

    ratebond_codes = fund_tags['ratebond']
    credit_codes = fund_tags['creditbond']
    convertible_codes = fund_tags['convertiblebond']

    need_rate = True
    need_credit = True
    need_convertible = True

    fund_sharpe = fi.fund_sharp_annual(funddf)
    codes = []
    tag = {}
    for i in range(0, len(fund_sharpe)):

        code = fund_sharpe[i][0]

        if code in set(ratebond_codes) and need_rate:
            codes.append(code)
            need_largecap = False
            tag['ratebond'] = code
            #print code, i
            continue
        if code in set(credit_codes) and need_credit:
            codes.append(code)
            need_credit = False
            tag['creditbond'] = code
            #print code, i
            continue
        if code in set(convertible_codes) and need_convertible:
            codes.append(code)
            need_convertible = False
            tag['convertiblebond'] = code
            #print code, i
            continue

    #print fund_sharpe
    #print codes

    return codes, tag
Example #3
0
def bondfundfilter(start_date, end_date):

    indicator = {}

    funddf = data.bond_value(start_date, end_date)
    indexdf = data.bond_index_value(start_date, end_date, 'H11001.CSI')

    #按照基金创立时间过滤
    setuptime_data = fundsetuptimefilter(funddf.columns, start_date, data.bond_establish_data())


    #print setuptime_data
    #按照jensen测度过滤
    jensen_data    = jensenfilter(funddf, indexdf, rf, 0.5)
    #jensen_data    = sf.jensenfilter(funddf, indexdf, rf, 1.0)

    #按照索提诺比率过滤
    sortino_data   = sortinofilter(funddf, rf, 0.5)
    #sortino_data   = sf.sortinofilter(funddf, rf, 1.0)

    #按照ppw测度过滤
    ppw_data       = ppwfilter(funddf, indexdf, rf, 0.5)
    #ppw_data       = sf.ppwfilter(funddf, indexdf, rf, 1.0)
    #print ppw_data

    stability_data = stabilityfilter(funddf, 2.0 / 3)
    #stability_data = sf.stabilityfilter(funddf, 1.0)

    sharpe_data    = fi.fund_sharp_annual(funddf)

    #print stability_data

    #print 'jensen'
    jensen_dict = {}
    for k,v in jensen_data:
        jensen_dict[k] = v
    #print k, v
    #print
    #print 'sortino'


    sortino_dict = {}
    for k,v in sortino_data:
        sortino_dict[k] = v
    #print k,v

    #print
    #print 'ppw'
    ppw_dict = {}
    for k,v in ppw_data:
        ppw_dict[k] = v
    #print k,v

    #print
    #print 'statbility'
    stability_dict = {}
    for k,v in stability_data:
        stability_dict[k] = v
    #print k,v


    sharpe_dict = {}
    for k,v in sharpe_data:
        sharpe_dict[k] = v


    setuptime_set = set(setuptime_data)


    jensen_set = set()
    for k, v in jensen_data:
        jensen_set.add(k)


    sortino_set = set()
    for k, v in sortino_data:
        sortino_set.add(k)


    ppw_set = set()
    for k, v in ppw_data:
        ppw_set.add(k)


    stability_set = set()
    for k, v in stability_data:
        stability_set.add(k)

    codes = []



    for code in setuptime_set:
        if (code in jensen_set) and (code in sortino_set) and (code in ppw_set) and (code in stability_set):
            codes.append(code)


    for code in codes:
        ind = indicator.setdefault(code, {})
        ind['sharpe']    = sharpe_dict[code]
        ind['jensen']    = jensen_dict[code]
        ind['sortino']   = sortino_dict[code]
        ind['ppw']         = ppw_dict[code]
        ind['stability'] = stability_dict[code]


    indicator_set = set()
    for code in setuptime_set:
        indicator_set.add(code)

    indicator_codes = []
    indicator_datas = []


    for code in indicator_set:
        indicator_codes.append(code)
        indicator_datas.append([sharpe_dict.setdefault(code, None), jensen_dict.setdefault(code, None), sortino_dict.setdefault(code, None), ppw_dict.setdefault(code, None), stability_dict.setdefault(code, None)])


    indicator_df = pd.DataFrame(indicator_datas, index = indicator_codes, columns=['sharpe', 'jensen', 'sortino', 'ppw', 'stability'])
    indicator_df.to_csv('./tmp/bond_indicator_' + end_date + '.csv')


    f = open('./tmp/bondfilter_codes_' + end_date + '.csv','w')


    for code in codes:
        f.write(str(code) + '\n')

    f.flush()
    f.close()


    return codes, indicator
        #按照基金创立时间过滤
        setuptime_data = sf.fundsetuptimefilter(funddf.columns, start_date, data.establish_data())

        #按照jensen测度过滤
        jensen_data    = sf.jensenfilter(funddf, indexdf, const.rf, 1.0)

        #按照索提诺比率过滤
        sortino_data   = sf.sortinofilter(funddf, const.rf, 1.0)

        #按照ppw测度过滤
        ppw_data       = sf.ppwfilter(funddf, indexdf, const.rf, 1.0)
        #print ppw_data

        stability_data = sf.stabilityfilter(funddf, 3.0 / 3)

        sharpe_data    = fi.fund_sharp_annual(funddf)
    
    jensen_dict = {}
        for k,v in jensen_data:
                jensen_dict[k] = v
                #print k, v

        #print
        #print 'sortino'

        sortino_dict = {}
        for k,v in sortino_data:
                sortino_dict[k] = v
                #print k,v

        #print
Example #5
0
def fundfilter(start_date, end_date):

    indicator = {}

    funddf = data.fund_value(start_date, end_date)
    #print 'hehe'
    #print funddf['000457.OF']
    #print funddf['163001.OF'].to_csv('./tmp/163001.csv')
    indexdf = data.index_value(start_date, end_date, '000300.SH')

    #按照规模过滤
    scale_data     = sf.scalefilter(2.0 / 3)    
    #scale_data     = sf.scalefilter(1.0)    
    #print scale_data
    #按照基金创立时间过滤
    setuptime_data = sf.fundsetuptimefilter(funddf.columns, start_date, data.establish_data())

    #print setuptime_data
    #按照jensen测度过滤
    jensen_data    = sf.jensenfilter(funddf, indexdf, rf, 0.5)
    #jensen_data    = sf.jensenfilter(funddf, indexdf, rf, 1.0)

    #按照索提诺比率过滤
    sortino_data   = sf.sortinofilter(funddf, rf, 0.5)
    #sortino_data   = sf.sortinofilter(funddf, rf, 1.0)

    #按照ppw测度过滤
    ppw_data       = sf.ppwfilter(funddf, indexdf, rf, 0.5)
    #ppw_data       = sf.ppwfilter(funddf, indexdf, rf, 1.0)
    #print ppw_data

    stability_data = sf.stabilityfilter(funddf, 2.0 / 3)
    #stability_data = sf.stabilityfilter(funddf, 1.0)

    sharpe_data    = fi.fund_sharp_annual(funddf)    
    
    #print stability_data

    #print 'jensen'
    jensen_dict = {}
    for k,v in jensen_data:
        jensen_dict[k] = v
        #print k, v
    #print 
    #print 'sortino'            
                
    sortino_dict = {}
    for k,v in sortino_data:
        sortino_dict[k] = v
        #print k,v

    #print 
    #print 'ppw'    
    ppw_dict = {}
    for k,v in ppw_data:
        ppw_dict[k] = v
        #print k,v

    #print 
    #print 'statbility'
    stability_dict = {}
    for k,v in stability_data:
        stability_dict[k] = v
        #print k,v 

    sharpe_dict = {}
    for k,v in sharpe_data:
        sharpe_dict[k] = v

    '''
    codes = list(jensen_dict.keys())
    codes.sort()


    jensen_array = []
    sortino_array = []
    ppw_array = []
    stability_array = []

    for code in codes:
        jensen_array.append(jensen_dict[code] if jensen_dict.has_key(code) else 0)
        sortino_array.append(sortino_dict[code] if sortino_dict.has_key(code) else 0)
        ppw_array.append(ppw_dict[code] if ppw_dict.has_key(code) else 0)
        stability_array.append(stability_dict[code] if stability_dict.has_key(code) else 0)


    indicators = {'code':codes, 'jensen':jensen_array, 'sortino':sortino_array, 'ppw':ppw_array,'stability':stability_array}    

    frame = pd.DataFrame(indicators)            

    frame.to_csv('./wind/fund_indicator.csv')
    '''


    scale_set = set()
    for k, v in scale_data:
        scale_set.add(k)

    setuptime_set = set(setuptime_data)
                                            
    jensen_set = set()
    for k, v in jensen_data:
        jensen_set.add(k)
    


    sortino_set = set()
    for k, v in sortino_data:
        sortino_set.add(k)

    ppw_set = set()
    for k, v in ppw_data:
        ppw_set.add(k)


    stability_set = set()
    for k, v in stability_data:
        stability_set.add(k)

    #print 'jensen', '000457.OF' in jensen_set
    #print 'sortino', '000457.OF' in sortino_set
    #print 'ppw', '000457.OF' in ppw_set
    #print 'stability', '000457.OF' in stability_set

    codes = []

    for code in scale_set:
        if (code in setuptime_set) and (code in jensen_set) and (code in sortino_set) and (code in ppw_set) and (code in stability_set):
            codes.append(code)

    for code in codes:
        ind = indicator.setdefault(code, {})
        ind['sharpe']    = sharpe_dict[code]
        ind['jensen']    = jensen_dict[code]    
        ind['sortino']   = sortino_dict[code]
        ind['ppw']     = ppw_dict[code]
        ind['stability'] = stability_dict[code]


    '''
    indicator_str = "%s,%f,%f,%f,%f,%f\n"
    f = open('./tmp/indicator.csv','w')
    f.write("code,sharpe,jensen,sortino,ppw,stability\n")
    for code in codes:
        f.write(indicator_str % (code, sharpe_dict[code],jensen_dict[code], sortino_dict[code], ppw_dict[code], stability_dict[code]))
        #print code,jensen_dict[code], sortino_dict[code], ppw_dict[code], stability_dict[code]        

    f.flush()    
    f.close()
    '''

    #按照业绩持续性过滤
    #stability_data = sf.stabilityfilter(funddf[codes], 2.0 / 3)
    #print stability_data

    #codes = []    
    #for k, v in stability_data:
    #    codes.append(k)

    return codes, indicator
Example #6
0
                            ts.append(key)

            #fund_codes = list(tmp_codes)

            #all_funddf        = data.fund_value(start_date, end_date)

            #fund_codes        = list(indicator.keys())
            #allocation_funddf = data.fund_value(allocation_start_date, end_date)
            #allocation_funddf = allocation_funddf[fund_codes]


            ####################################################################
            future_funddf   = data.fund_value(end_date, future_end_date)
            future_funddf   = future_funddf[fund_pool]
            future_codes    = []
            future_funddf_sharp = fi.fund_sharp_annual(future_funddf)
            end_n     = (int)(len(future_funddf_sharp) * 0.25)
            start_n   = (int)(len(future_funddf_sharp) * 0.125)
            for n in range(start_n, end_n):
                future_codes.append(future_funddf_sharp[n][0])
            #fund_codes = future_codes
            #####################################################################


            return_data    = fi.fund_return(allocation_funddf)
            risk_data      = fi.fund_risk(allocation_funddf)
            return_dict = {}
            for k,v in return_data:
                return_dict[k] = v
            risk_dict = {}
            for k,v in risk_data:
Example #7
0
def select_stock(funddf, fund_tags):

    largecap_codes = fund_tags['largecap']
    smallcap_codes = fund_tags['smallcap']
    risefitness_codes = fund_tags['risefitness']
    declinefitness_codes = fund_tags['declinefitness']
    oscillationfitness_codes = fund_tags['oscillationfitness']
    growthfitness_codes = fund_tags['growthfitness']
    valuefitness_codes = fund_tags['valuefitness']

    need_largecap = True
    need_smallcap = True
    need_risefitness = True
    need_declinefitness = True
    need_oscillationfitness = True
    need_growthfitness = True
    need_valuefitness = True

    fund_sharpe = fi.fund_sharp_annual(funddf)
    codes = []
    tag = {}
    for i in range(0, len(fund_sharpe)):

        code = fund_sharpe[i][0]

        if code in set(largecap_codes) and need_largecap:
            codes.append(code)
            need_largecap = False
            tag['largecap'] = code
            #print code, i
            continue
        if code in set(smallcap_codes) and need_smallcap:
            codes.append(code)
            need_smallcap = False
            tag['smallcap'] = code
            #print code, i
            continue
        if code in set(risefitness_codes) and need_risefitness:
            codes.append(code)
            need_risefitness = False
            tag['rise'] = code
            #print code, i
            continue
        if code in set(declinefitness_codes) and need_declinefitness:
            codes.append(code)
            need_declinefitness = False
            tag['decline'] = code
            #print code, i
            continue
        if code in set(oscillationfitness_codes) and need_oscillationfitness:
            codes.append(code)
            need_oscillationfitness = False
            tag['oscillation'] = code
            #print code, i
            continue
        if code in set(growthfitness_codes) and need_growthfitness:
            codes.append(code)
            need_growthfitness = False
            tag['growth'] = code
            #print code, i
            continue
        if code in set(valuefitness_codes) and need_valuefitness:
            codes.append(code)
            need_valuefitness = False
            tag['value'] = code
            #print code, i
            continue

    #print fund_sharpe
    #print codes

    return codes, tag