如何降低基金投资的风险?

How to reduce the risk of fund investment?

Using quantitative investment methods to verify that low-correlation investment portfolios can reduce investment risksand provide source code
Ray Dalio said that low-correlation investment portfolios can significantly reduce investment risks

According to the experience of Bridgewater Associates founder Ray Dalio (video), choose 15-20 low-correlation portfolios Investment products, combined, can significantly reduce investment risks

What is correlation

Correlation refers to the degree of association between two variablesAn uncorrelated fund portfolio means that the daily return levels of each fund in the portfolio have no correlation. Expressed in statistical terms, the correlation coefficient of the daily return levels of each fund in the portfolio is close to 0.

Can low correlation funds be found in the Chinese securities market?

I used 5.45 million historical data of all 4,000 public funds from 2016-10-11 to 2022-10-11 to analyze, and filtered out the correlation coefficient with the Shanghai and Shenzhen 300 ETF funds that is less than 0.1, and 16 funds whose pairwise correlation coefficients are also less than 0.1 and whose cumulative returns are positive
The following is the correlation coefficient heat map of these 16 funds:

The following is the cumulative return map of these 16 funds:

I set the weight of the low correlation fund portfolio to Equal weightThe following is the weight chart of the fund portfolio:

The underlying asset classes of these 16 funds include bond, currency, stock, hybrid and fund types. The following is the weight chart of the underlying asset class of the fund portfolio:

Bond types account for the largest proportion at 54.6%, while stock types account for only 9.1%

Can low-correlation fund portfolios really significantly reduce investment risks?

The following is the cumulative return chart of the equally weighted low correlation fund portfolio:

From the chart, the volatility of the equally weighted low correlation fund portfolio is significantly lower than that of the CSI 300 ETF , the cumulative return rate is slightly lower than that of the CSI 300 ETF, indicating that in the Chinese securities market, low-correlation fund portfolios can really significantly reduce investment risks.
You can also clone the "No Correlation Fund" study below and try it out.
What do you think about uncorrelated fund portfolios? Please leave a comment.Using quantitative investment methods to verify that low-correlation investment portfolios can reduce investment risks. and provide source code.
Ray Dalio said that low-correlation investment portfolios can significantly reduce investment risks

According to the experience of Bridgewater Associates founder Ray Dalio (video), choose 15-20 low-correlation portfolios A combination of investment products can significantly reduce investment risks.

What is correlation

Correlation refers to the degree of association between two variables. An uncorrelated fund portfolio means that the daily return levels of each fund in the portfolio have no correlation. Expressed in a statistical concept, it means that the correlation coefficient of the daily return levels of each fund in the portfolio is close to 0.

Can low correlation funds be found in the Chinese securities market?

I used 5.45 million historical data of all 4,000 public funds from 2016-10-11 to 2022-10-11 to analyze, and filtered out the correlation coefficient with the Shanghai and Shenzhen 300 ETF funds that is less than 0.1, and The pairwise correlation coefficient is also less than 0.1, and there are 16 funds with positive cumulative returns.
The following is the correlation coefficient heat map of these 16 funds:

The following is the cumulative return map of these 16 funds:

I set the weight of the low correlation fund portfolio to Equal weight. The following is the weight chart of the fund portfolio:

The underlying asset classes of these 16 funds include bond, currency, stock, hybrid and fund types. The following is the weight chart of the underlying asset class of the fund portfolio:

Bond types account for the largest proportion, accounting for 54.6%, while stock types account for only 9.1%.

Can low-correlation fund portfolios really significantly reduce investment risks?

The following is the cumulative return chart of the equally weighted low-correlation fund portfolio:

From the chart, the volatility of the equally-weighted low-correlation fund portfolio is significantly lower than that of the CSI 300 ETF , the cumulative return rate is slightly lower than that of the CSI 300 ETF, which shows that in the Chinese securities market, low-correlation fund portfolios can really significantly reduce investment risks.
You can also clone the "No Correlation Fund" study below and give it a test run.
If you have any thoughts on uncorrelated fund portfolios, please comment.
I heard that people who like it earn more!

Source code

The following is the source code studied in the Jukuan Quantization Platform-Strategy Research-Research Environment:

























1. Import library¶
In [1]:
from datetime import date, datetime
import pandas as pd
from jqdata import finance
from sqlalchemy import and_, or_
import seaborn as sns
import matplotlib.pyplot as plt



2. Set the start and end dates of fund transactions¶
In [2 ]:
start_date = date(2016, 10, 11)
end_date = date(2022, 10, 11)



3. Obtain fund information¶
3.1 Get fund information traded within the start and end dates¶
In [3]:
fund_info_0 = finance.run_query(query(finance.FUND_MAIN_INFO).\
filter(or_
(and_(finance.FUND_MAIN_INFO) .end_date >= end_date, finance.FUND_MAIN_INFO.start_date <= start_date),\
and_(finance.FUND_MAIN_INFO.end_date == None, finance.FUND_MAIN_INFO.start_date == None),\
and_(finance.FUND_MAIN_INFO .end_date >= end_date, finance.FUND_MAIN_INFO.start_date == None).\
and_(finance.FUND_MAIN_INFO.end_date == None, finance.FUND_MAIN_INFO.start_date <= start_date)\
)
)
​​)
ins1 = fund_info_0['main_code'].values.tolist()



3.2 Query the number of funds obtained¶
In [4]:
len(fund_info_0)

Out[4]:
4000


3.3 ​​Display the obtained fund information¶
In [5]:
fund_info_0. head()

Out[5]:

id main_code statistics_main_code name advisor trustee operate_mode_id operate_mode underlying_asset_type_id underlying_asset_type invest_style_id invest_style start_date end_date
0 1 000001 None China Growth China Fund Management Co., Ltd. China Construction Bank Co., Ltd. 401001 Open-end fund 402004 Hybrid 005005 Partial stock hybrid 2001-12-18 None
1 2 000003 000003 China Overseas Convertible Bonds China Overseas Fund Management Co., Ltd. Agricultural Bank of China Co., Ltd. 401001 Open-end fund 402003 Bond type 005011 Secondary debt base 2013-03-20 None
2 3 000005 None Harvest Enhanced Credit Harvest Fund Management Co., Ltd. Industrial and Commercial Bank of China Co., Ltd. 401001 Open-end fund 402003 Bond type 005009 Long-term pure debt type 2013-03- 08 None
3 5 000008 000008 Harvest CSI 500ETF connected to Harvest Fund Management Co., Ltd. China Construction Bank Co., Ltd. 401001 Open-end fund 402005 Fund type 005013 Fund type 2013-03-22 None
4 6 000009 000009 E Fund Tiantian Financial Management Currency E Fund Management Co., Ltd. Industrial and Commercial Bank of China Co., Ltd. 401001 Open-end Fund 402002 Currency Type 005014 Currency Type 2013-03-04 None


4. Obtain the cumulative net value of the fund based on the obtained fund code ¶
4.1 Get the cumulative net value of the fund¶
In [ ]:
i = 0
for code in ins1:
unit_fund_price = finance.run_query(query(finance.FUND_NET_VALUE).filter(finance .FUND_NET_VALUE.code == code, finance.FUND_NET_VALUE.day >= start_date).with_entities(finance.FUND_NET_VALUE.day, finance.FUND_NET_VALUE.code, finance.FUND_NET_VALUE.refactor_net_value))
if i == 0:
fund_price = unit_fund_price.copy()
else:
fund_price = pd.concat([fund_price, unit_fund_price])
i += 1



4.2 Query Fund Cumulative net worth data¶
In [159]:
len(fund_price)

Out[159]:
5445126


4.3 Display fund accumulation according to code Net worth¶
In [160]:
fund_price[fund_price['code'] == '000001'].head()

Out[160]:

day code refactor_net_value
0 2016-10-11 000001 5.904695
1 2016-10-12 000001 5.899515
2 2016-10-13 000001 5.920234
3 2016-10-14 000 001 5.915054
4 2016 -10-17 000001 5.878797


4.4 Display the cumulative net value of the fund according to date¶
In [161]:
fund_price[fund_price['day'] == start_date]

Out[161]:

day code refactor_net_value
0 2016-10-11 000001 5.904695
0 2016-10-11 000003 1.008778
0 2016-10-11 000005 1.20429 1
0 2016-10-11 000008 1.747600
0 2016-10-11 000009 1.151615
0 2016-10-11 000011 18.248833
0 2016-10-11 000014 1 .187000
0 2016-10-11 000015 1.216130
0 2016-10-11 000017 2.188291
0 2016-10-11 000020 1.771000
0 2016-10-11 000021 3.423294
0 2016-10-11 000024 1.328000
0 2016-10-11 000028 1.370776
0 2016-10-11 000029 1.537943
0 2016-10-11 000030 1.873511
0 2016-10-11 000031 1. 887000
0 2016-10 -11 000032 1.237000
0 2016-10-11 000039 1.967100
0 2016-10-11 000041 0.784000
0 2016-10-11 000042 1.408000
0 2 016-10-11 000043 1.338000
0 2016-10-11 000045 1.398820
0 2016-10-11 000047 1.399576
0 2016-10-11 000049 0.911000
0 2016-10-11 000051 1.058 000
0 2016-10- 11 000053 1.405342
0 2016-10-11 000054 1.282300
0 2016-10-11 270042 1.806844
0 2016-10-11 000056 1.686000
0 2 016-10-11 000057 1.373000
... ... ... ...
0 2016-10-11 730103 1.162621
0 2016-10-11 740602 1.158393
0 2016-10-11 750003 1.327954
0 2016 -10-11 750007 1.159515
0 2016-10-11 960000 0.994500
0 2016-10-11 960001 0.821000
0 2016-10-11 960002 1.208000
0 2016-10-11 960003 1.030400 2. 275000
0 2016- 10-11 960008 2.228000
0 2016-10-11 960010 1.054700
0 2016-10-11 960011 0.461600
0 2016-10-11 960012 1.383700
0 2016-10-11 960016 4.417700
0 2016-10-11 960018 2.389000
0 2016-10-11 960020 1.435000
0 2016-10-11 960021 1.030000
0 2016-10-11 960022 0. 988400
0 2016-10 -11 960023 1.021900
0 2016-10-11 960026 0.975000
0 2016-10-11 960027 1.014000
0 2016-10-11 960028 1.799000
0 2 016-10-11 960029 1.235220
0 2016-10-11 968001 10.671567
0 2016-10-11 968003 10.580000
0 2016-10-11 968004 10.434954
0 2016-10-11 968011 12 .020000

3386 rows × 3 columns



5. Generate a fund cumulative net value pivot table¶
5.1 Generate a fund cumulative net value pivot table¶
In [162]:
fund_price_pivot = pd. pivot_table(fund_price, index = 'day', values ​​= 'refactor_net_value', columns = 'code')



5.3 Use the previous value to fill the cumulative net value on non-trading dates¶
In [ 164]:
fund_price_pivot = fund_price_pivot.dropna(how = 'all')
fund_price_pivot = fund_price_pivot.fillna(method='ffill')



5.4 Delete start date Funds with missing values¶
In [165]:
fund_price_pivot1 = fund_price_pivot.dropna(axis = 1)



5.5 Query the number of funds in the fund’s cumulative net worth pivot table¶
In [166]:
len(fund_price_pivot1.iloc[0])

Out[166]:
3386


5.6 Display Fund Cumulative Net Value Perspective Table¶
In [167]:
fund_price_pivot1.head()

Out[167]:
code 000001 000003 000004 000005 000008 000009 000010 000011 000013 000014 000015 000016 000017 000020 000021 000024 000025 000028 000029 000030 000031 000032 000033 000039 000041 000042 000043 000044 000045 000046 000047 000048 000049 000051 00 0053 000054 000055 000056 000057 000058 ... 740101 740601 740602 750001 750002 750003 750005 750006 750007 762001 770001 96000 0 960001 960002 960003 960004 960005 960006 960007 960008 960010 960011 960012 960016 960018 960020 960021 960022 960023 960026 960027 960028 960029 968000 968001 968003 968004 968006 968010 968011
day











































​​





































2016-10-11 5.904695 1.008778 1.017008 1.204291 1.7476 1.151615 1.161591 18.248833 1.161981 1.187 1.21 6130 1.199036 2.188291 1.771 3.423294 1.328 1.324 1.370776 1.537943 1.873511 1.887 1.237 1.218 1.9671 0.784 1.408 1.338 1.2 24 1.398820 1.3771 1.399576 1.386085 0.911 1.058 1.405342 1.2823 0.267144 1.686 1.373 1.175065 ... 1.414816 1.148507 1.158393 1.720773 1 .351953 1.327954 1.562 1.149311 1.159515 3.002851 1.532830 0.9945 0.821 1.208 1.0304 1.801 0.8435 1.781 2.275 2.228 1.0547 0.4616 1.3837 4.4177 2.389 1.435 1.030 0.9884 1.0219 0.975 1.014 1.7990 1.23522 10.83 10.671567 10.58 10.434954 1.1754 12.10 12.02
2016-10-12 5.899515 1.007602 1.014657 1.204291 1.7467 1.151697 1.161682 18.188326 1.162072 1.187 1.216130 1.199036 2.177681 1.760 3.413008 1. 329 1.324 1.370776 1.548751 1.873511 1.888 1.237 1.219 1.9654 0.782 1.408 1.346 1.227 1.398820 1.3771 1.399576 1.386085 0.9 12 1.056 1.405544 1.2828 0.266782 1.686 1.372 1.175065 ... 1.413743 1.148585 1.158480 1.718510 1.351953 1.327954 1.562 1.14938 5 1.159597 3.003962 1.532479 0.9934 0.824 1.207 1.0288 1.799 0.8431 1.780 2.266 2.230 1.0498 0.4610 1.3843 4.3983 2.395 1.4 30 1.026 0.9864 1.0182 0.972 1.012 1.7937 1.23420 10.82 10.661176 10.57 10.424783 1.1621 12.02 11.94
2016-10-13 5.920234 1.008778 1.015832 1.205461 1.7475 1.151778 1.161771 18.190055 1.162161 1.188 1.217156 1.200063 2.172376 1.764 3.421237 1.329 1.325 1.370776 1.558478 1.873511 1.884 1.238 1.219 1.9734 0.775 1.410 1.3 42 1.223 1.399886 1.3771 1.400735 1.386085 0.905 1.057 1.406464 1.2833 0.265574 1.685 1.368 1.176236 ... 1.416963 1.148662 1.1 58565 1.727561 1.353121 1.329123 1.562 1.149457 1.159678 3.005390 1.532479 0.9926 0.827 1.211 1.0299 1.800 0.8439 1.782 2.270 2.232 1.0507 0.4600 1.3831 4.4043 2.411 1.431 1.023 0.9859 1.0165 0.975 1.012 1.7876 1.23522 10.81 10.661176 10.56 10.414612 1.1484 11.96 11.88
2016-10-14 5.915054 1.007602 1.014657 1.205461 1.7437 1.151859 1.161860 18.158937 1.1 62250 1.188 1.218182 1.201089 2.164419 1.749 3.415065 1.330 1.325 1.370776 1.557397 1.873511 1.889 1.238 1.219 1.9564 0.779 1.412 1.338 1.222 1.399886 1.3771 1.401895 1.387246 0.902 1.058 1.407675 1.2835 0 .266178 1.685 1.362 1.175065 ... 1.420184 1.148739 1.158650 1.709459 1.353121 1.329123 1.563 1.149528 1.159758 2.999517 1.5324 79 0.9928 0.826 1.208 1.0234 1.802 0.8442 1.784 2.267 2.231 1.0489 0.4612 1.3851 4.4407 2.388 1.422 1.024 0.9882 1.0138 0.980 1.013 1.7816 1.23726 10.83 10.671567 10.57 10.424783 1.1469 11.98 11.89
2016-10-15 5.915054 1.007602 1.014657 1.205461 1.7437 1.151940 1.161860 18.158937 1.162250 1.188 1.218182 1.201089 2.164419 1.749 3.415065 1.33 0 1.325 1.370776 1.557397 1.873511 1.889 1.238 1.219 1.9564 0.779 1.412 1.338 1.222 1.399886 1.3771 1.401895 1.387246 0.902 1.058 1.407675 1.2835 0.266178 1.685 1.362 1.175065 ... 1.420184 1.148739 1.158650 1 .709459 1.353121 1.329123 1.563 1.149528 1.159758 2.999517 1.532479 0.9928 0.826 1.208 1.0234 1.802 0.8442 1.784 2.267 2.23 1 1.0489 0.4612 1.3851 4.4407 2.388 1.422 1.024 0.9882 1.0138 0.980 1.013 1.7816 1.23726 10.83 10.671567 10.57 10.424783 1.1469 11.98 11.89


6. Calculate fund daily return¶
6.1 Calculate fund daily return¶
In [168]:
fund_daily_return = fund_price_pivot1.pct_change()
fund_daily_return = fund_daily_return.dropna(how = 'all')



6.2 Eliminate abnormal funds with daily return greater than 20%¶
In [169]:
daily_return_nan = fund_daily_return.applymap(lambda x: np.nan if x > 0.2 else x)
daily_return_nonan = daily_return_nan.dropna(axis = 1)



6.3 Query the daily return rate less than 20% of the number of funds¶
In [170]:
len(daily_return_nonan.iloc[0])

Out[170]:
3367


6.4 Display fund daily return¶
In [171]:
daily_return_nonan.head()

Out[171]:
code 000001 000003 000004 000005 000008 000009 000010 000011 000013 000014 000015 000016 000017 000020 000021 000024 000025 000028 000029 000030 000031 000032 000033 000039 000041 000042 000043 000044 000045 00 0046 000047 000048 000049 000051 000053 000054 000055 000056 000057 000058 ... 740101 740601 740602 750001 750002 750003 75000 5 750006 750007 762001 770001 960000 960001 960002 960003 960004 960005 960006 960007 960008 960010 960011 960012 960016 960018 960020 960021 960022 960023 960026 960027 960028 960029 968000 968001 968003 96 8004 968006 968010 968011
day








​​

















































​​






















2016-10-12 -0.000877 -0.001166 -0.002312 0.000000 -0.000515 0.000071 0.000078 -0.003316 0.000078 0.000000 0.000000 0.000000 -0.004849 -0.0062 11 -0.003005 0.000753 0.000000 0.0 0.007028 0.0 0.000530 0.000000 0.000821 -0.000864 -0.002551 0.000000 0.005979 0.002451 0.00 0000 0.0 0.000000 0.000000 0.001098 -0.001890 0.000144 0.000390 -0.001355 0.000000 - 0.000728 0.000000 ... -0.000758 0.000068 0.000075 -0.001315 0.000000 0.00000 0.00000 0.000064 0.000071 0.000370 -0.000229 -0.001 106 0.003654 -0.000828 -0.001553 -0.001110 -0.000474 -0.000561 -0.003956 0.000898 -0.004646 -0.001300 0.000434 -0.004391 0.002512 -0. 003484 -0.003883 -0.002023 - 0.003621 -0.003077 -0.001972 -0.002946 -0.000826 -0.000923 -0.000974 -0.000945 -0.000975 -0.011315 -0.006612 -0.006656
2016-10-13 0.003512 0.001167 0.001158 0.000972 0.000458 0.000070 0.000077 0.000095 0.000077 0.000842 0.000844 0.000857 -0.002436 0.002 273 0.002411 0.000000 0.000755 0.0 0.006281 0.0 -0.002119 0.000808 0.000000 0.004070 -0.008951 0.001420 -0.002972 -0.003260 0.000762 0.0 0.000828 0.000000 -0.007 675 0.000947 0.000655 0.000390 -0.004528 -0.000593 -0.002915 0.000997 ... 0.002278 0.000067 0.000073 0.005267 0.000864 0.00088 0. 00000 0.000063 0.000070 0.000475 0.000000 -0.000805 0.003641 0.003314 0.001069 0.000556 0.000949 0.001124 0.001765 0.000897 0.000857 -0.002169 -0.000867 0.001364 0.006681 0.000699 -0.002924 -0.000507 -0.001670 0.00 3086 0.000000 -0.003401 0.000826 -0.000924 0.000000 -0.000946 -0.000976 -0.011789 -0.004992 -0.005025
2016-10-14 -0.000875 -0.001 166-0.001157 0.000000 -0.002175 0.000070 0.000077 -0.001711 0.000077 0.000000 0.000843 0.000855 -0.003663 -0.008503 -0.001804 0.000752 0.00 0000 0.0 -0.000694 0.0 0.002654 0.000000 0.000000 -0.008615 0.005161 0.001418 -0.002981 -0.000818 0.000000 0.0 0.000828 0.00083 8 -0.003315 0.000946 0.000861 0.000156 0.002274 0.000000 -0.004386 -0.000996 . .. 0.002273 0.000067 0.000073 -0.010478 0.000000 0.00000 0.00064 0.000062 0.000069 -0.001954 0.000000 0.000201 -0.001209 -0.0 02477 -0.006311 0.001111 0.000355 0.001122 -0.001322 -0.000448 -0.001713 0.002609 0.001446 0.008265 -0.009540 -0.006289 0.000978 0.002333 -0.002656 0.005128 0.000988 -0.003356 0.001652 0.001850 0.000975 0.000947 0.000977 -0.001306 0.001672 0.000842 2016-10-15 0.000000 0.000000 0.000000 0.000070 0.000000 0.000000 0.000000 0.000000 0.00000000 0.00000000 0.00 0000 0.0000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.0000000 0.000000 0.000000 0.00000000 0.00000000 0.00000000 0.00000000 0.000000 0.000000 0.000000 ... 0.000000 0.000000 0.000000 0.000000 0.000000 0.00000 0.00000 0.000000 0.000000 0.000000 0.000 000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0. 000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
2016 -10-16 0.000000 0.000000 0.000000 0.000000 0.000000 0.000070 0.000153 0.000000 0.000153 0.000000 0.000000 0.000000 0.00000 0 0.000000 0.000000 0.000000 0.000000 0.0 0.000000 0.0 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000 000 0.000000 0.0 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 ... 0.000000 0.0001 34 0.000148 0.000000 0.000000 0.00000 0.00000 0.000121 0.000134 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.0000 00 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.0 00000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000


7. Calculate the union Screening low correlation funds¶
7.1 Calculate and screen low correlation funds¶
In [172]:
df_columns = daily_return_nonan.columns.tolist()
hs300_corr = pd.DataFrame(0, index = df_columns, columns = ['hs300_corr'])
for label, item in daily_return_nonan.iteritems():
hs300_corr.loc[label, 'hs300_corr'] = daily_return_nonan['159919'].corr(item)
hs300_corr = hs300_corr.sort_values(by = ['hs300_corr'])
hs300_corr1 = hs300_corr[(hs300_corr['hs300_corr'] <= 0.2) & (hs300_corr['hs300_corr'] >= 0) ]
hs300_corr1_ins = hs300_corr1.index.tolist()
hs300_corr1_ins.append('159919')
hs300_corr_df = daily_return_nonan[hs300_corr1_ins]
corr_high = hs300_corr_df.corr(). applymap(lambda x: np. nan if x > 0.2 else x).isnull()
col_all = corr_high.columns.tolist()
del_col = []
i = 0
while i < len(col_all) - 1:
ex_index = corr_high.iloc[:,i][i+1:].index[np.where(corr_high.iloc[:,i][i+1:])].tolist()
for var in ex_index:
col_all.remove(var)
corr_high = corr_high.loc[col_all, col_all]
i += 1
col_all_corr = hs300_corr_df[col_all].corr()
hs300_nocorr_df = hs300_corr_df[col_all]
ins = hs300_nocorr_df.columns.tolist()
name = []
for value in ins:
is_named = False
for index1, row1 in fund_info_0 .iterrows():
if value == row1['main_code']:
name.append(row1['name'])
is_named = True
break
hs300_nocorr_df.columns = name



7.2 Display the daily return of low correlation funds¶
In [173]:
hs300_nocorr_df.head()

Out[173]:

E Fund Tiantian R Huaan Gold Easy ETF Link C Shantou Tiantianying B Xinhua Pure Bond Tianli Bond Initiation ICBC Flexible Allocation Mixed B China Universal Pure Bond LOF China Hengli 3 Monthly fixed-open bond Huatai Quantitative Absolute Wealth Fargo Tianshi D GF Financial Management’s annual red Huaan coupon C ICBC Steady Growth Blend H Rongtong’s ever-increasing profits B Guolian AG’s Bond ICBC Core Value Blend H CSI 300ETF
day
















2016-10-12 0.000078 -0.002463 0.000051 0.0 -0.000887 0.000000 0.000000 0.000098 0.000046 0.0 0.000947 -0.003621 0.000000 0.0 00000 -0.004646 -0.001990
2016-10-13 0.000077 0.001975 0.000058 0.0 0.000000 0.000000 0.000000 0.000196 0.000046 0.0 0.000 000 -0.001670 0.000914 0.000000 0.000857 0.000786
2016-10-14 0.000077 -0.001380 0.000059 0.0 0.000000 0.000672 0.000965 0.000490 0.000048 0.0 -0.001892 - 0.002656 0.000000 0.000744 -0.001713 0.000954
2016-10-15 0.000000 0.000000 0.000000 0.0 0.000000 0.000000 0.000000 0.0000 00 0.000000 0.0 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
2016-10-16 0.000153 0.000000 0.000113 0.0 0.000000 0.000000 0.000000 0.000000 0.00 0091 0.0 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000


7.3 Show the correlation coefficient of low correlation funds¶
In [174]:
col_all_corr

Out[174]:
code 000013 000217 000856 519152 001428 164703 002552 001073 000863 270043 002429 960023 161619 253020 960010 159919
code
















000013 1.000000 -0.005544 - 0.013574 0.017853 0.000730 0.002062 0.011783 -0.000934 0.011466 -0.007135 -0.010136 0.004817 0.003147 -0.008214 -0.003716 0.00 0006
000217 -0.005544 1.000000 0.000171 0.050870 0.009196 0.028532 0.063671 0.004718 -0.018663 -0.008593 -0.047860 0.010465 0.041407 0.046659 -0.021267 0.000285
000856 -0.013574 0.000171 1.000000 0.005899 -0.000680 -0.000497 0.001417 0.000953 0.000063 0.000113 -0.000467 0.000068 0.000696 -0.000791 -0.00 0761 0.000368
519152 0.017853 0.050870 0.005899 1.000000 0.005357 -0.028618 0.062086 0.046239 -0.006507 0.008920 0.016492 - 0.040671 0.053378 0.046880 -0.011642 0.001671
001428 0.000730 0.009196 -0.000680 0.005357 1.000000 -0.000173 0.002084 -0.000041 0.000153 0.000684 -0.008877 0.022740 0.000889 0.000223 0.071225 0.00 4625
164703 0.002062 0.028532 -0.000497 -0.028618 -0.000173 1.000000 0.013711 -0.009758 -0.001890 0.001613 -0.028334 0.014445 0.009814 0.015928 -0.058509 0.004641
002552 0.011783 0.063671 0.001417 0.062086 0.002084 0.013711 1.000000 -0.013879 0.003249 0.037259 0.017825 -0.016153 0.062216 0.071207 0.00 3867 0.012899
001073 -0.000934 0.004718 0.000953 0.046239 -0.000041 -0.009758 -0.013879 1.000000 0.001706 0.014764 -0.006398 - 0.006135 -0.003865 0.000338 0.005417 0.021970
000863 0.011466 - 0.018663 0.000063 -0.006507 0.000153 -0.001890 0.003249 0.001706 1.000000 0.004900 -0.012068 0.000033 -0.002788 -0.003382 0.00 0113 0.022139
270043 -0.007135 -0.008593 0.000113 0.008920 0.000684 0.001613 0.037259 0.014764 0.004900 1.000000 -0.012416 0.000041 -0.004624 0.003047 0.000538 0.026187
002429 -0.010136 -0.047860 -0.000467 0.016492 -0.008877 -0.028334 0.017825 -0.006398 -0.012068 -0 .012416 1.000000 0.004823 0.005055 0.015702 0.027882 0.031484
960023 0.004817 0.010465 0.000068 -0.040671 0.022740 0.0144 45 -0.016153 -0.006135 0.000033 0.000041 0.004823 1.000000 0.005414 0.006924 0.032634 0.050141
161619 0.003147 0.041407 0.000696 0.053378 0.000889 0.009814 0.062216 -0.0 03865 -0.002788 -0.004624 0.005055 0.005414 1.000000 0.076854 0.026716 0.051711
253020 -0.008214 0.046659 -0.000791 0.046880 0.000223 0.015928 0.071207 0.000338 -0.003382 0.003047 0.015702 0.006924 0.076854 1.000000 0.017754 0.063169
960010 -0.003716 -0.021267 -0.000761 -0.011642 0.071225 -0.058509 0.003867 0.005417 0.000113 0.000538 0.027882 0.0 32634 0.026716 0.017754 1.000000 0.096514
159919 0.000006 0.000285 0.000368 0.001671 0.004625 0.004641 0.012899 0.021970 0.022139 0.026187 0.031484 0.050141 0.051711 0.063169 0.096514 1.000000


7.4 Display the correlation coefficient heatmap of low correlation funds¶
In [175]:
sns.heatmap(col_all_corr, cmap = "YlGnBu")

Out[175] :





8 Calculate the cumulative return of low correlation funds¶
8.1 Calculate low correlation funds Cumulative return¶
In [176]:
df_cumu_return = hs300_nocorr_df.copy()
lenth = len(hs300_nocorr_df.iloc[0])
for i in range(lenth):
df_cumu_return.iloc[:, i] = (hs300_nocorr_df.iloc[:, i] + 1).cumprod() - 1



8.2 Display the cumulative return rate of low correlation funds¶
In [177]:
df_cumu_return.tail()

Out[177]:

E Fund Tiantian R Huaan Gold Yi ETF Connection C Shantou Tiantianying B Xinhua Pure Bond Tianli Bond Initiation ICBC Flexible Allocation Mix B China Universal Pure Bond LOF Huaxia Henli 3-month Fixed-Open Bond Huatai Quantitative Absolute Wealth Fargo Time D GF Financial Management Annual Red Huaan Coupon C ICBC Steady Growth Mix H Rongtong Sui Sui Tian Profit B Guolian Anzhenli Bond ICBC Core Value Mixed H CSI 300ETF
day
















2022-11-03 0.196230 0.368473 -0.048512 0.234380 -0.000887 -0.178061 0.205514 0.224756 0.148520 0. 090025 0.070076 -0.021431 0.231841 0.042336 -0.051863 0.210734
2022-11-04 0.196282 0.370542 -0.048512 0.233938 -0.000887 -0.178253 0.205070 0.220852 0.148540 0.090025 0.071023 -0.021431 0. 230747 0.043080 -0.051863 0.250325
2022-11-05 0.196282 0.370542 -0.048512 0.233938 -0.000887 -0.178253 0.205070 0.220852 0.1 48540 0.090025 0.071023 -0.021431 0.230747 0.043080 -0.051863 0.250325
2022-11-06 0.196387 0.370542 -0.048512 0.233938 -0.000887 -0.178253 0.205070 0.220852 0.148579 0.090025 0.071023 -0.021431 0.230747 0.043080 -0.051863 0.250325
2022-11-07 0.196440 0.376847 -0.048512 0.234048 - 0.000887 - 0.178349 0.204848 0.222696 0.148562 0.090025 0.071023 -0.021431 0.230747 0.043080 -0.051863 0.252934


8.3 Delete funds with negative cumulative returns ¶
In [182]:
df_cumu_return_last = df_cumu_return.iloc[- 1,:]
columns_del = []
for index, value in df_cumu_return_last.items():
if value < 0:
columns_del.append(index)
df_cumu_return0 = df_cumu_return.drop (columns_del, axis = 1)
low_corr_fund_name = df_cumu_return0.columns.tolist()



8.4 Drawing the cumulative return of low correlation funds஍#29575;Figure¶
In [ 183]:
plt.figure(dpi = 100, figsize = (20, 8))
sns.lineplot(data = df_cumu_return0, dashes = False)
plt.show()
plt. tight_layout()








9 Low Correlation Fund Equal Weight Portfolio¶
9.1 Calculate the cumulative return of an equal-weighted portfolio of low-correlation funds¶
In [184]:
df_cumu_return0['Equal-weighted portfolio of low-correlation funds'] = df_cumu_return0.mean(axis = 1)



9.2 Obtain the underlying asset class of low correlation fund portfolio¶
In [187]:
fund_count = len(low_corr_fund_name)
j = 0
for item in low_corr_fund_name :
one_low_corr_fund_info = fund_info_0[fund_info_0['name'] == item][['name', 'underlying_asset_type']]
if j == 0:
low_corr_fund_info = one_low_corr_fund_info.copy()
else:
low_corr_fund_info = pd.concat([low_corr_fund_info, one_low_corr_fund_info])
j += 1



9.3 Displaying the underlying asset classes of low-correlation fund portfolios¶
In [188]:
low_corr_fund_info

Out[188]:

name underlying_asset_type
2691 E Fund Tiantian R Currency Type
2732 Huaan Gold Easy ETF Link C Fund Type
2361 Xinhua Pure Bond Tianli Bond-initiated Bond Type
1206 China Hengli 3-month Fixed-Issuance Bond Bond Type
547 Huatai Quantitative Absolute Hybrid Type
2852 Fuguo Tianshi D Currency Type
2040 GF Financial Management Annual Red Bond Type
3167 Huaan Coupon C Bond Type
3451 Rongtong Suisui Tianli B Bond Type
2000 Guolian AnzengProfit Bond Bond Type
1689 CSI 300ETF Stock Type


9.4 Calculate low correlation fund portfolio equal weight¶
In [190]:
low_corr_fund_info['weight'] = 1/len(low_corr_fund_info)



9.5 Display low correlation fund portfolio weight¶
In [196]:
low_corr_fund_weight = low_corr_fund_info[['name', 'weight' ]]
low_corr_fund_weight = low_corr_fund_weight.set_index('name')
low_corr_fund_weight['weight'].plot.pie()
plt.show()





9.6 Display the underlying asset class weight of low correlation fund portfolio¶
In [200]:
low_corr_fund_asset_class_weight = low_corr_fund_info[['underlying_asset_type', 'weight']]
low_corr_fund_asset_class_weight1 = low_corr_fund_asset_class_weight .groupby('underlying_asset_type').sum()
plt.pie(x = low_corr_fund_asset_class_weight1['weight'],
labels = low_corr_fund_asset_class_weight1.index, autopct = '%.2f%%')
plt .show()





9.2 Draw the cumulative return chart of an equal-weighted portfolio of low-correlation funds¶
In [181]:
df_cumu_return1 = df_cumu_return0[['Low Correlation Fund Equal Weight Portfolio', 'CSI 300ETF']]
plt.figure(dpi = 100, figsize = (20, 8))
sns.lineplot(data = df_cumu_return1)
plt.show()
plt.tight_layout()






In [ ]:
Return to blog

Comment