Python如何绘制股票移动均线

  介绍

小编给大家分享一下Python如何绘制股票移动均线,希望大家阅读完这篇文章之后都有所收获、下面让我们一起去探讨吧!

<强> 1。前沿

移动均线是股票最进本的指标,本文采用numpy.convolve计算股票的移动均线

<强> 2。numpy.convolve

numpy。卷积(a、v模式=& # 39;全# 39;)

返回离散、线性卷积两> a :, (N) array_like      ,First  one-dimensional  input 数组。      ,v : (M) array_like      ,Second  one-dimensional  input 数组。      ,mode :{“全# 39;,,”有效# 39;,,“相同# 39;},,可选的      ,“全# 39;:      By 默认情况下,才能,mode  is ,“全# 39;只却;能够returns 从而convolution  at  each  point  of 重叠,,with  an  output  shape  of  (N + m - 1)只at 从而end-points  of 从而,卷积,从而signals  do  not  overlap 完全,以及boundary  effects  may  be 观察。   ,“相同# 39;:      Mode 才能same  returns  output  of  length 马克斯(M, N)只Boundary  effects 断开连接;still 可见。   ,“有效# 39;:      Mode 才能valid  returns  output  of  length 马克斯(M, N),安康;min (M, N), +, 1只,convolution  product  is  only  given  for  points  where 从而signals  overlap 完全只Values  outside 从而signal  boundary  have  no 效果。

<>强劲的回报:

out : ndarray      ,离散,linear  convolution  of  a 以及v。

<强>计算公式:

 Python如何绘制股票移动均线

,

在祝辞祝辞,import  numpy  as  np   在在在,   祝辞祝辞祝辞,np_list =, np.array ([1, 2, 3, 4, 5, 6, 7, 8, 9))   在在在,   在祝辞祝辞np_list   数组([1,2,3,4,5,6,7,8,9))   在祝辞祝辞,x =, np.convolve (np_list, 2)   在祝辞祝辞x   阵列((,2,4,6,8,10,12日,14日,16日,18))   在祝辞祝辞,x =, np.convolve (np_list, [0.5, 0.5])   在祝辞祝辞x   数组([,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=& # 39;简单# 39;):=,,x  np.asarray (x)==,if  type  & # 39;简单# 39;:   时间=weights 才能;np.ones (n)   ,其他的:   weights 才能=,np.exp (np.linspace (1。,, 0。,, n))      ,weights /=, weights.sum ()=,,a  np.convolve (x),重量,,模式=& # 39;全# 39;)(len (x)):   ,一个[:n]=, [n]   以前,return 
, ma10 =, moving_average (close_data, 10日,& # 39;简单# 39;)=,,ma20  moving_average (close_data, 20日,& # 39;简单# 39;)
  
  ,ax1.plot(数据(& # 39;日期# 39;],,ma10,,颜色=& # 39;c # 39;,, lw=2,,标签=& # 39;MA  (10) & # 39;)
  ,ax1.plot(数据(& # 39;日期# 39;],,ma20,,颜色=& # 39;红色# 39;,,lw=2,,标签=& # 39;MA  (20) & # 39;) 

<强> 4。效果图

 Python如何绘制股票移动均线

Python是什么意思

Python是一种跨平台的,具有解释性,编译性,互动性和面向对象的脚本语言,其最初的设计是用于编写自动化脚本,随着版本的不断更新和新功能的添加,常用于用于开发独立的项目和大型项目。

看完了这篇文章,相信你对“Python如何绘制股票移动均线”有了一定的了解,如果想了解更多相关知识,欢迎关注行业资讯频道,感谢各位的阅读!

Python如何绘制股票移动均线