Пример #1
0
def main():
    if not os.path.exists(save_path):
        os.makedirs(save_path)


    # ------------------------------------------------
    stockinfo = class_stockinfo(findbillion_database)
    stock_all_list = stockinfo.get_stock_list()

    if debug == 1:
        stock_all_list = stock_all_list[:300]

    for (year_stat, year_est) in zip(year_stat_list, year_est_list):
        print('=======================================')
        print('Year: ' + format(year_est))

        print('search roe>15% ...')
        with Pool(num_cpu) as pool:
            stock_roe_15pa_list = pool.starmap(processing_roe_15pa, zip(stock_all_list, repeat(year_stat)))

        stock_list = []
        for i_stock in stock_roe_15pa_list:
            if i_stock is not None:
                stock_list.append(i_stock)


        # --------------------------------------------------
        print('search free cash>0 ...')
        with Pool(num_cpu) as pool:
            stock_free_cash_list = pool.starmap(processing_free_cash_positive , zip(stock_list, repeat(year_stat)))

        stock_list = []
        for i_stock in stock_free_cash_list:
            if i_stock is not None:
                stock_list.append(i_stock)
        stock_free_cash_list = stock_list



        # --------------------------------------------------
        # method 5 estimate eps, yield and growth rate
        # yield_buyin > 0.05 and hold_year = 1
        print('--------------------------------')
        print('method 5')

        '''
        with Pool(num_cpu) as pool:
            return_for_est_cash_dividend_by_netincome_ratio_with_revenue_growth_result = pool.starmap(processing_return_for_est_cash_dividend_by_netincome_ratio_with_revenue_growth, zip(stock_free_cash_list, repeat(year_stat), repeat(year_est), repeat(yield_buyin), repeat(hold_year)))
        '''
        #'''
        return_for_est_cash_dividend_by_netincome_ratio_with_revenue_growth_result = []
        for i_stock in stock_list:
            return_for_est_cash_dividend_by_netincome_ratio_with_revenue_growth_result.append(processing_return_for_est_cash_dividend_by_netincome_ratio_with_revenue_growth(i_stock, year_stat, year_est, yield_buyin, hold_year))
        #'''

        dict_to_csv_yeild_return(return_for_est_cash_dividend_by_netincome_ratio_with_revenue_growth_result, 'return_for_est_cash_dividend_by_netincome_ratio_with_revenue_growth_' + format(year_est) + '.csv',
                    save_path=save_path)
        stat_dict_return(return_for_est_cash_dividend_by_netincome_ratio_with_revenue_growth_result, 'return_for_est_cash_dividend_by_netincome_ratio_with_revenue_growth_' + format(year_est),
                         num_stock_sel=num_stock_sel, low_bound_pa=yield_buyin_target, save_path=save_path)
def main():
    if not os.path.exists(save_path):
        os.makedirs(save_path)

    #------------------------------------------------
    # list all stock
    stockinfo = class_stockinfo(findbillion_database)
    stock_list = stockinfo.get_stock_list()

    if debug == 1:
        stock_list = stock_list[:30]
    '''
    # For Debug
    for i_stock in stock_list:
        eps_true, eps_pred, err_percentage = processing_est_eps(i_stock, year)
        break_pt = 1
    '''

    #============================================
    for year_est in year_est_list:
        print('=======================================')
        print('Year: ' + format(year_est))
        #--------------------------------------------------
        # method 1: estimate all stock
        print('--------------------------------')
        print('method 1')
        with Pool(num_cpu) as pool:
            est_eps_result = pool.starmap(processing_est_eps,
                                          zip(stock_list, repeat(year_est)))

        #eps_true, eps_pred, err_percentage
        dict_to_csv(est_eps_result,
                    'est_eps_' + format(year_est) + '.csv',
                    save_path=save_path)
        stat_dict(est_eps_result,
                  'est_eps_' + format(year_est),
                  up_bound_pa=10,
                  low_bound_pa=-10,
                  save_path=save_path)

        # --------------------------------------------------
        # method 2: estimate the ROE>15% stock
        print('--------------------------------')
        print('method 2')
        with Pool(num_cpu) as pool:
            est_eps_result = pool.starmap(processing_est_eps_roe15,
                                          zip(stock_list, repeat(year_est)))

        dict_to_csv(est_eps_result,
                    'est_eps_roe15_' + format(year_est) + '.csv',
                    save_path=save_path)
        stat_dict(est_eps_result,
                  'est_eps_roe15_' + format(year_est),
                  up_bound_pa=10,
                  low_bound_pa=-10,
                  save_path=save_path)
from . import dataset_path

import sys
import os
sys.path.append('../../')
from findbillion.models.class_stockinfo import class_stockinfo
from findbillion.core.class_findbillion_database import class_findbillion_database


#-------------------------------------------------------------
findbillion_database = class_findbillion_database(dataset_path)
stockinfo = class_stockinfo(findbillion_database)

#-------------------------------------------------------------
class Test_class_fs_revenures_month():

    def test_get_PriceAvg(self):
        stock_list = stockinfo.get_stock_list()

        assert len(stock_list)>1000

    # TOOD: others
def main():
    if not os.path.exists(save_path):
        os.makedirs(save_path)

    # ------------------------------------------------
    stockinfo = class_stockinfo(findbillion_database)
    stock_all_list = stockinfo.get_stock_list()

    if debug == 1:
        stock_all_list = stock_all_list[:300]

    for (year_stat, year_est) in zip(year_stat_list, year_est_list):
        print('=======================================')
        print('Year: ' + format(year_est))

        print('search roe>15% ...')
        with Pool(num_cpu) as pool:
            stock_roe_15pa_list = pool.starmap(
                processing_roe_15pa, zip(stock_all_list, repeat(year_stat)))

        stock_list = []
        for i_stock in stock_roe_15pa_list:
            if i_stock is not None:
                stock_list.append(i_stock)

        # --------------------------------------------------
        # method 1 average PER Expected return > 30%
        print('--------------------------------')
        print('method 1')

        return_average_per = []
        for i_stock in stock_list:
            return_average_per.append(
                process_average_per(i_stock, year_est, year_stat, hold_year,
                                    expect_return))

        dict_to_csv_per_return(return_average_per,
                               'return_average_per_' + format(year_est) +
                               '.csv',
                               save_path=save_path)

        stat_dict_return(return_average_per,
                         'return_average_per_' + format(year_est),
                         low_bound_pa=-0.1,
                         check_return=check_return,
                         save_path=save_path)

        # --------------------------------------------------
        # method 2
        print('--------------------------------')
        print('method 2')

        print('search free cash>0 ...')
        with Pool(num_cpu) as pool:
            stock_free_cash_list = pool.starmap(
                processing_free_cash_positive,
                zip(stock_list, repeat(year_stat)))

        stock_list = []
        for i_stock in stock_free_cash_list:
            if i_stock is not None:
                stock_list.append(i_stock)
        stock_free_cash_list = stock_list

        return_average_per_free_cash = []
        for i_stock in stock_free_cash_list:
            return_average_per_free_cash.append(
                process_return_average_per_for_est_cash_dividend_by_netincome_ratio(
                    i_stock, year_est, year_stat, hold_year, expect_return,
                    yield_buyin))

        dict_to_csv_per_return(return_average_per_free_cash,
                               'return_average_per_free_cash_' +
                               format(year_est) + '.csv',
                               save_path=save_path)

        stat_dict_return(return_average_per_free_cash,
                         'return_average_per_free_cash_' + format(year_est),
                         low_bound_pa=-0.1,
                         check_return=check_return,
                         save_path=save_path)
Пример #5
0
def main():
    if not os.path.exists(save_path):
        os.makedirs(save_path)

    # ------------------------------------------------
    stockinfo = class_stockinfo(findbillion_database)
    stock_all_list = stockinfo.get_stock_list()

    if debug == 1:
        stock_all_list = stock_all_list[:100]

    for (year_stat, year_est) in zip(year_stat_list, year_est_list):
        print('=======================================')
        print('Year: ' + format(year_est))

        print('search roe>15% ...')
        with Pool(num_cpu) as pool:
            stock_roe_15pa_list = pool.starmap(
                processing_roe_15pa, zip(stock_all_list, repeat(year_stat)))

        stock_list = []
        for i_stock in stock_roe_15pa_list:
            if i_stock is not None:
                stock_list.append(i_stock)
        '''
        for i_stock in stock_all_list:
            financial_ratio = class_financial_ratio(findbillion_database)
            roe_avg = financial_ratio.get_ROE_avg(i_stock, year_stat, 4, 5)
            if roe_avg is not None and roe_avg > 0.15:
                stock_list.append(i_stock)
        '''

        # --------------------------------------------------
        # method 1
        print('--------------------------------')
        print('method 1')
        with Pool(num_cpu) as pool:
            est_cash_dividend_result = pool.starmap(
                processing_est_cash_dividend_average,
                zip(stock_list, repeat(year_stat), repeat(year_est)))

        # eps_true, eps_pred, err_percentage
        dict_to_csv(est_cash_dividend_result,
                    'est_cash_dividend_average_' + format(year_est) + '.csv',
                    save_path=save_path)
        stat_dict(est_cash_dividend_result,
                  'est_cash_dividend_average_' + format(year_est),
                  up_bound_pa=20,
                  low_bound_pa=-20,
                  save_path=save_path)
        # --------------------------------------------------
        # method 2
        print('--------------------------------')
        print('method 2')
        with Pool(num_cpu) as pool:
            est_cash_dividend_average_dividend_payout_ratio = pool.starmap(
                processing_est_cash_dividend_average_dividend_payout_ratio,
                zip(stock_list, repeat(year_stat), repeat(year_est)))

        dict_to_csv(est_cash_dividend_average_dividend_payout_ratio,
                    'est_cash_dividend_average_dividend_payout_ratio' +
                    format(year_est) + '.csv',
                    save_path=save_path)
        stat_dict(est_cash_dividend_average_dividend_payout_ratio,
                  'est_cash_dividend_average_dividend_payout_ratio_' +
                  format(year_est),
                  up_bound_pa=20,
                  low_bound_pa=-20,
                  save_path=save_path)

        # --------------------------------------------------
        # method 3
        print('--------------------------------')
        print('method 3')
        with Pool(num_cpu) as pool:
            est_cash_dividend_by_netincome_ratio = pool.starmap(
                processing_est_cash_dividend_by_netincome_ratio,
                zip(stock_list, repeat(year_stat), repeat(year_est)))

        dict_to_csv(est_cash_dividend_by_netincome_ratio,
                    'est_cash_dividend_by_netincome_ratio_' +
                    format(year_est) + '.csv',
                    save_path=save_path)
        stat_dict(est_cash_dividend_by_netincome_ratio,
                  'est_cash_dividend_by_netincome_ratio_' + format(year_est),
                  up_bound_pa=20,
                  low_bound_pa=-20,
                  save_path=save_path)

        # --------------------------------------------------
        # method 4
        print('method 4')
        print('search free cash>0 ...')
        with Pool(num_cpu) as pool:
            stock_free_cash_list = pool.starmap(
                processing_free_cash_positive,
                zip(stock_list, repeat(year_stat)))
        '''
        stock_free_cash_list = []
        for i_stock in stock_list:
            stock_free_cash_list.append(processing_free_cash_positive(i_stock, year_stat))
        '''
        '''
        stock_list = []
        for i_stock in stock_free_cash_list:
            if i_stock is not None:
                stock_list.append(i_stock)
        stock_free_cash_list = stock_list
        
        with Pool(num_cpu) as pool:
            est_cash_dividend_by_netincome_ratio = pool.starmap(processing_est_cash_dividend_by_netincome_ratio, zip(stock_free_cash_list, repeat(year_stat), repeat(year_est)))

        dict_to_csv(est_cash_dividend_by_netincome_ratio, 'est_cash_dividend_by_netincome_ratio_free_cashflow_'+format(year_est)+'.csv', save_path=save_path)
        stat_dict(est_cash_dividend_by_netincome_ratio, 'est_cash_dividend_by_netincome_ratio_free_cashflow_'+format(year_est), up_bound_pa=20, low_bound_pa=-20, save_path=save_path)
        '''

        # --------------------------------------------------
        # method 5
        print('method 5')
        print('search opetating activities ratio >0.5 ...')
        #with Pool(num_cpu) as pool:
        #    stock_free_cash_list = pool.starmap(processing_opetating_activities_ratio, zip(stock_list, repeat(year_stat) ))

        #'''
        stock_opetating_activities_ratio_list = []
        for i_stock in stock_list:
            stock_opetating_activities_ratio_list.append(
                processing_opetating_activities_ratio(i_stock, year_stat))
        #'''

        stock_list = []
        for i_stock in stock_opetating_activities_ratio_list:
            if i_stock is not None:
                stock_list.append(i_stock)
        stock_opetating_activities_ratio_list = stock_list

        with Pool(num_cpu) as pool:
            est_cash_dividend_by_netincome_ratio = pool.starmap(
                processing_est_cash_dividend_by_netincome_ratio,
                zip(stock_opetating_activities_ratio_list, repeat(year_stat),
                    repeat(year_est)))

        dict_to_csv(
            est_cash_dividend_by_netincome_ratio,
            'est_cash_dividend_opetating_activities_ratio_by_netincome_ratio_free_cashflow_'
            + format(year_est) + '.csv',
            save_path=save_path)
        stat_dict(
            est_cash_dividend_by_netincome_ratio,
            'est_cash_dividend_opetating_activities_ratio_by_netincome_ratio_free_cashflow_'
            + format(year_est),
            up_bound_pa=20,
            low_bound_pa=-20,
            save_path=save_path)