文章来源: 量化小课堂
#!/usr/bin/env python
#coding:utf-8
import pandas as pd
#导入数据
stock_data = pd.read_csv('./all_trading_data/stock data/sh600000.csv', parse_dates[1])
stock_data.sort_values('date', inplace=True)
ma_list = [5, 20 ,60]
for ma in ma_list:
stock_data['MA_' + str(ma)] = pd.rolling_mean(stock_data['close'], ma)
for ma in ma_list:
stock_data['EMA_' + str(ma)] = pd.ewma(stock_data['close'], span=ma)
stock_data.sort_values('date', ascending=False, inplace=True)
stock_data.csv('sh600000_ma_ema.csv', index=False)
网友评论