Python绘制股票移动均线的实例
时间:2019-08-26
本文章向大家介绍Python绘制股票移动均线的实例,主要包括Python绘制股票移动均线的实例使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
1. 前沿
移动均线是股票最进本的指标,本文采用numpy.convolve计算股票的移动均线
2. numpy.convolve
numpy.convolve(a, v, mode='full')
Returns the discrete, linear convolution of two one-dimensional sequences.
The convolution operator is often seen in signal processing, where it models the effect of a linear time-invariant system on a signal [R17]. In probability theory, the sum of two independent random variables is distributed according to the convolution of their individual distributions.
If v is longer than a, the arrays are swapped before computation.
Parameters:
a : (N,) array_like First one-dimensional input array. v : (M,) array_like Second one-dimensional input array. mode : {‘full', ‘valid', ‘same'}, optional ‘full': By default, mode is ‘full'. This returns the convolution at each point of overlap, with an output shape of (N+M-1,). At the end-points of the convolution, the signals do not overlap completely, and boundary effects may be seen. ‘same': Mode same returns output of length max(M, N). Boundary effects are still visible. ‘valid': Mode valid returns output of length max(M, N) - min(M, N) + 1. The convolution product is only given for points where the signals overlap completely. Values outside the signal boundary have no effect.
Returns:
out : ndarray Discrete, linear convolution of a and v.
计算公式:
eg:
>>> import numpy as np >>> >>> np_list = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> >>> np_list array([1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> x = np.convolve(np_list, 2) >>> x array([ 2, 4, 6, 8, 10, 12, 14, 16, 18]) >>> x = np.convolve(np_list, [0.5, 0.5]) >>> x array([ 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 4.5])
3. 移动均线计算
def moving_average(x, n, type='simple'): x = np.asarray(x) if type == 'simple': weights = np.ones(n) else: weights = np.exp(np.linspace(-1., 0., n)) weights /= weights.sum() a = np.convolve(x, weights, mode='full')[:len(x)] a[:n] = a[n] return a
ma10 = moving_average(close_data, 10, 'simple') ma20 = moving_average(close_data, 20, 'simple') ax1.plot(data['date'], ma10, color='c', lw=2, label='MA (10)') ax1.plot(data['date'], ma20, color='red', lw=2, label='MA (20)')
4. 效果图
以上这篇Python绘制股票移动均线的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
- Python常见数据结构整理 Python常见数据结构整理
- “共享洗车机”落户咸阳,你怎么看?
- 蒋涛——软件是一个非常特殊的产业,一旦进入就再难挣脱
- Pechkin:html -> pdf 利器
- C#执行XSL转换
- javascript:算法笔记
- spring boot 登录注册 demo (一)
- linux学习:CentOS、Mac上SSH的设置以及SceureCRT中的文件上传下载
- 中关村成为北京“高精尖”产业发展主阵地
- jquery-barcode:js实现的条码打印
- 页面json 格式化+颜色高亮
- Python 里 and、or 的计算规则
- Python中赋值、浅拷贝与深拷贝
- git 简易使用说明
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 【译】代码中如何写出更有意义的命名
- nodejs源码分析之线程
- Java String Krains 2020-08-05
- 垃圾回收相关概念 Krains 2020-08-06
- 算法—判断字符串是否为IP地址
- 基于SpringBoot的Web前后端分离开发
- 【赵渝强老师】Docker的日志
- 超全递归技巧整理,这次一起拿下递归
- [译] React 测试驱动开发:从用户故事到产品
- 计算机基础之位运算 | 按位取反
- 关于php的ini文件相关操作函数浅析
- PHP中的输出缓冲控制
- SpringCloud微服务:基于Nacos组件,整合Dubbo框架
- [译] 使用 microbundle 打包 TypeScript 组件库
- 3分钟短文 | Laravel 获取模型查询生成的SQL语句