When buying stocks and investment trusts, there is a dollar cost averaging method as a buying method. Risk can be reduced by purchasing products such as stocks and mutual funds ** on a regular basis ** at a fixed price **.
In the slides I often see, I felt that I was not convinced because it was written assuming an arbitrary transition of stock price / base price and the number of data was small. Obviously, the risk is reduced in theory. Therefore, it is an attempt to simulate based on the standard price data of actual investment trusts.
Sumitomo Mitsui Trust Assetment's Foreign Stock Index e
In this simulation, we will compare the ROI one year after the start of purchase.
ROI = \frac{Assets held one year later-1 year investment amount}{1 year investment amount}
I will purchase a certain amount (100,000 yen) at a certain timing.
From a certain timing, we will purchase a certain number of units (10,000 yen) on the 25th of every month for one year.
From a certain timing, I will purchase a fixed amount (10,000 yen) on the 25th of every month for one year.
Risk evaluation is performed by changing the purchase start time in 100 ways and comparing the resulting ROI distribution.
import pandas as pd
df = pd.read_csv('http://www.smtam.jp/fund_data/csv/110057.csv',
names=['day', 'price', 'income', 'asset'], skiprows=1)
df.loc[:, 'day'] = pd.to_datetime(df.day)
print df.shape
df.head(10)
import matplotlib
import seaborn as sns
%matplotlib inline
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, figsize=(12, 8))
df.plot('day', 'price', ax =ax, label=u'Base price')
ax.set_ylabel(u'Base price')
ax.set_xlabel(u'date')
import numpy as np
def package(timing):
num = []
invest = []
price = 100000
for i, r in df.iterrows():
if i == timing:
num_add = int(10000.0 * price/ r.price)
num.append(num[i-1] + num_add if len(num) > 0 else num_add)
invest.append(invest[i-1] + price if len(invest) > 0 else price)
else:
num.append(num[i-1] if len(num) > 0 else 0)
invest.append(invest[i-1] if len(invest) > 0 else 0)
return num, invest
def constant_num(start_timing):
num = []
invest = []
for i, r in df.iterrows():
if r.day.day == 25 and i >= start_timing:
num_add = 10000
invest_add = r.price
num.append(num[i-1] + num_add if len(num) > 0 else num_add)
invest.append(invest[i-1] + invest_add if len(invest) > 0 else invest_add)
else:
num.append(num[i-1] if len(num) > 0 else 0)
invest.append(invest[i-1] if len(invest) > 0 else 0)
return num, invest
def doller_cost(start_timing):
num = []
invest = []
price = 10000
for i, r in df.iterrows():
if r.day.day == 25 and i >= start_timing:
num_add = int(10000.0 * price/ r.price)
num.append(num[i-1] + num_add if len(num) > 0 else num_add)
invest.append(invest[i-1] + price if len(invest) > 0 else price)
else:
num.append(num[i-1] if len(num) > 0 else 0)
invest.append(invest[i-1] if len(invest) > 0 else 0)
return num, invest
def sim(function, label, color):
fig, ax = plt.subplots(1, figsize=(12, 8))
final_ratio = []
for i in np.arange(0, 100) * 10:
num, invest = function(i)
num = pd.Series(num)
invest = pd.Series(invest)
df.loc[:, 'ratio'] = (num * df.price / 10000.0 - invest.astype(float)) / invest.astype(float)
df.plot('day', 'ratio', ax=ax,alpha=0.1, color=color)
final_ratio.append(df.iloc[i + 365].ratio)
ax.set_title(label)
ax.set_ylabel('ROI')
ax.set_xlabel(u'date')
ax.legend_.remove()
return final_ratio
package_ratio = sim(package, u'Bulk purchase', 'blue')
constant_ratio = sim(constant_num, u'Fixed number of subscriptions', 'green')
dc_ratio = sim(doller_cost, u'Fixed amount subscription', 'red')
fig, ax = plt.subplots(1, figsize=(12, 8))
pd.Series(package_ratio).hist(ax=ax, color='blue', alpha=0.3, normed=True, label=u'Bulk purchase')
pd.Series(constant_ratio).hist(ax=ax, color='green', alpha=0.3, normed=True, label=u'Fixed number of subscriptions')
pd.Series(dc_ratio).hist(ax=ax, color='red', alpha=0.3, normed=True, label=u'Fixed amount subscription')
ax.set_xlabel('ROI')
ax.set_ylabel('freq(normed)')
ax.legend()
Recommended Posts