Financial data indicators (historical moving volatility, mean)

Source: Internet
Author: User

1. Import functions

Import NumPy as NP Import Pandas as PD Import Matplotlib.pyplot as Plt Import Tushare as TS Import Math

2. Data acquisition

data = Ts.get_hist_data ('000012', start='2015-06-23', end= ' 2017-11-16 ')

3. Moving Average

# Use of scrolling windows
data[' 42d ']= pd.rolling_mean (data[' close '],window=42)
data[' 252d ' =pd.rolling_mean (data[' close '],window=252)
Print (data[[' close ', ' 42d ', ' 252d ']].tail ())

data[[' close ', ' 42d ', ' 252d ']].plot (figsize= (8,5))
Plt.show ()

4. Moving historical fluctuations

data['return']=np.log (data['Close']/data['Close'].shift (1)) data['Mov_vol'] = PD.ROLLING_STD (data['return'],window=252) *math.sqrt (252) data[['Close','return','Mov_vol']].plot (subplots=true,style='b', Figsize= (8,7) ) plt.show ()

Financial data indicators (historical moving volatility, mean)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.