def print_fund_ror_short(funds): print(''.join([ '%-47s' % '', '%-6s' % '年化收益率', '%-40s' % '', '%-5s' % '区间最大回撤', ])) print(''.join([ '%-5s' % '代码', '%-26s' % '名称', '%-6s' % '成立日期', ' ', '%-7s' % '1m', '%-7s' % '3m', '%-7s' % '6m', '%-7s' % '8m', '%-7s' % '9m', '%-7s' % '10m', '%-7s' % '12m', ' ', '%-5s' % '当前', '%-7s' % '2020q3', '%-7s' % '2020q2', '%-7s' % '2020q1', '%-7s' % '2019h2', '%-7s' % '2019h1', '%-s' % '2018', ])) print('-' * 140) for fund in funds: fmt = ''.join([ '%-7s', '%-s', '%-11s', '', '%-7s', '%-7s', '%-7s', '%-7s', '%-7s', '%-7s', '%-7s', ' ', '%-7s', '%-7s', '%-7s', '%-7s', '%-7s', '%-7s', '%-7s', ]) s = fmt % ( fund['code'], wpad(fund['name'], 28), fund['inception_date_text'], grace_format('% .03f', fund, 'aror.1m'), grace_format('% .03f', fund, 'aror.3m'), grace_format('% .03f', fund, 'aror.6m'), grace_format('% .03f', fund, 'aror.8m'), grace_format('% .03f', fund, 'aror.9m'), grace_format('% .03f', fund, 'aror.10m'), grace_format('% .03f', fund, 'aror.1y'), grace_format('% .03f', fund, 'mdd.current'), grace_format('% .03f', fund, 'mdd.2020q3'), grace_format('% .03f', fund, 'mdd.2020q2'), grace_format('% .03f', fund, 'mdd.2020q1'), grace_format('% .03f', fund, 'mdd.2019h2'), grace_format('% .03f', fund, 'mdd.2019h1'), grace_format('% .03f', fund, 'mdd.2018'), ) print(s)
def print_fund_ror_range(funds): print(''.join([ '%-48s' % '', '%-6s' % '区间收益率', ' ' * 45, '%-5s' % '区间最大回撤', ' ' * 18, '%s' % 'Sterling' ])) print(''.join([ '%-5s' % '代码', '%-26s' % '名称', '%-9s' % '成立日期', '%-8s' % '14➔', '%-7s' % '15➔', '%-8s' % '150612➔', '%-9s' % '160128➔', '%-7s' % '17➔19', '%-8s' % '180124➔', '%-7s' % '19➔', ' ', '%-5s' % '15➔', '%-5s' % '2016', '%-8s' % '180124➔', '%-6s' % '2019', '%-5s' % '2020', ' ', '%-s ' % '15➔19', '%-s' % '17➔19', ])) print('-' * 140) for fund in funds: # mdds = [] # for year in ['2020', '2019', '2018', '2017', '2016', '2015']: # if has_key(fund, 'mdd.%s' % year): # mdds.append(fund['mdd'][year]) # mdd_mean = mean(mdds) fmt = ''.join([ '%-7s', '%-s', '%-11s', ' ', '%-8s', # ror.2014_yet '%-8s', # ror.2015_yet '%-7s', # ror.20150612_yet '%7s ', # ror.20160128_yet '%-8s', # ror.2017_2019 '%-7s', # ror.20180124_yet '%-8s', # ror.2019_yet ' ', '%5s ', # mdd.2015_yet '%5s ', # mdd.2015_yet '%5s ', # mdd.20180124_yet '%5s ', # mdd.2019 '%5s ', # mdd.2020 ' ', '%5s ', # sterling_ratio.2015_2019 '%-s', # sterling_ratio.2017_2019 ]) s = fmt % ( fund['code'], wpad(fund['name'], 28), fund['inception_date_text'], grace_format('% .02f', fund, 'ror.2014_yet'), grace_format('% .02f', fund, 'ror.2015_yet'), grace_format('% .02f', fund, 'ror.20150612_yet'), grace_format('% .02f', fund, 'ror.20160128_yet'), grace_format('% .02f', fund, 'ror.2017_2019'), grace_format('% .02f', fund, 'ror.20180124_yet'), grace_format('% .02f', fund, 'ror.2019_yet'), grace_format('% .01f', fund, 'mdd.2015_yet'), grace_format('% .01f', fund, 'mdd.2016'), grace_format('% .01f', fund, 'mdd.20180124_yet'), grace_format('% .01f', fund, 'mdd.2019'), grace_format('% .01f', fund, 'mdd.2020'), grace_format('% .02f', fund, 'sterling_ratio.2015_2019'), grace_format('% .02f', fund, 'sterling_ratio.2017_2019'), ) print(s)
def print_fund_ror_range2(funds): print(''.join([ '%-48s' % '', '%-6s' % '区间收益率', ' ' * 46, '%-5s' % '区间最大回撤', ])) print(''.join([ '%-5s' % '代码', '%-26s' % '名称', '%-9s' % '成立日期', '%-7s' % '15➔', '%-8s' % '1607➔18', '%-9s' % '1607➔19', '%-8s' % '1607➔', '%-7s' % '17➔', '%-9s' % '180124➔', '%-7s' % '19➔', ' ', '%s' % '当前 ', '%-6s' % '2020', '%-6s' % '2019', '%-6s' % '2018', '%-6s' % '2017', '%-6s' % '2016', '%s' % '2015', ])) print('-' * 140) for fund in funds: fmt = ''.join([ '%-7s', '%-s', '%-10s', ' ', '%8s', # ror.2015_yet '%7s ', # ror.20160701_2018 '%7s ', # ror.20160701_2019 '%7s ', # ror.20160701_yet '%7s ', # ror.2017_yet '%7s ', # ror.20180124_yet '%7s ', # ror.2019_yet ' ', '%6s ', # mdd.current '%6s', # mdd.2020 '%6s', # mdd.2019 '%6s', # mdd.2018 '%6s', # mdd.2017 '%6s', '%6s', ]) s = fmt % ( fund['code'], wpad(fund['name'], 28), fund['inception_date_text'], grace_format('% .02f', fund, 'ror.2015_yet'), grace_format('% .02f', fund, 'ror.20160701_2018'), grace_format('% .02f', fund, 'ror.20160701_2019'), grace_format('% .02f', fund, 'ror.20160701_yet'), grace_format('% .02f', fund, 'ror.2017_yet'), grace_format('% .02f', fund, 'ror.20180124_yet'), grace_format('% .02f', fund, 'ror.2019_yet'), grace_format('% .02f', fund, 'mdd.current'), grace_format('% .02f', fund, 'mdd.2020'), grace_format('% .02f', fund, 'mdd.2019'), grace_format('% .02f', fund, 'mdd.2018'), grace_format('% .02f', fund, 'mdd.2017'), grace_format('% .02f', fund, 'mdd.2016'), grace_format('% .02f', fund, 'mdd.2015'), ) print(s)
def print_fund_ror_half_year(funds): print(''.join([ '%-5s' % '代码', '%-26s' % '名称', '%-6s' % '成立日期', '%-2s' % '', '%-6s' % '半年度收益率', '%-45s' % '', '%-5s' % '半年度最大回撤', ])) print(''.join([ '%-47s' % '', '%-8s' % '2020h2', '%-8s' % '2020h1', '%-8s' % '2019h2', '%-8s' % '2019h1', '%-8s' % '2018h2', '%-8s' % '2018h1', '%-8s' % '2017h2', # '%-8s' % '2017h1', ' ', '%-7s' % '2020h2', '%-7s' % '2020h1', '%-7s' % '2019h2', '%-7s' % '2019h1', '%-7s' % '2018h2', '%-7s' % '2018h1', ])) print('-' * 140) for fund in funds: fmt = ''.join([ '%-7s', '%-s', '%-11s', '', '%-8s', # ror.2020h2 '%-8s', # ror.2020h1 '%-8s', # ror.2019h2 '%-8s', # ror.2019h1 '%-8s', # ror.2018h2 '%-8s', # ror.2018h1 '%-8s', # ror.2017h2 # '%-8s', # ror.2017h1 ' ', '%-7s', # mdd.2020h2 '%-7s', # mdd.2020h1 '%-7s', # mdd.2019h2 '%-7s', # mdd.2019h1 '%-7s', # mdd.2018h2 '%-7s', # mdd.2018h1 ]) s = fmt % ( fund['code'], wpad(fund['name'], 28), fund['inception_date_text'], grace_format('% .03f', fund, 'ror.2020h2'), grace_format('% .03f', fund, 'ror.2020h1'), grace_format('% .03f', fund, 'ror.2019h2'), grace_format('% .03f', fund, 'ror.2019h1'), grace_format('% .03f', fund, 'ror.2018h2'), grace_format('% .03f', fund, 'ror.2018h1'), grace_format('% .03f', fund, 'ror.2017h2'), # grace_format('% .03f', fund, 'ror.2017h1'), grace_format('% .03f', fund, 'mdd.2020h2'), grace_format('% .03f', fund, 'mdd.2020h1'), grace_format('% .03f', fund, 'mdd.2019h2'), grace_format('% .03f', fund, 'mdd.2019h1'), grace_format('% .03f', fund, 'mdd.2018h2'), grace_format('% .03f', fund, 'mdd.2018h1'), ) print(s)
def print_fund_ror_year(funds): print(''.join([ '%-5s' % '代码', '%-26s' % '名称', '%-6s' % '成立日期', '%-2s' % '', '%-6s' % '年度收益率', '%-46s' % '', '%-5s' % '年度最大回撤', ])) print(''.join([ '%-47s' % '', '%-8s' % '2020', '%-8s' % '2019', '%-8s' % '2018', '%-8s' % '2017', '%-8s' % '2016', '%-8s' % '2015', '%-8s' % '2014', ' ', '%s' % '当前 ', '%-6s' % '2020', '%-6s' % '2019', '%-6s' % '2018', '%-6s' % '2017', '%-6s' % '2016', '%s' % '2015', ])) print('-' * 140) for fund in funds: fmt = ''.join([ '%-7s', '%-s', '%-11s', '', '%-8s', # ror.2020 '%-8s', # ror.2019 '%-8s', # ror.2018 '%-8s', # ror.2017 '%-8s', # ror.2016 '%-8s', # ror.2015 '%-8s', # ror.2014 ' ', '%-6s', '%-6s', '%-6s', '%-6s', '%-6s', '%-7s', '%-7s', ]) s = fmt % ( fund['code'], wpad(fund['name'], 28), fund['inception_date_text'], grace_format('% .03f', fund, 'ror.2020'), grace_format('% .03f', fund, 'ror.2019'), grace_format('% .03f', fund, 'ror.2018'), grace_format('% .03f', fund, 'ror.2017'), grace_format('% .03f', fund, 'ror.2016'), grace_format('% .03f', fund, 'ror.2015'), grace_format('% .03f', fund, 'ror.2014'), grace_format('% .02f', fund, 'mdd.current'), grace_format('% .02f', fund, 'mdd.2020'), grace_format('% .02f', fund, 'mdd.2019'), grace_format('% .02f', fund, 'mdd.2018'), grace_format('% .02f', fund, 'mdd.2017'), grace_format('% .02f', fund, 'mdd.2016'), grace_format('% .02f', fund, 'mdd.2015'), ) print(s)
def print_fund_ror_long2(funds): print(''.join([ '%-5s' % '代码', '%-26s' % '名称', '%-6s' % '成立日期', '%-2s' % '', '%-6s' % '累计收益率', '%-54s' % '', '%-5s' % '区间最大回撤', ])) print(''.join([ '%-47s' % '', '%-7s' % '1年', '%-7s' % '2年', '%-7s' % '3年', '%-7s' % '4年', '%-7s' % '5年', '%-7s' % '6年', '%-7s' % '7年', '%-7s' % '8年', ' ', '%-6s' % '1年', '%-6s' % '2年', '%-6s' % '3年', '%-6s' % '4年', '%-6s' % '5年', # '%s ' % '6年', ])) print('-' * 140) for fund in funds: fmt = ''.join([ '%-7s', '%-s', '%-11s', '', '%-8s', '%-8s', '%-8s', '%-8s', '%-8s', '%-8s', '%-8s', '%-8s', ' ', '%-7s', '%-7s', '%-7s', '%-7s', '%-7s', # '%-7s', ]) s = fmt % ( fund['code'], wpad(fund['name'], 28), fund['inception_date_text'], grace_format('% .03f', fund, 'ror.1y'), grace_format('% .03f', fund, 'ror.2y'), grace_format('% .03f', fund, 'ror.3y'), grace_format('% .03f', fund, 'ror.4y'), grace_format('% .03f', fund, 'ror.5y'), grace_format('% .03f', fund, 'ror.6y'), grace_format('% .03f', fund, 'ror.7y'), grace_format('% .03f', fund, 'ror.8y'), grace_format('% .03f', fund, 'mdd.1y'), grace_format('% .03f', fund, 'mdd.2y'), grace_format('% .03f', fund, 'mdd.3y'), grace_format('% .03f', fund, 'mdd.4y'), grace_format('% .03f', fund, 'mdd.5y'), ) print(s)
def print_fund_brief(funds, file=None): data = [] data.append(''.join([ ' ' * 90, '基金经理', ])) data.append(''.join([ '%-10s' % '类型', '%-5s' % '代码', '%-37s' % '名称', '%-8s' % '成立日期', '%s ' % '净值日期', '%s ' % '运作时间', '%s ' % '在任时间', '%-4s' % '总资产', '%-4s' % '仓位', '%-5s' % '基金经理', ])) data.append('-' * 140) for fund in funds: if 'inception_date_text' in fund: fmt = ''.join([ '%-s', '%s ', '%-s ', '%s ', '%s ', '%s ', '%s ', '%s ', '%s ', '%6s ', '%5s ', '%s', ]) s = fmt % ( wpad(fund['kind'], 12), fund['code'], wpad(fund['name'], 37), fund['inception_date_text'], fund.get('nav_date_text', ''), '%5.2f年' % (fund['days'] / 365.0), '%5.2f年' % (fund['max_manager_work_days'] / 365.0), '%7.1f' % fund['total_asset'], '%4.1f' % fund['asset_allocation_stock'], grace_format('% .02f', fund, 'sterling_ratio.2017_2019'), grace_format('% .02f', fund, 'sterling_ratio.2015_2019'), ' '.join([ i['name'] for i in fund['manager_history'][0]['managers'] ]), ) else: fmt = ''.join([ '%-s', '%s ', '%-s', ]) s = fmt % ( wpad(fund['kind'], 12), fund['code'], wpad(fund['name'], 37), ) s = s.rstrip() data.append(s) data.append('') s = '\n'.join(data) if file: print(s, file=file) else: print(s)
def main(): parser = argparse.ArgumentParser(add_help=False) parser.add_argument('--sort', help='按指定的指标排序') parser.add_argument('--uniq', action='store_true', help='同一基金的不同份额只保留一个') parser.add_argument('--short', action='store_true', help='查看较短时间的收益率') parser.add_argument('--long', action='store_true', help='查看较长时间的收益率') parser.add_argument('--long2', action='store_true', help='查看较长时间的收益率') parser.add_argument('--range', action='store_true', help='查看区间收益率 (2015至今, 20180124至今)') parser.add_argument('--range2', action='store_true', help='查看区间收益率 (2015至2019, 20180124至今)') parser.add_argument('--year', action='store_true', help='查看年度收益率') parser.add_argument('--hy', action='store_true', help='查看半年度收益率') parser.add_argument('--quarter', action='store_true', help='查看季度收益率') options, codes = parse_args(parser) if not options: return # 获取基金数据 pool = multiprocessing.dummy.Pool(40) funds = pool.map(partial(fund_detail, verbose=False), codes) funds = [i for i in funds if i] # 去重 if options['uniq']: uniq = defaultdict(list) for fund in funds: fn = fund['fullname'] uniq[fn].append(fund) for fn in uniq: uniq[fn].sort(key=lambda x: (-x[ 'days'], get_key(x, 'fees.sale_service') or 0, x['name'])) uniq = {i[0]['code'] for i in uniq.values()} funds = [i for i in funds if i['code'] in uniq] # # ***** 计算年化收益率 ***** # # for fund in funds: adjnavs = fund['adjnavs'] calc_range_ror(fund) calc_range_aror(fund) # last = datetime.datetime.fromtimestamp(adjnavs[-1][0] / 1000) # ytd_days = (last - datetime.datetime(2018, 12, 31)).days # if fund['days'] > ytd_days: # fund['aror']['ytd'] = calc_aror(adjnavs, ytd_days) * 100 if options['short']: if fund['days'] >= 30.42 * 2 + 30: fund['aror']['2m'] = calc_aror(adjnavs, 30.42 * 2) * 100 if fund['days'] >= 30.42 * 8 + 30: fund['aror']['8m'] = calc_aror(adjnavs, 30.42 * 8) * 100 if fund['days'] >= 30.42 * 9 + 30: fund['aror']['9m'] = calc_aror(adjnavs, 30.42 * 9) * 100 if fund['days'] >= 30.42 * 10 + 30: fund['aror']['10m'] = calc_aror(adjnavs, 30.42 * 10) * 100 if fund['days'] >= 365 * 1.0 + 30: fund['aror']['12m'] = float(fund['raw']['syl_1n']) if fund['days'] >= 365 * 2.0 + 30: fund['aror']['24m'] = calc_aror(adjnavs, 365 * 2) * 100 if fund['days'] >= 365 * 3.0 + 30: fund['aror']['36m'] = calc_aror(adjnavs, 365 * 3) * 100 if fund['days'] >= 365 * 4.0 + 30: fund['aror']['48m'] = calc_aror(adjnavs, 365 * 4) * 100 # # ***** 计算最大回撤 ***** # # for fund in funds: adjnavs = fund['adjnavs'] fund['drawdown'] = {} fund['drawdown']['current'] = ( 1 - adjnavs[-1][1] / max([i[1] for i in adjnavs[-60:]])) * 100 fund['drawdown']['3m'] = calc_max_drawdown(adjnavs, 30.42 * 3) * 100 if options['short']: if fund['days'] >= 30.42 * 8: fund['drawdown']['8m'] = calc_max_drawdown(adjnavs, 30.42 * 8) * 100 # last = datetime.datetime.fromtimestamp(adjnavs[-1][0] / 1000) # ytd_days = (last - datetime.datetime(2018, 12, 31)).days # if fund['days'] >= ytd_days: # fund['drawdown']['ytd'] = calc_max_drawdown(adjnavs, ytd_days) * 100 if fund['days'] >= 30.42 * 6: fund['drawdown']['6m'] = calc_max_drawdown(adjnavs, 30.42 * 6) * 100 if fund['days'] >= 30.42 * 9: fund['drawdown']['9m'] = calc_max_drawdown(adjnavs, 30.42 * 9) * 100 if fund['days'] >= 30.42 * 10: fund['drawdown']['10m'] = calc_max_drawdown(adjnavs, 30.42 * 10) * 100 if fund['days'] >= 365 * 1.0: fund['drawdown']['12m'] = calc_max_drawdown(adjnavs, 365 * 1.0) * 100 if fund['days'] >= 365 * 1.5: fund['drawdown']['18m'] = calc_max_drawdown(adjnavs, 365 * 1.5) * 100 if fund['days'] >= 365 * 2.0: fund['drawdown']['24m'] = calc_max_drawdown(adjnavs, 365 * 2.0) * 100 if fund['days'] >= 365 * 3.0: fund['drawdown']['36m'] = calc_max_drawdown(adjnavs, 365 * 3.0) * 100 if fund['days'] >= 365 * 3.5: fund['drawdown']['42m'] = calc_max_drawdown(adjnavs, 365 * 3.5) * 100 if fund['days'] >= 365 * 4.0 + 30: fund['drawdown']['48m'] = calc_max_drawdown(adjnavs, 365 * 4.0) * 100 # # ***** 计算短时间收益 ***** # # if options['short']: for fund in funds: calc_month_ror(fund) calc_quarter_ror(fund) calc_half_year_ror(fund) calc_range_ror(fund) calc_range_aror(fund) calc_year_ror(fund) # # ***** 计算长时间年化收益 ***** # # if options['long']: for fund in funds: calc_range_ror(fund) calc_range_aror(fund) # # ***** 计算长时间累计收益 ***** # # if options['long2']: for fund in funds: calc_range_ror(fund) # # ***** 计算区间收益 ***** # # if options['range'] or options['range2']: for fund in funds: calc_year_ror(fund) calc_range_ror(fund) # # ***** 计算年度收益 ***** # # if options['hy']: for fund in funds: calc_half_year_ror(fund) # # ***** 计算年度收益 ***** # # if options['year'] or options['sort'] == 'lv': for fund in funds: calc_year_ror(fund) # # ***** 计算季度收益 ***** # # if options['quarter']: for fund in funds: calc_quarter_ror(fund) # 排序 if options['sort']: if options['sort'] == 'lv': # 低波动优先排序 def rank(fund): rors = [ fund['ror']['2019'], fund['ror']['2018'], fund['ror']['2017'] ] if has_key(fund, 'ror.2016'): rors.append(fund['ror']['2016']) ror_mean = mean(rors) ror_stdev = stdev(rors) mdds = [ fund['mdd']['2020'], fund['mdd']['2019'], fund['mdd']['2018'], fund['mdd']['2017'] ] if has_key(fund, 'mdd.2016'): mdds.append(fund['mdd']['2016']) mdd_mean = mean(mdds) r = ror_mean - ror_stdev * 0.25 - mdd_mean * 0.25 return -r funds.sort(key=rank) else: factors = [] for factor in options['sort'].split(','): factor = factor.strip() if not factor: continue if factor[0] == '-': reverse = False factor = factor[1:] else: reverse = True samples = (get_key(i, factor) for i in funds) samples = [i for i in samples if i] if not samples: continue sample = samples[0] if isinstance(sample, (int, float)): padding = 0 elif isinstance(sample, str): padding = '' else: padding = None factors.append({ 'factor': factor, 'reverse': reverse, 'padding': padding, }) for factor in reversed(factors): funds.sort(key=lambda x: get_key(x, factor['factor']) or factor['padding'], reverse=factor['reverse']) # # ***** 打印结果 ***** # # if options['long']: print_fund_ror_long(funds) elif options['long2']: print_fund_ror_long2(funds) elif options['short']: print_fund_ror_short(funds) elif options['range']: print_fund_ror_range(funds) elif options['range2']: print_fund_ror_range2(funds) elif options['year']: print_fund_ror_year(funds) elif options['hy']: print_fund_ror_half_year(funds) elif options['quarter']: print(''.join([ '%-5s' % '代码', '%-26s' % '名称', '%-6s' % '成立日期', '%-2s' % '', '%-6s' % '季度收益率', '%-46s' % '', '%-5s' % '季度最大回撤', ])) print(''.join([ '%-47s' % '', '%-8s' % '2020q2', '%-8s' % '2020q1', '%-8s' % '2019q4', '%-8s' % '2019q3', '%-8s' % '2019q2', '%-8s' % '2019q1', '%-8s' % '2018q4', ' ', '%-7s' % '2020q2', '%-7s' % '2020q1', '%-7s' % '2019q4', '%-7s' % '2019q3', '%-7s' % '2019q2', ])) print('-' * 140) for fund in funds: fmt = ''.join([ '%-7s', '%-s' + ' ' * (28 - wcswidth(fund['name'])), '%-11s', '', '%-8s', # ror.2020q2 '%-8s', # ror.2020q1 '%-8s', # ror.2019q4 '%-8s', # ror.2019q3 '%-8s', # ror.2019q2 '%-8s', # ror.2019q1 '%-8s', # ror.2018q4 ' ', '%-7s', # mdd.2020q2 '%-7s', # mdd.2020q1 '%-7s', # mdd.2019q4 '%-7s', # mdd.2019q3 '%-7s', # mdd.2019q2 ]) s = fmt % ( fund['code'], fund['name'], fund['inception_date'].strftime('%Y-%m-%d'), grace_format('% .03f', fund, 'ror.2020q2'), grace_format('% .03f', fund, 'ror.2020q1'), grace_format('% .03f', fund, 'ror.2019q4'), grace_format('% .03f', fund, 'ror.2019q3'), grace_format('% .03f', fund, 'ror.2019q2'), grace_format('% .03f', fund, 'ror.2019q1'), grace_format('% .03f', fund, 'ror.2018q4'), grace_format('% .03f', fund, 'mdd.2020q2'), grace_format('% .03f', fund, 'mdd.2020q1'), grace_format('% .03f', fund, 'mdd.2019q4'), grace_format('% .03f', fund, 'mdd.2019q3'), grace_format('% .03f', fund, 'mdd.2019q2'), ) print(s) else: print(''.join([ '%-5s' % '代码', '%-26s' % '名称', '%-6s' % '成立日期', '%-2s' % '', '%-6s' % '年化收益率', '%-51s' % '', '%-5s' % '区间最大回撤', ])) print(''.join([ '%-47s' % '', '%-7s' % '1m', '%-7s' % '3m', '%-7s' % '6m', '%-8s' % '10m', '%-7s' % '1年', '%-7s' % '2年', '%-7s' % '3年', '%-7s' % '4年', ' ', '%-7s' % '6m', '%-6s' % '1年', '%-6s' % '2年', '%-6s' % '3年', '%s' % '42m', ])) print('-' * 140) for fund in funds: fmt = ''.join([ '%-7s', '%-s' + ' ' * (28 - wcswidth(fund['name'])), '%-11s', '', '%-7s', '%-7s', '%-7s', '%-8s', '%-8s', '%-8s', '%-8s', '%-8s', ' ', '%-7s', '%-7s', '%-7s', '%-7s', '%-7s', ]) s = fmt % ( fund['code'], fund['name'], fund['inception_date'].strftime('%Y-%m-%d'), '% .03f' % fund['aror']['1m'], grace_format('% .03f', fund, 'aror.3m'), grace_format('% .03f', fund, 'aror.6m'), grace_format('% .04f', fund, 'aror.10m'), grace_format('% .04f', fund, 'aror.12m'), grace_format('% .04f', fund, 'aror.24m'), grace_format('% .04f', fund, 'aror.36m'), grace_format('% .04f', fund, 'aror.48m'), grace_format('% .03f', fund, 'drawdown.6m'), grace_format('% .03f', fund, 'drawdown.12m'), grace_format('% .03f', fund, 'drawdown.24m'), grace_format('% .03f', fund, 'drawdown.36m'), grace_format('% .03f', fund, 'drawdown.42m'), ) print(s)