分类
加密货币

指数移动平均线

代码输出的数据截图如下:

YunHao-Von/Electrician_Cup

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Use Git or checkout with SVN using the web URL.

Work fast with our official CLI. Learn more.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

About

Stars

Watchers

Forks

Releases

Packages 0

Languages

Footer

© 2022 GitHub, Inc.

You can’t perform that action at this time.

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.

YunHao-Von/Electrician_Cup

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Use Git or checkout with SVN using the web URL.

Work fast with our official 指数移动平均线 CLI. Learn more.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching 指数移动平均线 GitHub Desktop

If nothing happens, download 指数移动平均线 GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

About

Stars

Watchers

Forks

Releases

Packages 0

Languages

Footer

© 2022 GitHub, Inc.

You can’t perform that action at this time.

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.

指数移动平均线

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Footer

© 2022 GitHub, Inc.

You can’t perform that action at this time.

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.

【量化投资-python & pandas技巧系列】使用python计算移动平均线

【量化小讲堂 – python & pandas技巧系列】使用python计算各类移动平均线

计算移动平均线是最常见的需求,下面这段代码将完成以下三件事情:
1. 从csv格式的文件中导入股票数据,数据例图如下:

—————- —————- —————- —————- —————- —————- —————- —————- —————- —————- —————- —————- —————-
# -*- coding: utf-8 -*-
“””
@author: yucezhe
@contact: QQ:2089973054 email:[email protected]
“””
import pandas as pd

# ========== 从原始csv文件中导入股票数据,以浦发银行sh600000为例

# 导入数据 – 注意:这里请填写数据文件在您电脑中的路径
stock_data = pd.read_csv( ‘stock data/sh600000.csv’ , parse_dates =[ 1 ])

# 将数据按照交易日期从远到近排序
stock_data.sort( ‘date’ , inplace = True )

# ========== 计算移动平均线

# 分别计算5日、20日、60日的移动平均线
ma_list 指数移动平均线 = [ 5 , 20 , 60 ]

# 计算简单算术移动平均线MA – 注意:stock_data[‘close’]为股票每天的收盘价
for ma in ma_list:
stock_data[ ‘MA_’ + str (ma)] = pd.rolling_mean(stock_data[ ‘close’ ] , ma)

# 计算指数平滑移动平均线EMA
for ma in ma_list:
stock_data[ ‘EMA_’ + str (ma)] = pd.ewma(stock_data[ ‘close’ ] , span =ma)

# 将数据按照交易日期从近到远排序
stock_data.sort( ‘date’ , ascending = False , inplace = 指数移动平均线 True )

【量化投资-python & pandas技巧系列】使用python计算移动平均线

代码输出的数据截图如下:

现在想到的之后几期会讲的内容:
【量化小讲堂 – python & pandas技巧系列】如何在windows环境安装python和pandas
【量化小讲堂 – python & pandas技巧系列】如何在mac OSX环境安装python和pandas
【量化小讲堂 – python & pandas技巧系列】使用python计算KDJ指标
【量化小讲堂 – python & pandas技巧系列】使用python计算MACD指标
【量化小讲堂 – 投资策略系列】KDJ、MACD指标双金叉选股效果
【量化小讲堂 – python & pandas技巧系列】使用pytho将日线数据转换成周线、月线数据