Obtain the data of Mitsubishi UFJ International Investment Trust eMAXIS with Python and create a graph with the code set to 100 at the beginning of the term.
First, import the library (some do not use it).
python
#invite my friends to the party...
import numpy as np
import seaborn as sns
sns.set()
import matplotlib.pyplot as plt
import pandas as pd
from datetime import datetime
Obtain csv from the Mitsubishi UFJ International Investment Trust website and save it. It is a violation of etiquette to access the web many times, so save the acquired file on your PC.
python
#Obtain and save csv from Mitsubishi UFJ International Investment Trust website
import urllib.request
url_list = {'Japan Equity':'https://emaxis.jp/content/csv/fundCsv.php?fund_cd=252634',
'Emerging Equity':'https://emaxis.jp/content/csv/fundCsv.php?fund_cd=252878',
'Developed Equity':'https://emaxis.jp/content/csv/fundCsv.php?fund_cd=252653',
'Japabn Bond':'https://emaxis.jp/content/csv/fundCsv.php?fund_cd=252648',
'Emerging Bond':'https://emaxis.jp/content/csv/fundCsv.php?fund_cd=260448',
'Developed Bond':'https://emaxis.jp/content/csv/fundCsv.php?fund_cd=252667',
'Developed Reit':'https://emaxis.jp/content/csv/fundCsv.php?fund_cd=253674',
'Japan Reit':'https://emaxis.jp/content/csv/fundCsv.php?fund_cd=253669',
'8 assets': 'https://emaxis.jp/content/csv/fundCsv.php?fund_cd=252760'}
for key in url_list:
url = url_list[key]
title = "{0}.csv".format(key)
urllib.request.urlretrieve(url,title)
Create a file that summarizes the total return index of all funds. (The CSV file of Mitsubishi UFJ International Investment Trust is easy because it has a distribution reinvestment base price from the beginning)
python
#Create a file that summarizes the total return index of all funds
assets = ['Japan Equity','Emerging Equity','Developed Equity','Japabn Bond','Emerging Bond'
,'Developed Bond','Developed Reit','Japan Reit', '8 assets']
df_all = pd.DataFrame()
for asset in assets:
asset_file = "{0}.csv".format(asset)
df = pd.read_csv(asset_file, skiprows = [0,1], names = ['date','nav_void', 'nav','div', 'aum'],
parse_dates = True, index_col = 0)
df['tr'] = df['nav'] / df['nav'].shift(1)
df[asset] = df['tr'].cumprod()
df = df.loc[:,[asset, 'div']]
df_all[asset] = df[asset]
df_all.to_csv('df_all.csv')
If you create a file that summarizes the total return index, you can use it in various ways.
For example, the cumulative return transition graph with the beginning of the period as 100 is as follows.
python
df = pd.read_csv('df_all.csv')
df = df_all['2019-12-29':]
df_cum = (df / df.iloc[0,:])*100
df_cum.plot(figsize = (6,6),title = "Plot Chart (Start = 100)")
plt.savefig('emaxis_chart',bbox_inches="tight")
↓ You can make a graph like this.
Since March 2020, it has fallen sharply except for Japanese bonds and developed country bonds. If you want to invest in declining assets, eMAXIS Slim Balance (8 assets equal type) is a quick way (* investment is at your own risk).
Recommended Posts