# Numpy&pandas（八）–股票分析实例

587-王同学

## 分析波动幅度

%matplotlib inline
import pandas as pd
import numpy as np
import os
import matplotlib.pyplot as plt
fname = '002001.csv'
#读取文件，将date列作为行索引，并解析为datetime类型

## 使用 resample 针对复权收盘价进行重采样

#求一个比例
(resampled.high - resampled.low) / resampled.low



## 增长曲线

# 600690.ss 000951.sz 002001.sz
stockid = '600690.sz'
stockfile = '600690.csv'
ds = pd.read_csv(os.path.join('yahoo-data', stockfile), index_col='Date', parse_dates=True)
#绘制折线图


### 增长倍数

# 最高增长倍数
total_max_growth

# 最大年均复合增长率
max_growth_per_year = total_max_growth ** (1.0 / (max_date.year - min_date.year))
max_growth_per_year

### 当前增长倍数及复合增长率

# 当前平均增长倍数
total_growth

# 年复合增长倍数
growth_per_year = total_growth ** (1.0 / (now_date.year - old_date.year))
growth_per_year

### 平均年化增长率

price_in_years = adj_price.to_period(freq='A').groupby(level=0).first()
price_in_years
price_in_years.plot(figsize=(8,6))

# 这里的关键信息：
# 计算年化收益率时，diff 应该要除以前一年的价格，即在前一年的价格的基础上上涨了多少，而不是在当前年的价格。
diff = price_in_years.diff()
rate_in_years =  diff / (price_in_years - diff)
rate_in_years

rate_in_years.mean()
rate_in_years.plot(kind='bar', figsize=(8,6))
X = [0, len(rate_in_years)]
Y = [0, 0]
plt.plot(X, Y, color='red', linestyle='-')

Vieu3.3主题

Q Q 登 录