current position:Home>Python data analysis - linear regression selection fund
Python data analysis - linear regression selection fund
2022-02-01 10:51:45 【first quarter of the moon】
This is my participation 11 The fourth of the yuegengwen challenge 8 God , Check out the activity details :2021 One last more challenge
1、 Survival is the first need of civilization .2、 Civilization is growing and expanding , But the total amount of matter in the universe remains basically the same .
1 Preface
In the previous chapter, we have a small try , Always in use python Crawlers to grab data , Then store the data information in the database , So far, the processing of basic information has been completed , Next, let's deal with the more advanced content , Start today with the trend analysis of the Fund .
2 Fund trend analysis
Fund trends , Is to choose some funds with strong performance , What kind of is strong ? That is to be stable , Step by step all the way north . Usually , Funds will follow a trend line up or down , The trend formation of funds is more certain than that of stocks . The following is an example , It shows Huaxia Zhongzheng new energy vehicles ETF The trend of , It can be seen that the trend of this fund basically follows the red trend line . What we need to do today is to use mathematics - The slope of this trend and the reliability of the trend table are calculated by linear regression .
The model for analyzing the fund trend here adopts linear regression , Assume that its trend is consistent with , y Is the corresponding rate of return , x For time .k The value is the slope . What we need to do now is to use the data of this group of funds to calculate this k value , So you can use this k Compare the value of the Fund .
3 Data capture and analysis
3.1 Fund data capture
Grab the data of the fund's historical rate of return
# Grab the historical rate of return data connection of the fund
http://api.fund.eastmoney.com/pinzhong/LJSYLZS?fundCode=515030&indexcode=000300&type=y
# Parameter description
fundCode For the fund code to be queried
indexcode Fund comparison benchmark data , The default is Shanghai and Shenzhen 300(000300)
type For the period of data query ,m A month q 3 Months hy 6 Months y A year try 3 year fiy 5 year sy This year se Maximum
Copy code
stay api In the data returned by the interface ,0 Represents fund data , 1 Is the average of similar funds ,2 Shanghai and Shenzhen 300 The data of . The specific implementation code is shown in Figure :
3.2 Data analysis
The way of data analysis is to use matplotlib
and sklearn.linear_model
, The first is the graphical presentation of data , The second is the linear analysis tool , Used to calculate the fund k value . About linear analysis , If you are interested, you can query the calculation details of linear analysis .
As shown in the figure below , Code for data model calculation and graphical presentation . New energy ETF Take the data , We got y= 0.3541x + b The trend line , The score of this linear model is 0.741. In fact, this score is already quite high , The higher the yield , The greater the fluctuation , The lower the fit with linear programming .
But are there any exceptions , Increase profits and short-term debts with Tianhong C(008647) For example , The score is quite high , Look at the graphic display, you can know , But bond funds k It's worth more than a stock fund k The value ratio is quite low , High risk , High return , Low risk , Low return . Return is compensation for risk .
4 summary
In this chapter , This paper introduces the use of linear programming to analyze the trend of funds , And use the method of quantitative analysis to analyze and screen the fund . Finally, this method can be used to analyze all funds , Select funds with strong trend for investment .
copyright notice
author[first quarter of the moon],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/02/202202011051425484.html
The sidebar is recommended
- Python * * packaging and unpacking details
- Python realizes weather query function
- Python from 0 to 1 (day 12) - Python data application 2 (STR function)
- Python from 0 to 1 (day 13) - Python data application 3
- Numpy common operations of Python data analysis series Chapter 8
- How to implement mockserver [Python version]
- Van * Python! Write an article and publish the script on multiple platforms
- Python data analysis - file reading
- Python data De duplication and missing value processing
- Python office automation - play with browser
guess what you like
-
Python series tutorial 127 -- Reference vs copy
-
Control flow in Python: break and continue
-
Teach you how to extract tables in PDF with Python
-
leetcode 889. Construct Binary Tree from Preorder and Postorder Traversal(python)
-
leetcode 1338. Reduce Array Size to The Half(python)
-
Object oriented and exception handling in Python
-
How to configure load balancing for Django service
-
How to embed Python in go
-
Python Matplotlib drawing graphics
-
Python object-oriented programming 05: concluding summary of classes and objects
Random recommended
- Python from 0 to 1 (day 14) - Python conditional judgment 1
- Several very interesting modules in Python
- How IOS developers learn Python Programming 15 - object oriented programming 1
- Daily python, Chapter 20, exception handling
- Understand the basis of Python collaboration in a few minutes
- [centos7] how to install and use Python under Linux
- leetcode 1130. Minimum Cost Tree From Leaf Values(python)
- leetcode 1433. Check If a String Can Break Another String(python)
- Python Matplotlib drawing 3D graphics
- Talk about deep and shallow copying in Python
- Python crawler series - network requests
- Python thread 01 understanding thread
- Analysis of earthquake distribution in the past 10 years with Python~
- You need to master these before learning Python crawlers
- After the old friend (R & D post) was laid off, I wanted to join the snack bar. I collected some data in Python. It's more or less a intention
- Python uses redis
- Python crawler - ETF fund acquisition
- Detailed tutorial on Python operation Tencent object storage (COS)
- [Python] comparison of list, tuple, array and bidirectional queue methods
- Go Python 3 usage and pit Prevention Guide
- Python logging log error and exception exception callback method
- Learn Python quickly and take a shortcut~
- Python from 0 to 1 (day 15) - Python conditional judgment 2
- Python crawler actual combat, requests module, python to capture headlines and take beautiful pictures
- The whole activity collected 8 proxy IP sites to pave the way for the python proxy pool, and the 15th of 120 crawlers
- Why can't list be used as dictionary key value in Python
- Python from 0 to 1 (day 16) - Python conditional judgment 3
- What is the python programming language?
- Python crawler reverse webpack, a real estate management platform login password parameter encryption logic
- Python crawler reverse, a college entrance examination volunteer filling platform encrypts the parameter signsafe and decrypts the returned results
- Python simulated Login, selenium module, python identification graphic verification code to realize automatic login
- Python -- datetime (timedelta class)
- Python's five strange skills will bring you a sense of enrichment in mastering efficient programming skills
- [Python] comparison of dictionary dict, defaultdict and orderdict
- Test driven development using Django
- Face recognition practice: face recognition using Python opencv and deep learning
- leetcode 1610. Maximum Number of Visible Points(python)
- Python thread 03 thread synchronization
- Introduction and internal principles of Python's widely used concurrent processing Library Futures
- Python - progress bar artifact tqdm usage