程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

3. Python quantitative trading - stock data preprocessing & decline trading return analysis

編輯:Python

Catalog

  • Preface
  • One 、tushare
  • Two 、 Stock data preprocessing
  • 3、 ... and 、 The output of the stock all closed higher than the opening 3% The above date
  • Four 、 The output of all the shares opened more than the day before yesterday's closing decline 2% Date
  • 5、 ... and 、 Case study : Analysis of trading income of decline
    • 1 - demand
    • 2 - Capture the original data according to the date
    • 3 - Buy stock calculation
    • 4 - Sell stock calculation
    • 5 - Revenue calculation
  • 6、 ... and 、jupyter note

Preface

  • Before that, we have learned the pre process of data analysis , Next we pass tushare Get stock data and preprocess

One 、tushare

  • tushare: Old official website address 、 New official website address
  • tushare install

Two 、 Stock data preprocessing

  • Use tushare Interface to get historical data of stocks :ts.set_token You need to register on the official website , Then you can get your own token

  • Save the acquired data to the local

  • Delete df in Unnamed Column data for

  • take trade_date To time series type

  • take trade_date As the row index of the source data

3、 ... and 、 The output of the stock all closed higher than the opening 3% The above date

  • (df['open'] - df['close']) / df['open'] > 0.03: You can set the date when the condition is met to True, Discontented is False

  • take boolean Value as the index of the source data

  • Take out the date data

Four 、 The output of all the shares opened more than the day before yesterday's closing decline 2% Date

  • Analysis of implementation ideas : Because today's opening needs to be compared with the closing of the previous day , We can close Move the whole down one bit ; In this way, we can integrate today's opening and yesterday's closing into the same line

5、 ... and 、 Case study : Analysis of trading income of decline

1 - demand

  • demand : If I start from 2010 year 1 month 1 The day begins , Buy on the first trading day of each month 1 Hand stock , Sell all the stocks on the last trading day every year , As of today , What's my income ?
  • analysis
    • Time node :2010-2020
    • First hand stocks :100 Shares
    • buy : A full year needs to buy 1200 Shares
    • sell : A full year needs to be sold 1200 Shares
    • The unit price for buying and selling shares : Are assumed to be the opening price

2 - Capture the original data according to the date

3 - Buy stock calculation

  • Filter out the row data on the first trading day of each month
  • Calculate the total purchase price

4 - Sell stock calculation

  • To filter out 2020 Years of data : because 2020 In, we only got 2 month , It's not the end of the year
  • Sell calculation

5 - Revenue calculation

  • Need to put 2020 Still held in 2 Hand stocks are valued and added to total earnings : The valuation price is based on 2 The closing price of the previous trading day on the last trading day of the month shall be calculated

6、 ... and 、jupyter note

Click to download jupyter note


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved