Three-minute tips! ! Are you afraid of losing money when you learn this trick?

Data analysis of a stock


Preface

This article uses the crawling of stock data to visualize the data analysis of this stock. If there is a problem with the analysis, you can leave a message below.


One, data crawling

I use the python financial data package tushare to crawl data. It also has an interface, and you can use different interfaces to get different data.

code show as below:

import tushare as ts
import pandas as pd
stock_data = ts.get_hist_data('600848')
stock_data.to_csv(r'C:\Users\GK丶taptap\Desktop\stock_data2.csv')

The picture of the csv file is as follows:

Insert picture description here

2. Data visualization analysis

1. Trends in the past three years

The number of points at the end of each day for this stock is visualized using matplotlib. The
code is as follows:

import numpy as np
import matplotlib.pyplot as plt 
df = pd.read_csv(r'C:\Users\GK丶taptap\Desktop\stock_data2.csv')
x = df['date']
y = df['close']
plt.figure(figsize=(10,10))
plt.plot(x, y)
plt.title('close-date')
plt.xlabel('date')
plt.ylabel('close')
plt.savefig(r'C:\Users\GK丶taptap\Desktop\3.jpg')
plt.show()

The graph obtained is as follows:
Insert picture description here

Looking at the trend chart, you know that this stock is still very unstable. When it falls, it does not bottom out, and the drop is very large, and there are few stages of the process, but it rises when it rises. It is very slow, takes a lot of time, and the process of rising is accompanied by a huge decline. In this way, many people will run away and will not get the final gain. And when it fell later, it was in 2020, and 2020 is also considered a slow bull period, and many stocks have risen a lot. Therefore, investment in this stock is not recommended.

2. The maximum range of stock points

Our analysis of the maximum value of the stock’s daily points can let us know that there are more positions in the maximum range to determine whether to invest in this stock.
We first divide the interval of the maximum value into the following four intervals:
[0,20] (20,25] (25,30] (30,+oo] The
code is as follows:

import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv(r'C:\Users\GK丶taptap\Desktop\stock_data2.csv')
plt.title('股票运势最高点分布(百分点)')#绘制标题
plt.rcParams['font.sans-serif']='SimHei'#设置中文显示
label=['20以下','20-25','25-30','30以上']#定义饼图的标签,标签是列表
explode=[0.01,0.01,0.01,0.01]#设定各项距离圆心n个半径
values=[len(df[df['high']<=20]),len(df[(df['high'] >20 ) & (df['high'] <=25)]),
len(df[(df['high'] >25 ) & (df['high'] <=30)]),len(df[df['high'] > 30])]
plt.pie(values,explode=explode,labels=label,autopct='%1.1f%%',radius=2)#绘制饼图
plt.savefig(r'C:\Users\GK丶taptap\Desktop\2.jpg')
plt.show()

Recommendation: 020 is continuously updated, the small circle of boutiques has new content every day, and the concentration of dry goods is extremely high.
There are everything you want to make connections and discuss technology!
Be the first to join the group and outperform your peers! (There is no fee for joining the group)
Click here to communicate and learn with Python developers.
Group number: 745895701
application and delivery :
Python software installation package, Python actual combat tutorial,
free collection of materials, including Python basic learning, advanced learning, crawling, artificial intelligence, automated operation and maintenance, automated testing, etc.

The resulting pie chart is as follows:

It can be seen from the figure that the position of the maximum distribution of the stock’s daily maximum points is between 20-25, and the minimum is below 20. The points of 25 and 25-30 are roughly the same. The stock’s daily upside space is still very large, but by The previous analysis shows that the stock will rise a lot at a certain time every day, but it is also accompanied by a big dive, which is very unfriendly to those who like to watch the market.

3. Daily low analysis

We use the scatter chart to analyze the daily lows to see how big their daily declines can be.
code show as below:

df = pd.read_csv(r'C:\Users\GK丶taptap\Desktop\stock_data2.csv')
x = df['date']
y = df['low']
plt.figure(figsize=(10,10))
plt.title("min-date")
plt.xlabel("date") 
plt.ylabel("min") 
plt.plot(x,y,"ob") 
plt.savefig(r'C:\Users\GK丶taptap\Desktop\6.jpg')
plt.show()

The resulting scatter plot is as follows:
Insert picture description here

From the scatter chart, we can see that the trend of the daily low point and the end trend are roughly the same, the high points are both 35, and the densely distributed places are all lower points, and the daily end value is roughly the same as the lowest value. This stock is not suitable for purchase.

4. High and low opening analysis

We analyze the starting value of the stock to determine whether it is open long low or open long low.
code show as below:

import numpy as np 
import matplotlib.pyplot as plt
import pandas as pd
df = pd.read_csv(r'C:\Users\GK丶taptap\Desktop\stock_data2.csv')
plt.savefig(r'C:\Users\GK丶taptap\Desktop\8.jpg')
df.hist('open')
plt.show()

The resulting histogram is as follows:

It can be seen from the figure that there are many times when the stock opens low, but its trend is not to open low and go high, but when it opens high, it goes high and opens low, which is very deceptive.


Three, summary

From the above four analyses, it can be seen that the Shanghai Lingang (code 600848) stock is not recommended to buy, not to open low and go high, but when it opens high, it goes low, and the previous conclusions show that the stock is very unstable.
Finally, there are risks in financial management and investment needs to be cautious. Please make reasonable investment allocations.

Guess you like

Origin blog.csdn.net/Python_xiaobang/article/details/113031514