Esempio n. 1
0
def stock(code):
    stock = db.stock_by_code(code)
    filters = db.all_filters()
    return render_template('stock_detail.html',
                           VERSION=VERSION,
                           stock=stock,
                           filters=filters)
Esempio n. 2
0
def stocks_new_filter():
    filters = db.all_filters()
    name = '새필터' + str(len(filters) + 1)
    filter_id = db.save_filter({
        'name': name,
        'options': [],
    })
    return redirect(url_for('stocks', filter_id=filter_id))
Esempio n. 3
0
def etfs(etf_type='domestic'):
    momentum_base = 'month3' if etf_type == 'domestic' else 'month6'
    momentum_base_kr = '3개월' if etf_type == 'domestic' else '6개월'
    order_by = request.args.get('order_by', momentum_base)
    ordering = request.args.get('ordering', 'desc')
    etfs = db.all_etf(order_by=order_by, ordering=ordering, etf_type=etf_type)
    bond_etfs = ['148070', '152380']
    tags = defaultdict(list)
    for etf in etfs:
        for tag in etf.get('tags'):
            tags[tag].append(etf)
    tags = {k: ETFTag(k, v) for k, v in tags.items()}

    stat = {}
    etfs_by_momentum_base = [
        etf for etf in db.all_etf(
            order_by=momentum_base, ordering='desc', etf_type=etf_type)
        if etf[momentum_base] != 0
    ]
    no_bond_etfs = sorted(
        [etf for etf in etfs_by_momentum_base if etf['code'] not in bond_etfs],
        key=lambda x: x.get(momentum_base, 0),
        reverse=True)
    stat['absolute_momentum_momentum_base_avg'] = mean_or_zero(
        [etf[momentum_base] for etf in no_bond_etfs])
    stat['absolute_momentum_high'] = no_bond_etfs[0]
    stat['relative_momentum_etf'] = etfs_by_momentum_base[0]

    tags = sorted(tags.values(),
                  key=lambda t: getattr(t, momentum_base),
                  reverse=True)

    filters = db.all_filters()

    return render_template('etfs.html',
                           VERSION=VERSION,
                           INTEREST=INTEREST,
                           filters=filters,
                           etfs=etfs,
                           order_by=order_by,
                           ordering=ordering,
                           stat=stat,
                           tags=tags,
                           etf_type=etf_type,
                           momentum_base=momentum_base,
                           momentum_base_kr=momentum_base_kr)
Esempio n. 4
0
def stocks(status=None, filter_id=None):
    find = None
    filter_fscore = False
    stat = {}
    if status == 'starred':
        find = {'starred': True}
    elif status == 'owned':
        find = {'owned': True}
    elif status == 'starredorowned':
        find = {'$or': [{'starred': True}, {'owned': True}]}
    elif status == 'doubtful':
        find = {'doubtful': True}
    elif status == 'fscore':
        filter_fscore = True
    order_by = request.args.get('order_by', 'expected_rate')
    ordering = request.args.get('ordering', 'desc')

    filters = db.all_filters()
    current_filter = None
    if filter_id:
        current_filter = db.filter_by_id(filter_id)
    
    stocks = db.all_stocks(order_by=order_by, 
        ordering=ordering, find=find, 
        filter_by_expected_rate=find==None, 
        filter_bad=status!='bad', 
        filter_fscore=filter_fscore,
        filter_options=(current_filter.filter_options if current_filter else []))

    if status in ['owned', 'starred', 'starredorowned']:
        stat['low_pbr'] = len([stock for stock in stocks if stock.pbr <= 1])
        stat['high_expected_rate'] = len([stock for stock in stocks if stock.expected_rate >= 15])
        stat['fscore'] = len([stock for stock in stocks if stock.latest_fscore >= 3])
        stat['mean_expected_rate'] = mean_or_zero([stock.expected_rate for stock in stocks])
        stat['mean_expected_rate_by_low_pbr'] = mean_or_zero([stock.expected_rate_by_low_pbr for stock in stocks])
        stat['mean_future_roe'] = mean_or_zero([stock.future_roe for stock in stocks])
        
        qROE_numbers = [stock.QROEs[0][1] for stock in stocks if len(stock.QROEs) > 0]
        qROE_numbers = [float(roe_number) for roe_number in qROE_numbers if roe_number]
        stat['mean_qROEs'] = mean_or_zero(qROE_numbers)
        stat['qROEs_count'] = len(qROE_numbers)

    return render_template('stocks.html', stocks=stocks, order_by=order_by, ordering=ordering, status=status,
        available_filter_options=db.available_filter_options, filters=filters,
        current_filter=current_filter, stat=stat)