金融数据分析(八)计算股票的超额收益率 您所在的位置:网站首页 累计收益率和年收益率 金融数据分析(八)计算股票的超额收益率

金融数据分析(八)计算股票的超额收益率

2024-05-28 16:16| 来源: 网络整理| 查看: 265

案例(三)简单金融数据分析 项目二:计算股票的超额收益率

设计一个程序,计算股票的季收益率和年收益率,并计算单支股票收益率相对同一时期股票市场平均收益率的超额收益率(即相对收益率)。

本项目采用tushare的Python SDK 获取数据 具体方法另开新篇。

# -*- coding: utf-8 -*- """ Created on Sat Sept 19 9:30:36 2020 @author: mly """ import tushare as ts import numpy as np import pandas as pd import matplotlib.pyplot as plt from matplotlib import ticker plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签 startday = '2015-01-01' endday = '2020-04-01' tscode = '600519' tsindx = 'sh' df1 = ts.get_k_data(tscode, start = startday, end = endday, ktype = 'M') df2 = ts.get_k_data(tsindx, start = startday, end = endday, ktype = 'M') df1.to_excel('600519.xlsx',index=False) df2.to_excel('sh.xlsx',index=False) df1=pd.read_excel('600519.xlsx',dtype={ 'code':'str'}) df2=pd.read_excel('sh.xlsx',dtype={ 'code':'str'}) df = df2[['date', 'close']].copy() df.rename(columns={ 'close': 'indclose'}, inplace = True) df = pd.merge(df[['date', 'indclose']],


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有