def processing_est_cash_dividend_average_dividend_payout_ratio( stockid, year_stat, year_est): print(format(stockid) + '...') fs_dividendpolicy = class_fs_dividendpolicy(findbillion_database) dividend_cash_true = fs_dividendpolicy.get_Dividend_Cash(stockid, year_est) est_eps = class_est_eps(findbillion_database) eps_est = est_eps.est_last_4q_eps_by_netincome_ratio(stockid, year_stat, 4) est_yield = class_est_yield(findbillion_database) est_dividend_cash = est_yield.est_cash_dividend_by_dividend_payout_ratio( stockid, year_stat, eps_est) if dividend_cash_true is not None and est_dividend_cash is not None: if dividend_cash_true == 0: err_percentage = None else: err_percentage = (est_dividend_cash - dividend_cash_true) / dividend_cash_true * 100 else: dividend_cash_true, est_dividend_cash, err_percentage = None, None, None\ return { stockid: dividend_cash_true }, { stockid: est_dividend_cash }, { stockid: err_percentage }
def process_return_average_per_for_est_cash_dividend_by_netincome_ratio( stockid, year_est, year_stat, hold_year, expect_return, yield_buyin): #fs_dividendpolicy = class_fs_dividendpolicy(findbillion_database) est_eps = class_est_eps(findbillion_database) eps_est_last_4q = est_eps.est_last_4q_eps_by_netincome_ratio( stockid, year_est, 4) est_yield = class_est_yield(findbillion_database) est_dividend_cash = est_yield.est_cash_dividend_by_linear_regression_5y( stockid, year_stat, eps_est_last_4q) monthprice = class_monthprice(findbillion_database) price_buyin = monthprice.get_PriceHigh( stockid, year_est + 1, 1) # +1, estimate 2018 Q4 EPS, 2019/1 get revenues, if est_dividend_cash is not None and price_buyin is not None: est_dividend_cash_yield = est_dividend_cash / price_buyin else: est_dividend_cash_yield = None if stockid == 1234: debug_tmp = 1 PERatio = get_average_PERatio(stockid, year_est, 1, 3) eps_est_last_4q = est_eps.est_last_4q_eps_by_netincome_ratio( stockid, year_est, 4) if eps_est_last_4q is not None and PERatio is not None: price_target = eps_est_last_4q * PERatio else: price_target = 0 price_buyin = monthprice.get_PriceHigh(stockid, year_est + 1, 1) if price_buyin is not None: price_target_buyin_diff = (price_target - price_buyin) / price_buyin else: price_target_buyin_diff = None if price_buyin is not None and price_target_buyin_diff is not None and price_target_buyin_diff>expect_return \ and est_dividend_cash_yield is not None and est_dividend_cash_yield>yield_buyin: # and PERatio<20 price_high_hold = get_high_price_hold(stockid, year_est + 1, 1, hold_year) price_target_high_diff = (price_high_hold - price_target) / price_target return_max = (price_high_hold - price_buyin) / price_buyin else: price_buyin = None price_high_hold = None price_target_high_diff = None return_max = None return {stockid: price_target}, \ {stockid: PERatio}, \ {stockid: price_buyin}, \ {stockid: price_target_buyin_diff}, \ {stockid: price_high_hold}, \ {stockid: price_target_high_diff}, \ {stockid: return_max}
def main(): findbillion_database = class_findbillion_database(dataset_path) # est_eps = class_est_eps(findbillion_database) est_yield = class_est_yield(findbillion_database) #----------------------------------------- # ground truth of dividend_cash fs_dividendpolicy = class_fs_dividendpolicy(findbillion_database) dividend_cash = fs_dividendpolicy.get_Dividend_Cash(stockid, year_est) #----------------------------------------- # methed 1: average cash dividend dividend_cash_avg = est_yield.get_average_5y_cash_dividend( stockid, year_stat) error_method1 = (dividend_cash_avg - dividend_cash) / dividend_cash * 100 print("Average cash dividend: ") print("cash dividend (true): {:2.2f}".format(dividend_cash)) print("cash dividend (predict): {:2.2f}".format(dividend_cash_avg)) print("error of predict: {:2.2f}%".format(error_method1)) #-------------------------------------------------- # methed 2: average dividend payout ratio print("----------------------------------------") eps_est_last4q = est_eps.est_last_4q_eps_by_netincome_ratio( stockid, year_est, 4) est_dividend_cash = est_yield.est_cash_dividend_by_dividend_payout_ratio( stockid, year_stat, eps_est_last4q) error_method2 = (est_dividend_cash - dividend_cash) / dividend_cash * 100 print("Average cash dividend payout ratio: ") print("cash dividend (true): {:2.2f}".format(dividend_cash)) print("cash dividend (predict): {:2.2f}".format(est_dividend_cash)) print("error of predict: {:2.2f}%".format(error_method2)) #-------------------------------------------------- # methed 3: estimate dividend payout ratio by linear regression print("----------------------------------------") eps_est = est_eps.est_last_4q_eps_by_netincome_ratio(stockid, year_est, 4) est_dividend_cash = est_yield.est_cash_dividend_by_linear_regression_5y( stockid, year_stat, eps_est) error_method3 = (est_dividend_cash - dividend_cash) / dividend_cash * 100 print("Estimate cash dividend payout ratio by linear regression: ") print("cash dividend (true): {:2.2f}".format(dividend_cash)) print("cash dividend (predict): {:2.2f}".format(est_dividend_cash)) print("error of predict: {:2.2f}%".format(error_method3))
def processing_return_for_est_cash_dividend_by_netincome_ratio_with_revenue_growth(stockid, year_stat, year_est, yield_buyin, hold_year): print(format(stockid) + '...') # cash dividend (ground truth) fs_dividendpolicy = class_fs_dividendpolicy(findbillion_database) dividend_cash_true = fs_dividendpolicy.get_Dividend_Cash(stockid, year_est) # estimate eps est_eps = class_est_eps(findbillion_database) eps_est_last_4q = est_eps.est_last_4q_eps_by_netincome_ratio(stockid, year_est, 4) # estimate cash dividend by linear_regression est_yield = class_est_yield(findbillion_database) est_dividend_cash = est_yield.est_cash_dividend_by_linear_regression_5y(stockid, year_stat, eps_est_last_4q) # estimate revenue growth check_year = 3 year_end = year_est month_end = 12 year_start = year_end - check_year+1 # 2017/1~2019/12 month_start = 1 est_growth = class_est_growth(findbillion_database) growth_rate = est_growth.get_revenue_growth(stockid, year_start, month_start, year_end, month_end, 0) # buy price at next year/Jan monthprice = class_monthprice(findbillion_database) price_buyin = monthprice.get_PriceHigh(stockid, year_est+1, 1) # +1, estimate 2018 Q4 EPS, 2019/1 get revenues, if est_dividend_cash is not None and price_buyin is not None: est_dividend_cash_yield = est_dividend_cash/price_buyin else: est_dividend_cash_yield = None # buy when estimate cash yield > {yield_buyin} if price_buyin is not None and est_dividend_cash_yield is not None and est_dividend_cash_yield>yield_buyin and growth_rate is not None and growth_rate>0: price_buyin_hold = monthprice.getPriceClose(stockid, year_est+1+hold_year, 1) return_buyin = cal_retrun(stockid, price_buyin, price_buyin_hold, year_est, hold_year, fs_dividendpolicy) else: price_buyin = None price_buyin_hold = None return_buyin = None return {stockid: dividend_cash_true}, \ {stockid: est_dividend_cash}, \ {stockid: est_dividend_cash_yield}, \ {stockid: growth_rate}, \ {stockid: price_buyin}, \ {stockid: price_buyin_hold}, \ {stockid: return_buyin}
def func_est_eps(stockid, year_est): quarter_est = 4 financial_ratio = class_financial_ratio(findbillion_database) est_eps = class_est_eps(findbillion_database) eps_true = financial_ratio.get_eps_last_4q(stockid, year_est, quarter_est) eps_pred = est_eps.est_last_4q_eps_by_netincome_ratio( stockid, year_est, quarter_est) if eps_true is None or eps_pred is None: err_percentage = None elif eps_true != 0: err_percentage = (eps_pred - eps_true) / eps_true * 100 else: err_percentage = None #(eps_pred - 0.001) / 0.001 * 100 return eps_true, eps_pred, err_percentage
def main(): year = 2019 quarter = 4 stockid = 2330 findbillion_database = class_findbillion_database(dataset_path) financial_ratio = class_financial_ratio(findbillion_database) est_eps = class_est_eps(findbillion_database) eps_true = financial_ratio.get_eps_last_4q(stockid, year, quarter) eps_pred = est_eps.est_last_4q_eps_by_netincome_ratio( stockid, year, quarter) err_percentage = (eps_pred - eps_true) / eps_true * 100 print("eps (true): {:2.2f}".format(eps_true)) print("eps (predict): {:2.2f}".format(eps_pred)) print("error of predict: {:2.2f}%".format(err_percentage))
def process_average_per(stockid, year_est, year_stat, hold_year, expect_return): fs_dividendpolicy = class_fs_dividendpolicy(findbillion_database) est_eps = class_est_eps(findbillion_database) monthprice = class_monthprice(findbillion_database) if stockid == 1234: debug_tmp = 1 PERatio = get_average_PERatio(stockid, year_est, 1, 3) eps_est_last_4q = est_eps.est_last_4q_eps_by_netincome_ratio( stockid, year_est, 4) if eps_est_last_4q is not None and PERatio is not None: price_target = eps_est_last_4q * PERatio else: price_target = 0 price_buyin = monthprice.get_PriceHigh(stockid, year_est + 1, 1) if price_buyin is not None: price_target_buyin_diff = (price_target - price_buyin) / price_buyin else: price_target_buyin_diff = None if price_buyin is not None and price_target_buyin_diff is not None and price_target_buyin_diff > expect_return and PERatio < 20: price_high_hold = get_high_price_hold(stockid, year_est + 1, 1, hold_year) price_target_high_diff = (price_high_hold - price_target) / price_target return_max = (price_high_hold - price_buyin) / price_buyin else: price_buyin = None price_high_hold = None price_target_high_diff = None return_max = None return {stockid: price_target}, \ {stockid: PERatio}, \ {stockid: price_buyin}, \ {stockid: price_target_buyin_diff}, \ {stockid: price_high_hold}, \ {stockid: price_target_high_diff}, \ {stockid: return_max}
def main(): findbillion_database = class_findbillion_database(dataset_path) for year in year_list: print('----------------------------') print(year) # eps ground truth financial_ratio = class_financial_ratio(findbillion_database) eps_true = financial_ratio.get_eps_last_4q(stockid, year, quarter) # estimated eps est_eps = class_est_eps(findbillion_database) eps_pred = est_eps.est_last_4q_eps_by_netincome_ratio( stockid, year, quarter) # error err_percentage = (eps_pred - eps_true) / eps_true * 100 print("eps (true): {:2.2f}".format(eps_true)) print("eps (predict): {:2.2f}".format(eps_pred)) print("error of predict: {:2.2f}%".format(err_percentage))