亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Python繪制股票移動(dòng)均線的實(shí)例

 更新時(shí)間:2019年08月24日 16:40:01   作者:微巖  
今天小編就為大家分享一篇Python繪制股票移動(dòng)均線的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

1. 前沿

移動(dòng)均線是股票最進(jìn)本的指標(biāo),本文采用numpy.convolve計(jì)算股票的移動(dòng)均線

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.

計(jì)算公式:

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. 移動(dòng)均線計(jì)算

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繪制股票移動(dòng)均線的實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • 淺談Python 集合(set)類型的操作——并交差

    淺談Python 集合(set)類型的操作——并交差

    下面小編就為大家?guī)?lái)一篇淺談Python 集合(set)類型的操作——并交差。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2016-06-06
  • Python搶購(gòu)腳本的編寫(xiě)方法

    Python搶購(gòu)腳本的編寫(xiě)方法

    本文給大家分享一個(gè)秒殺搶購(gòu)腳本,幫助大家雙十二搶購(gòu)心愛(ài)的禮物,步驟很簡(jiǎn)單,下面小編給大家分享基于Python搶購(gòu)腳本的編寫(xiě)方法,感興趣的朋友一起看看吧
    2021-11-11
  • Python新手學(xué)習(xí)過(guò)程記錄之基礎(chǔ)環(huán)境:環(huán)境變量、版本區(qū)分、虛擬環(huán)境

    Python新手學(xué)習(xí)過(guò)程記錄之基礎(chǔ)環(huán)境:環(huán)境變量、版本區(qū)分、虛擬環(huán)境

    剛開(kāi)始接觸Python開(kāi)發(fā)語(yǔ)言,可能就會(huì)遇到一些棘手的問(wèn)題,比如電腦上不知不覺(jué)已經(jīng)安裝了多個(gè)python版本,python3.8/3.10/3.11,甚至一些軟件中也集成有python解釋器;那么我編寫(xiě)的python代碼,到底是使用哪個(gè)解釋器在執(zhí)行?我通過(guò)pip包管理工具安裝的依賴包到底在那個(gè)地方
    2024-05-05
  • Python autoescape標(biāo)簽用法解析

    Python autoescape標(biāo)簽用法解析

    這篇文章主要介紹了Python autoescape標(biāo)簽用法解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-01-01
  • Python解析json時(shí)提示“string indices must be integers”問(wèn)題解決方法

    Python解析json時(shí)提示“string indices must be integers”問(wèn)題解決方法

    這篇文章主要介紹了Python解析json時(shí)提示“string indices must be integers”問(wèn)題解決方法,結(jié)合實(shí)例形式分析了Python解析json字符串操作規(guī)范與相關(guān)使用技巧,需要的朋友可以參考下
    2019-07-07
  • Python中bisect的用法

    Python中bisect的用法

    這篇文章主要介紹了Python中bisect的用法,主要講述了針對(duì)數(shù)組的插入及排序操作,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2014-09-09
  • 基于Python的網(wǎng)頁(yè)自動(dòng)化工具DrissionPage的使用詳解

    基于Python的網(wǎng)頁(yè)自動(dòng)化工具DrissionPage的使用詳解

    DrissionPage 是一個(gè)基于 python 的網(wǎng)頁(yè)自動(dòng)化工具,它既能控制瀏覽器,也能收發(fā)數(shù)據(jù)包,還能把兩者合而為一,下面就跟隨小編一起來(lái)學(xué)習(xí)一下它的具體使用吧
    2024-01-01
  • tensorflow 限制顯存大小的實(shí)現(xiàn)

    tensorflow 限制顯存大小的實(shí)現(xiàn)

    今天小編就為大家分享一篇tensorflow 限制顯存大小的實(shí)現(xiàn),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-02-02
  • 基于python實(shí)現(xiàn)生成指定大小txt文檔

    基于python實(shí)現(xiàn)生成指定大小txt文檔

    這篇文章主要介紹了基于python實(shí)現(xiàn)生成指定大小txt文檔,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-07-07
  • Python 安裝setuptools和pip工具操作方法(必看)

    Python 安裝setuptools和pip工具操作方法(必看)

    下面小編就為大家?guī)?lái)一篇Python 安裝setuptools和pip工具操作方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-05-05

最新評(píng)論