Acquire the data of Mitsubishi UFJ International Investment Trust eMAXIS with Python and make a graph with the beginning of the term as 100

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. emaxis_chart.png

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

Acquire the data of Mitsubishi UFJ International Investment Trust eMAXIS with Python and make a graph with the beginning of the term as 100
Get the stock price of a Japanese company with Python and make a graph
Calculate the shortest route of a graph with Dijkstra's algorithm and Python
Let's make a graph with python! !!
Python> Slice> A slice offset earlier than the beginning of a string is treated as 0, and one after the end is treated as -1
Send and receive image data as JSON over the network with Python
Make a DNN-CRF with Chainer and recognize the chord progression of music
Make a decision tree from 0 with Python and understand it (4. Data structure)
[Introduction to Python] How to get the index of data with a for statement
Make a copy of the list in Python
A discussion of the strengths and weaknesses of Python
Get a large amount of Starbucks Twitter data with python and try data analysis Part 1
Predicting the goal time of a full marathon with machine learning-③: Visualizing data with Python-
I created a stacked bar graph with matplotlib in Python and added a data label
PhytoMine-How to efficiently acquire gene sequence data of a specific plant species with Python
Learn Nim with Python (from the beginning of the year).
Visualize railway line data as a graph with Cytoscape 2
Let's make a simple game with Python 3 and iPhone
Visualize the range of interpolation and extrapolation with python
Make a breakpoint on the c layer with python
Extract the band information of raster data with python
[Python] I want to make a 3D scatter plot of the epicenter with Cartopy + Matplotlib!
Return the image data with Flask of Python and draw it to the canvas element of HTML
Try scraping the data of COVID-19 in Tokyo with Python
A network diagram was created with the data of COVID-19.
As a result of mounting and tuning with POH! Lite
Get UNIXTIME at the beginning of today with a command
Associate Python Enum with a function and make it Callable
Get rid of dirty data with Python and regular expressions
Detect objects of a specific color and size with Python
Solve the spiral book (algorithm and data structure) with python!
The story of rubyist struggling with python :: Dict data with pycall
[Homology] Count the number of holes in data with Python
Build a Python environment and transfer data to the server
Make a BLE thermometer and get the temperature with Pythonista3
Play with the password mechanism of GitHub Webhook and Python
Find the white Christmas rate by prefecture with Python and map it to a map of Japan
A Python beginner first tried a quick and easy analysis of weather data for the last 10 years.
A super beginner who does not know the basics of Python tried to graph the realized profit and loss data of Rakuten Securities in Python