当前位置:网站首页>How to obtain the basic ten heavy positions? -Know

How to obtain the basic ten heavy positions? -Know

2020-12-07 16:58:18 osc_ n77be92e

Today, let's have some technical .

I don't know if my friends still remember my article :

20200924 How can retail investors make money ?

There's real dry stuff in it :

The energy and ability of retail investors can't do the organization , The most obvious weakness of retail investors is Information asymmetry . therefore , Retail investors always have in their minds : I found a wonderful opportunity , No one else knows , I'm going to make a lot of money , Basically, it means to finish the calf .

In the trading market where real gold and silver are fighting , smart 、 How many people have sharp eyes , Retail investors want to make money through this strategy is to hit the stone with eggs .

What should retail investors really do ? To buy stocks with no asymmetric information .

To be specific, I'm going to buy Mingpai stocks , Buy stocks that you're all in favor of , Institutions like to buy and buy stocks , Because of the organization 、 Big investors are no better than us in these stocks .

There are always friends in the group asking me what I think of a certain stock ?

I always see that this stock market is worth 300 Below 100 million , I basically say it's gambling , Because at this time the fundamentals 、 Technical analysis is not important , Because you don't know what's under the dark card . Maybe it's a demon for you 10 Double return , It's also possible that thunderstorms can't turn you over again .

As a small San , There's no chance of a comeback . therefore , Don't make money like this , Gambling once will only make the final failure worse .

A lot of partners asked me what stocks I should buy , I say the stock pool is very simple to be honest , That's what the fund bought with heavy positions , I'll buy it too .

But China has thousands of funds , Each fund has dozens of shares , It's not the same again , Which stock is the fund love to buy ?

I'm going to show you how to do this kind of data today , I'm professional in doing this kind of thing .

First of all, we should configure python Environmental Science , Very simple. , You can refer to my tutorial :

https://github.com/hangsz/pandas-tutorialgithub.com

The first lesson .

We take Love fund ( Under the flag of the same flower ) Fund data :

Ranking of fund returns _ Fund data _ Tonghuashun financial network fund.10jqka.com.cn

1. The first step is to open the official website of love fund

import os
import time
import traceback

import pandas as pd
from selenium import webdriver

import utils

option = webdriver.ChromeOptions()
option.add_argument('headless')

driver = webdriver.Chrome('C:\chromedriver_win32\chromedriver.exe')
driver.get("http://fund.10jqka.com.cn/datacenter/sy/")
time.sleep(10)

2. Get all column names

driver.find_element_by_xpath('//tr[@class="tr_hover"]').text.split()
columns = [
    ' Serial number ',
    ' Fund code ',
    ' Fund name ',
    ' Related links ',
    ' Updated date ',
    ' Weekly earnings ',
    ' Monthly income ',
    ' Quarterly earnings ',
    ' Annual income ',
    ' Three years of earnings ',
    ' Today's earnings ',
    ' Since its establishment, the rate of return ',
    ' operation '
]

3. Access to all equity funds

#  Stock type 
driver.find_element_by_xpath('//dd[@type="gpx"]').click()
time.sleep(5)

#  Annual income ranking 
driver.find_element_by_xpath('//span[@sort="F011"]').click()
time.sleep(5)

for i in range(10):
    js = 'window.scrollTo(0, document.body.scrollHeight);'
    driver.execute_script(js)
    time.sleep(5)
else:

    js = 'var q=document.documentElement.scrollTop=0'
    driver.execute_script(js)
    time.sleep(5)

eles = driver.find_elements_by_xpath('//tbody[@id="containerMain"]/tr')

res = []
for ele in eles:
    res.append(ele.text.split())

res = pd.DataFrame(data=res, columns=columns)
res.drop(columns=[' Related links ', ' Today's earnings ', ' operation '], inplace=True)

res.to_excel('raw_data/ Equity funds .xlsx', header=True, index=False)

4. Access to all hybrid funds

#  mixed type 
driver.find_element_by_xpath('//dd[@type="hhx"]').click()
time.sleep(5)

#  Annual income ranking 
driver.find_element_by_xpath('//span[@sort="F011"]').click()
time.sleep(5)

for i in range(10):
    js = 'window.scrollTo(0, document.body.scrollHeight);'
    driver.execute_script(js)
    time.sleep(5)

else:
    js = 'var q=document.documentElement.scrollTop=0'
    driver.execute_script(js)
    time.sleep(5)

eles = driver.find_elements_by_xpath('//tbody[@id="containerMain"]/tr')

res = []
for ele in eles:
    res.append(ele.text.split())

res = pd.DataFrame(data=res, columns=columns)
res.drop(columns=[' Related links ', ' Today's earnings ', ' operation '], inplace=True)

res.to_excel('raw_data/ Mixed fund .xlsx', header=True, index=False)

5. Get the top 10 positions of each Equity Fund

#  Stock type 
driver.find_element_by_xpath('//dd[@type="gpx"]').click()
time.sleep(5)
#  Annual income ranking 
driver.find_element_by_xpath('//span[@sort="F011"]').click()
time.sleep(5)

for i in range(10):
    js = 'window.scrollTo(0, document.body.scrollHeight);'
    driver.execute_script(js)
    time.sleep(5)
else:
    js = 'var q=document.documentElement.scrollTop=0'
    driver.execute_script(js)
    time.sleep(5)

eles = driver.find_elements_by_xpath('//td[@class="links_td links_val"]/a')

for ele in eles[1:]:
    try:
        name = ele.get_attribute('text')
        href = ele.get_attribute('href')
        utils.get_top10_list(name, href)
    except Exception:

        traceback.print_exc()

6. Get the top 10 positions of hybrid funds

#  mixed type 
driver.find_element_by_xpath('//dd[@type="hhx"]').click()
time.sleep(5)

#  Annual income ranking 
driver.find_element_by_xpath('//span[@sort="F011"]').click()
time.sleep(5)

for i in range(10):
    js = 'window.scrollTo(0, document.body.scrollHeight);'
    driver.execute_script(js)
    time.sleep(5)
else:
    js = 'var q=document.documentElement.scrollTop=0'
    driver.execute_script(js)
    time.sleep(5)

eles = driver.find_elements_by_xpath('//td[@class="links_td links_val"]/a')

for ele in eles[1:]:
    try:
        name = ele.get_attribute('text')
        href = ele.get_attribute('href')
        utils.get_top10_list(name, href)
    except Exception:
        traceback.print_exc()

7. utils.py file

#coding: utf-8

import time
from selenium import webdriver
import pandas as pd

def get_top10_list(name, href):
    print(name, href)
    driver = webdriver.Chrome(r'C:\chromedriver_win32\chromedriver.exe')
    driver.get(href)

    js = 'var q=document.documentElement.scrollTop=200'
    driver.execute_script(js)
    time.sleep(5)

    driver.find_element_by_xpath('//a[@data-taid="tzzh"]').click()
    time.sleep(5)

    js = 'var q=document.documentElement.scrollTop=1000'
    driver.execute_script(js)
    time.sleep(5)

    year =  driver.find_element_by_xpath('//div[@id="zcgDate"]/div[1]/p').text
    month = driver.find_element_by_xpath('//div[@id="zcgDate"]/div[2]/p').text

    print(year, month)
    top10 = driver.find_elements_by_xpath('//div[@id="zcgList"]/div[3]/ul')
    title = top10[0].text.split('\n')

    buffer = []
    for x in top10[1:]:
        buffer.append(x.text.split('\n'))

    data = pd.DataFrame(data=buffer, columns=title)
 
    filename = 'raw_data/ fund /' + name + '.xlsx'
    sheet_name = year + ' year ' + month + ' quarter '

    with pd.ExcelWriter(filename) as writer:
        data.to_excel(writer, sheet_name=sheet_name, header=True, index=False)
 
    driver.quit()

def read_top10(name, sheet_name):
    try:
        filename = 'raw_data/ fund /'+ name + '.xlsx'
        df = pd.read_excel(filename, sheet_name)
    except Exception:
        print(name, 'does not exist')
        df = None
    return df

Too long to see

I know there are a lot of partners to say , I just want to see a 10 Big positions , You give me so much ?

Don't worry , If you don't want to do this, you can directly look at the data I've got .

Data links :

https://github.com/hangsz/datagithub.com


Of course, it's raw data , To really analyze the top 100 high-yield fund's top 10 or 20 heavy positions in the end what is , It needs further processing , Those who are interested can pay attention to me , Leave me a message .

Today, let's talk about how to get the data , In my opinion, this part is the most important part , After all, we can do a lot of analysis based on this . Another day to share the fund's heavy positions data , It's really delicious to copy homework directly .

版权声明
本文为[osc_ n77be92e]所创,转载请带上原文链接,感谢
https://chowdera.com/2020/12/20201207165510987r.html