(前复权和后复权技术分析)前复权和后复权什么意思

admin 16 0

"""Python 获取股票(未复权、前复权、后复权)行情数据上市公司除权除息后,股价通常会发生变化,在价格走势图上出现了一个缺口。但实际价值并没有变化。复权就是对股价和成交量进行权息修复,按照股票的 实际涨跌绘制股价成交量走势图,并把成交量调整为相同的价值口径。复权能 消除因除权除息造成的价格、成交量指标的走势不正常变动。前复权是以除权后的价格为基准来测算除权前股票的市场成本价。复权后价格=(复权前价格-现金红利)÷(1 流通股份变动比例)后复权是以除权前的价格为基准来测算除权后股票的市场成本价。复权后价格=复权前价格×(1 流通股份变动比例) 现金红利股票除权为利于分析一般使用前复权(不构成推荐)。"""import timeimport datetimeimport tushare as tsts.set_token('your token') #自行注册获取pro = ts.pro_api()def get_data_bar(ts_code='', adj='', start_date='', end_date='', retry_count=3, pause=2): #复权日线行情 adj ='qfq','hfq'代表前复权,后复权 for g in range(retry_count): try: df = ts.pro_bar(ts_code=ts_code, adj=adj, start_date=start_date, end_date=end_date) except: time.sleep(pause) else: return dfdef get_data_stock_daily(ts_code='', start_date='', end_date='', retry_count=3, pause=2): #不复权日线行情 for g in range(retry_count): try: df = pro.daily(ts_code=ts_code, start_date=start_date, end_date=end_date, fields='ts_code,trade_date,open,high,low,close,pre_close,change,pct_chg,vol,amount') except Exception as err: print(err) time.sleep(pause) else: return dfdef end_dt(days=0): try: time_temp = datetime.datetime.now() - datetime.timedelta(days=days) dt = time_temp.strftime('%Y%m%d') return dt except Exception as err: print('end_dt is err', err)if __name__ == '__main__': start_dt = end_dt(days=365) #行情开始日期 end_dt = end_dt(days=0) #行情终止日期 print(start_dt, end_dt) last_trade_dt = '20221031' #指定行情日期 code_wm = '000028.SZ' #指定股票代码 以比亚迪为例 #获取000028.SZ股票期间不复权行情 df_wm = get_data_stock_daily(ts_code=code_wm, start_date=start_dt, end_date=end_dt, retry_count=3, pause=2) print(df_wm.head(8)) #获取000028.SZ股票期间前复权行情 df_qfq = get_data_bar(ts_code=code_wm, adj='qfq', start_date=start_dt, end_date=end_dt, retry_count=3, pause=2) print(df_qfq.head(8)) # 获取000028.SZ股票期间前后权行情 df_hfq = get_data_bar(ts_code=code_wm, adj='hfq', start_date=start_dt, end_date=end_dt, retry_count=3, pause=2) print(df_hfq.head(8)) """运行结果 20211115 20221115 ts_code trade_date open high ... change pct_chg vol amount 0 000028.SZ 20221115 33.85 35.63 ... 1.15 3.3744 84531.78 293308.434 1 000028.SZ 20221114 31.66 34.39 ... 2.04 6.3670 88615.43 298084.693 2 000028.SZ 20221111 32.95 33.66 ... -0.35 -1.0806 59711.46 196521.266 3 000028.SZ 20221110 31.67 32.78 ... 0.63 1.9836 37789.35 122420.441 4 000028.SZ 20221109 31.70 32.15 ... 0.13 0.4110 18036.32 57442.850 5 000028.SZ 20221108 31.61 31.80 ... -0.23 -0.7219 28254.67 88723.821 6 000028.SZ 20221107 31.56 32.34 ... 0.01 0.0314 23762.12 75506.015 7 000028.SZ 20221104 31.70 31.99 ... 0.31 0.9829 19295.00 61308.707 [8 rows x 11 columns] ts_code trade_date open high ... change pct_chg vol amount 0 000028.SZ 20221115 33.85 35.63 ... 1.15 3.3744 84531.78 293308.434 1 000028.SZ 20221114 31.66 34.39 ... 2.04 6.3670 88615.43 298084.693 2 000028.SZ 20221111 32.95 33.66 ... -0.35 -1.0806 59711.46 196521.266 3 000028.SZ 20221110 31.67 32.78 ... 0.63 1.9836 37789.35 122420.441 4 000028.SZ 20221109 31.70 32.15 ... 0.13 0.4110 18036.32 57442.850 5 000028.SZ 20221108 31.61 31.80 ... -0.23 -0.7219 28254.67 88723.821 6 000028.SZ 20221107 31.56 32.34 ... 0.01 0.0314 23762.12 75506.015 7 000028.SZ 20221104 31.70 31.99 ... 0.31 0.9829 19295.00 61308.707 [8 rows x 11 columns] ts_code trade_date open ... pct_chg vol amount 0 000028.SZ 20221115 140.8871 ... 3.3744 84531.78 293308.434 1 000028.SZ 20221114 131.7721 ... 6.3671 88615.43 298084.693 2 000028.SZ 20221111 137.1412 ... -1.0806 59711.46 196521.266 3 000028.SZ 20221110 131.8137 ... 1.9836 37789.35 122420.441 4 000028.SZ 20221109 131.9386 ... 0.4110 18036.32 57442.850 5 000028.SZ 20221108 131.5640 ... -0.7219 28254.67 88723.821 6 000028.SZ 20221107 131.3559 ... 0.0314 23762.12 75506.015 7 000028.SZ 20221104 131.9386 ... 0.9829 19295.00 61308.707 [8 rows x 11 columns] Process finished with exit code 0 """ """ Pgabc 2022000032 author : Pgabc www.wmdbsoft.com 更多函数,安装工具包 pip install pgabc pgabc@sohu.com """

  • 随机文章
  • 热门文章
  • 热评文章

抱歉,评论功能暂时关闭!