2-10作业 第一二题
来源:2-10 【作业】使用财务数据计算估值指标-简答题

lxltom
2021-06-11
2-10作业 第一二题
from jqdatasdk import *
import pandas as pd
import datetime
from Data.user_const import username, password
auth(username=username, password=password)
pd.set_option("display.max_rows", 100)
pd.set_option("display.max_columns", 100)
# 【作业】使用财务数据计算估值指标-简答题
"""
第一题
使用 Python 计算贵州茅台的最新市值数据,并验证其是否正确。
Tips:当天市值 = 当天股票收盘价 × 发行总股数。
"""
current_date = datetime.datetime.today()
current_date_strf = current_date.strftime("%Y-%m-%d")
all_stocks = get_all_securities()
gzmt_stock_code = all_stocks[all_stocks['display_name'] == '贵州茅台'].index[0]
gzmt_current_data = get_price(security=gzmt_stock_code, start_date=current_date_strf, end_date=current_date_strf,
frequency='daily')
gzmt_current_close = gzmt_current_data.iloc[0, 1]
gzmt_fundamentals = get_fundamentals(
query(valuation).filter(
valuation.code.in_([gzmt_stock_code])
),
date=current_date
)
total_capitalization = gzmt_fundamentals.capitalization[0]
current_market_val = gzmt_current_close * total_capitalization
print('当日{}收盘价为:{}'.format(gzmt_stock_code, gzmt_current_close))
print('{}当日市值为:{}'.format(gzmt_stock_code, current_market_val))
'''
第二题
使用 Python 计算贵州茅台的市盈率(静态),并验证其是否正确。
Tips:市盈率(静态) = 每股股价 / 每股收益(或者:市值 / 母公司净利润)
'''
gzmt_indicator = get_fundamentals(
query(indicator).filter(
indicator.code.in_(
[gzmt_stock_code]
)
),
statDate='2020'
)
# 每股盈利 (Earnings per share)
gzmt_eps = gzmt_indicator.loc[0, 'eps']
# 静态市盈率 (股价[当日收盘价] / 每股收益)
print('静态市盈率为: {:.2f}'.format(gzmt_current_close / gzmt_eps))
当日600519.XSHG收盘价为:2178.81
===============================
第一题:当日市值
600519.XSHG当日市值为:273701635.476372
第二题:市盈率(静态)
静态市盈率为: 58.62
写回答
1回答
-
DeltaF
2021-06-12
棒棒哒,祝学习愉快!
10
相似问题