This is the 19th day of my participation in the August More Text Challenge

A list,

I’ve been working on the fund for months, so I’m sitting around today and seeing if I can program it. – Collecting fund data and analyzing it

Here take liquor as an example, I believe that those who have played the fund all know that liquor fund has been hot searched for several times and everyone knows it in the fund list, so I choose liquor as an example (the most important is 2021-1-25, liquor increased by 6.35%, what is this concept!! If you buy $100, you make $6.35.

A little too much bullshit. Let’s move on.

2. Collecting funds

Analysis of the

The first is the page, here the egg Roll fund web page to collect data

https://danjuanapp.com/funding/161725?channel=1300100141

Copy the code

The code name of liquor fund is: 161725

If you look at the data packet in F12, you can see that the web page is asynchronously loading the data

The access link is

https://danjuanapp.com/djapi/fund/nav/history/161725? size=200&page=1

Copy the code

Json data can be returned when it is accessed by the browser. At the same time, we also found that the latest number of data of different funds can be obtained by changing the code 161725 and size.

programming

First, request data through Requests. Code is the corresponding fund code, where 161725 is liquor fund and SIZE is the corresponding data amount

code = 161725
size = 365
url = "https://danjuanapp.com/djapi/fund/nav/history/"+str(code)+"? size="+str(size)+"&page=1"
 
 
headers = {'User-Agent': 'the Mozilla / 5.0 (Windows NT 6.3; Win64; x64; The rv: 84.0) Gecko / 20100101 Firefox 84.0 / ',
          }
res = requests.get(url, headers=headers)
res.encoding = 'utf-8'
s = json.loads(res.text)
Copy the code

After we get the data. Print from before to now (in reverse order) and separate by month

s = s['data'] ['items']
f = ((s[len(s)-1] ['date']).split("-"))1]
 
 
for j in range(len(s)-1, -1, -1):
    i = s[j]
    m = (i['date'].split("-"))
    if m[1] == f:
        try:
            date = i['date']
            percentage = i['percentage']
            value = i['value']
            print("date=" + str(date) + ",percentage=" + str(percentage) + ",value=" + str(value))
        except:
            pass
    else:
        f = m[1]
        try:
            date = i['date']
            percentage = i['percentage']
            value = i['value']
            print("date=" + str(date) + ",percentage=" + str(percentage) + ",value=" + str(value))
        except:
            pass
        print("-- -- -- -- -- -- -- -- -- -- -- -- -- -- --")
Copy the code

The results are as follows:

Visual analysis

1. Month-on-month comparisons

def analysis1(x,y1,y2) :
    myfont = font_manager.FontProperties(fname="C:\\Windows\\Fonts\\simhei.ttf")
    a=x
    b_14=y1
    b_15=y2
 
 
    bar_width = 0.25
    x_14 = list(range(len(a)))
    x_15 = list(i + bar_width for i in x_14)
 
 
    # Set graphics size
    plt.figure(figsize=(20.8), dpi=80)
    plt.bar(range(len(a)), b_14, width=bar_width, label="Early")
    plt.bar(x_15, b_15, width=bar_width, label="The end")
 
 
    # Set legend
    plt.legend(prop=myfont)
    #
    plt.xlabel("Month",fontproperties=myfont)
    plt.ylabel("Value",fontproperties=myfont)
    # Set the X-axis scale
    plt.xticks(x_15, a, fontproperties=myfont)
    plt.savefig("./mutiy.png")
    plt.show()
Copy the code

1 rendering

Analysis:

As can be seen from the bar chart above, the monthly value in recent months is greater than the initial value, indicating that these months are all profitable, especially the period from 2020 to December, which is the most profitable period. The period from 2020 to August was the biggest period of loss. Overall, the months of the whole year were still profitable.

2. Monthly highs and lows

###2. The highest rise and the lowest fall of the month
def analysis2(x,y1,y2) :
    myfont = font_manager.FontProperties(fname="C:\\Windows\\Fonts\\simhei.ttf")
    a=x
    b_14=y1
    b_15=y2
 
 
    bar_width = 0.25
    x_14 = list(range(len(a)))
    x_15 = list(i + bar_width for i in x_14)
 
 
    # Set graphics size
    plt.figure(figsize=(20.8), dpi=80)
    plt.bar(range(len(a)), b_14, width=bar_width, label="High of the month.")
    plt.bar(x_15, b_15, width=bar_width, label="Lowest drop of the month.")
 
 
    # Set legend
    plt.legend(prop=myfont)
    #
    plt.xlabel("Month",fontproperties=myfont)
    plt.ylabel("Value",fontproperties=myfont)
    # Set the X-axis scale
    plt.xticks(x_15, a, fontproperties=myfont)
    plt.savefig("./mutiy.png")
    plt.show()
Copy the code

Rendering 2

Analysis:

The blue line is the highest for the month, and the orange line is the highest for the month. The steepest declines were in July 2020, and the biggest gains were in October and December.

3. Monthly fluctuation value (the difference between the highest rise and lowest fall)

###3. Monthly volatility (difference between highest and lowest)
def analysis3(x,y1,y2) :
    myfont = font_manager.FontProperties(fname="C:\\Windows\\Fonts\\simhei.ttf")
    a=x
    y=[]
    for i in range(0.len(y1)):
        y.append(float(y1[i]-y2[i]))
    # Set graphics size
    plt.figure(figsize=(20.8), dpi=80)
    plt.plot(a,y, label="Fluctuation difference")
 
 
    # Set legend
    plt.legend(prop=myfont)
    plt.xlabel("Month", fontproperties=myfont)
    plt.ylabel("Value", fontproperties=myfont)
    plt.savefig("./mutiy.png")
    plt.show()
Copy the code

Rendering 3

Analysis:

The chart shows the difference between the highest highs and lowest lows for the month. 2019-July was the least volatile month, and 2020-July was the most volatile month, both in July, hahaha, what a coincidence.

4. Monthly difference (from the end of the month to the beginning of the month, whether the month is profitable or not)Copy the code
4. Monthly difference (whether the month is profitable or not from the end of the month to the beginning of the month)
def analysis4(x,y) :
    myfont = font_manager.FontProperties(fname="C:\\Windows\\Fonts\\simhei.ttf")
 
 
    # Set graphics size
    plt.figure(figsize=(20.8), dpi=80)
    plt.plot(x,y, label="Month-beginning")
 
 
    # Set legend
    plt.legend(prop=myfont)
    plt.xlabel("Month", fontproperties=myfont)
    plt.ylabel("Value", fontproperties=myfont)
    plt.savefig("./mutiy.png")
    plt.show()
Copy the code

Rendering 4

Analysis:

A value greater than 0 for the month indicates a profit, while a value less than 0 indicates a loss. If you look at the line chart, most months are above zero, especially the last few months, well above zero.

Okay, that’s it. I’m off to dinner. I’ll talk about it later.

4, summarize

  1. The above analysis is based on liquor as an example (code 161725), by changing the code can be used to analyze other funds.

  2. By changing the size, fund data of several months, recent year and recent years can be analyzed.