How programmers use Python to scientifically trade stocks

rookie monologue

I am a programmer and an old stock investor. I have been in the stock market for almost 5 years, and I have experienced both bull and bear markets. There were ups and downs, and I didn’t make much money. Last year, I started to use Python to start learning and researching quantitative investment, and started the road of scientific stock trading. It turns out that there is a shortcut to stock trading.

I believe that there should be some students in this group of programmers who like to spend some spare money to buy some funds, buy financial management, and speculate in stocks with high risks! But there is a saying in the stock market that "one gain, two equals and seven losses". The ups and downs of the stock market, there are gains and losses!

The most important thing in stock trading is mentality, plus technology! Today I will talk about my own experience, using Python to analyze stocks! To make money, at least three elements must be mastered:

  • Which stock to buy
  • when to buy
  • when to sell

1. Use Python to crawl stock data

Greed is the most taboo in stock trading, and it will double up at every turn. It is best to buy today, and the limit will be raised tomorrow! I think the mentality should be calm. Now ordinary financial management is generally 4-5%, and the better one is about 8%. It is very good to have a 15% return in stocks for a year. How to choose stocks is very important. I crawled all the important indicators and financial data of more than 3,400 stocks on the whole network.

1). Source of data

There are many channels to obtain stock data. Since you are playing with Python, it is better to build your own wheels to crawl. I have talked about a lot of crawler articles before. You can read the historical articles! It is not very difficult technically. This time I chose Oriental Fortune.com, and it took about 8-9 minutes to crawl through more than 3,400 stocks.

For example, for the data of Wuliangye, we need to obtain the closing price, year-on-year growth of net profit, price-to-book ratio, price-earnings ratio, closing price, net assets per share,
insert image description here
insert image description here
etc. , a total of more than 3,400 stocks, we select ['net profit','net profit year-on-year growth','price-to-book ratio','price-earnings ratio','closing price','net assets per share','earnings per share', 'Operating year-on-year growth', 'operating income'] 9 indicators.

A few points for reptiles:

1). Multithreading + shared queue

2). Data analysis Pay attention to abnormal stock values, such as some prices are suspended, some earnings are negative, some dynamic price-earnings ratios are empty, and some revenues are negative.

3). Be sure to turn off the power and continue climbing. After all, there are more than 3,400 stocks with more than 3400 values, and it is easy to have problems in the middle. You must consider continuing to climb

insert image description here

2). Data cleaning

We need to do some cleaning of the original data, and add some indicators. (net assets per share - stock price per share)/stock price per share, to get a gap ratio; at the same time, among these 9 indicators, I pay more attention to the year-on-year growth of net interest rate, So with a little data processing, the following table is obtained:
insert image description here
If the gap number is higher, it means that the stock price is far lower than the stock's net assets. If the stock's growth rate is high, such a stock is very good!

2. Scientific stock selection with Python

If you are a player looking for stability and hope to obtain stable returns, it is of course safer to choose stocks with low price-earnings ratios, that is, to choose stocks with net losses, or stocks with not too many losses and relatively high net profit growth. The stock is obviously a good stock. The stocks of the whole network are sorted by:

1). Sort by Gap:
insert image description here
China Coal Energy ranks first in the whole network, with a stock price of 4.94, but its net assets per share are 6.846, and its net profit growth is also good by 20%. Although Ganyue Expressway, which ranks second, has a lot of net losses , but the net profit is -47%, which is not very reliable.

At the same time, we found that among the more than 3,400 stocks, the top 10 with the highest cost performance found that 40% of the bank stocks. Let's take a closer look at the bank stocks.

2). Sort according to net profit growth
insert image description here
3). Comprehensively select 6 stocks

Based on the previous two stock selection strategies, we selected 6 stocks, looked at the growth rate of these stocks this year, and then compared the Shanghai Composite Index to see how the growth rate is: It is obvious that China Everbright Bank is a good stock, at least relatively
insert image description here
insert image description here
insert image description here
stable , These dozens of bank stocks should be pretty good!

4). Gold stocks in bank stocks

Since China Everbright Bank is so stable and the market has fallen by 7-8%, it can still go up, so let’s look for other bull stocks in the bank stocks: Bank of Guizhou, Bank of Ningbo and Bank of
insert image description here
Nanjing are undoubtedly the three very good banks share. If there is a big rise after May Day, you must leave a message!

After talking about stock selection, now it's time to buy stocks. Timing is very important. There are many trading strategies, such as the turtle trading method, which determine the time to buy and sell according to the moving average.

Finally: About Python technical reserves

It is good to learn Python whether it is employment or sideline business to make money, but to learn Python, you still need a study plan. Finally, everyone will share a full set of Python learning materials to help those who want to learn Python!

Friends, if you need it, you can scan the CSDN official certification QR code below on WeChat to get it for free [guaranteed 100% free] .

1. Learning routes in all directions of Python

The technical points in all directions of Python are sorted out to form a summary of knowledge points in various fields. Its usefulness lies in that you can find corresponding learning resources according to the above knowledge points to ensure that you can learn more comprehensively.
insert image description here

2. Essential development tools for Python

insert image description here

3. Excellent Python learning books

When I have learned a certain foundation and have my own understanding ability, I will read some books or handwritten notes compiled by my predecessors. These notes record their understanding of some technical points in detail. These understandings are relatively unique and can be learned. to a different way of thinking.
insert image description here

4. Python video collection

Watching the zero-based learning video is the fastest and most effective way to learn. Following the teacher's ideas in the video, it is still very easy to get started from the basics to the in-depth.
insert image description here

5. Practical cases

Optical theory is useless, you have to learn to follow along, and you have to do it yourself, so that you can apply what you have learned to practice. At this time, you can learn from some actual combat cases.insert image description here

6. Python exercises

Check the learning results.
insert image description here

7. Interview information

We must learn Python to find high-paying jobs. The following interview questions are the latest interview materials from first-line Internet companies such as Ali, Tencent, and Byte, and Ali bosses have given authoritative answers. After finishing this set The interview materials believe that everyone can find a satisfactory job.
insert image description here
insert image description here
Finally, don't let go of the enthusiasm you started at that time, and become stronger and better together.

Guess you like

Origin blog.csdn.net/libaiup/article/details/127776703