[PYTHON] [Stable at the beginning of the month] Considering the purchase timing of funded investment


Synopsis
If you want to start a funded investment every month, you need to set a purchase date. It is generally said that the dollar cost averaging method makes ** long-term returns almost unchanged ** even if the monthly accumulation date and frequency are changed.

But ** Is it the same if more people make monthly funded investments? ** ** ・ The number of "Tsumitatate NISA" accounts, which started in January 2018, has increased 1.6 times in one year. ・ Vanguard's "VTSAX" is the first fund of the same type to have assets under management exceeding $ 1 trillion Index investment and funded investment continue to increase both in Japan and around the world.

At this point, I was wondering if the impact of a biased purchase date would be greater (more pronounced) as the number of people making a monthly funded investment increases.

This time, we will examine whether the increase in the number of people making funded investments every month causes a bias in price movements. We investigated the dates when purchase dates tend to be biased, and compared the average purchase price of the S & P 500 and the Nikkei Stock Average.


Conclusion
・ ** 1st (beginning of the month) is the cheapest to purchase ** (1% cheaper when the period is 1 year) ・ When the period is 10 or 5 years ** The purchase price is high by about 0.1% at the end of the month **

background

Timing of purchase of funded investment

Many people are investing in investment trusts for reasons such as "Tsumitatate NISA," "dollar cost averaging," and "easy." Therefore, if you want to make a monthly funded investment, you need to set a purchase date. I wondered what day it should be set, and when I searched for "funded investment funded date" ・ Surprising result of funded investment: There is no big difference in return depending on purchase frequency"High stock prices at the beginning of the month" What is the best timing for investing trusts? There are several articles that have long-term verifications by investment trust and funding frequency, but The conclusion is that the returns are almost the same every day, every week, every month, and every other month for a long period of time **.

Certainly, it hasn't changed for nearly 20 years, but I was wondering if it would be the same even if more people make funded investments in the future.

Increasing NISA/Securities Account/Index Investment

▼ Increasing NISA: From the Japan Securities Dealers Association NISA Account Opening/Usage Status Results (2020/6/30) SnapCrab_NoName_2020-12-27_17-15-2_No-00.png ▼ Increasing securities accounts: The number of new account openers will increase by attracting women, young people, and beginners

Rakuten Securities announced on December 15 that the number of securities accounts has reached 5 million. The number of users of online securities has increased in the midst of the corona disaster, which has helped. It took 35 months to go from 2 million to 3 million and 15 months to go from 3 to 4 million, but it took 9 months to go from 4 to 5 million. Quote: Rakuten Securities exceeded 5 million accounts, increased by 1 million in 9 months

▼ Increasing index investment: VTSAX surpasses $ 1 trillion in assets under management

Vanguard Total Stock Market Index Fund has $ 1.4 trillion in assets under management as of November 30, including both mutual funds and exchange-traded funds (ETFs). This is evidence that index investment has increased over the last 30 years. Quote: Vanguard Equity Fund, Over $ 1 Trillion in Assets-First in a Similar Fund

When more people make a monthly funded investment

▼ When one month's inflow of funds is completely random in a certain investment trust SnapCrab_NoName_2020-12-27_20-18-36_No-00.png ▼ When the inflow of funds in a certain investment trust is completely random and ** increases by 10% only for 15 days ** SnapCrab_NoName_2020-12-27_20-19-10_No-00.png

Here, if "the number of trials ⇒ the number of people who make a monthly funded investment" ** The more people make a monthly funded investment, the greater (more prominent) the impact of a biased purchase date may be **. This idea was the trigger for this verification.

Possible purchase date

Many securities companies can decide the accumulation date by themselves.

This is an article on February 25, 2018, but from here Matsui Securities' reserve account purchase date setting ranking 1st place: 1 day 2nd place: End of the month 3rd place: 10th 4th place: 25th 5th place: 15th 6th place: 20th 7th place: 5th 8th place: 27th 9th place: 26th 10th place: 28th

Also, ・ IDeCo: Withdrawn on the 26th of every month and placed at 10 o'clock on the 13th business day (around the 15th of every month) ・ Japanese payday: 5th, 10th, 15th, 20th, 25th, 30th, especially 25th -World payday: 2nd and 4th Fridays in the US, the end of the month in China/Europe, the beginning of the month in India

From the above I think that there are many purchase dates ** 1 day / end of month / fifty days (days that are multiples of 5) **.

Verification content

The purchase date pattern to be verified is as follows.

The purchase method is the dollar cost averaging method, and you purchase a fixed amount every month. We will compare the ** average purchase price for the past 20 years/10 years/5 years/1 year ** when contracted at 6 timings. There are two verification targets, ** S & P500 **, which is an index of many investment trusts and ETFs, and ** Nikkei Stock Average ** for comparison.

I expected that the average purchase price would be lower on the 14th and 24th, which is the day before **, than on the 1st / end of the month / 50th (a multiple of 5 days), which is the expected purchase date. .. The lower the value to be compared is the average purchase price, the more profitable you will be. Also, in this verification, the purchase date = contract date, and we do not consider exchange fluctuations.

result

[Parameter] Verification period: 20,10,5,1 years Target stocks: S & P500, Nikkei Stock Average Contract date: 1,14,15,24,25, end of month

【result】 The table of verification results is shown below, but it can be summarized briefly. ・ Of all contract days, ** 1 day (beginning of the month) is the cheapest to purchase ** (1% cheaper when the period is 1 year) ・ When the period is 10 or 5 years, the purchase price is about 0.1% higher at the end of the month than on other days ** ・ No remarkable features can be confirmed between the day assumed to be a large number of contract days and the 14th and 24th days before that. ・ If you save monthly for 20 years, the average purchase price will not change no matter when you purchase

▼ Average purchase price result_ave_price.png

▼ Ratio of average purchase price to one day of contract (plus is higher than one day) result_ave_price_rate.png

▼ Graph of the ratio of the average purchase price to the contract date of 1 day (if positive, it is higher than 1 day) result_all.png

Bonus (all data from 1 to 31 days)

▼ Graph of the ratio of the average purchase price to the contract date of 1 day (if positive, it is higher than 1 day) omake.png

Summary

If you want to make a funded investment every month, you may be worried about the purchase timing once. In general, the dollar cost averaging method does not change the long-term return even if the monthly accumulation date and frequency are changed. However, I thought that ** the impact of a biased purchase date would increase as the number of people making funded investments increases in the future . One day / end of the month / fifty days (days that are multiples of 5) are candidates as the most purchase days, and I expected that the average purchase price would be lower the day before. As a result, the cheapest purchase was possible on the 1st (beginning of the month), and " The cheapest purchase date was assumed to be the most purchase date **" was obtained.

In this verification, it was confirmed that the long-term return is almost the same depending on the timing of the purchase date, but it was found that the purchase price increases from the first day to the end of the month in the period of 10 to 5 years. If it rises steadily, it may be cheaper to buy early.

From the above, ** It is recommended to set the purchase date to 1 day unless you are particular about it. ** ** Looking at the bonus results, a mountain appears around 11 days in the verification period of 1 year. There is a possibility that the purchase timing is biased around here ...

next

I would like to examine something about the soaring virtual currency. Since it is clear that Bitcoin is the leading index of Altcoin for virtual currencies, I would like to take a closer look using data. Also, since the correlation with Bitcoin alone is not a deciding factor for purchasing, I would like to investigate the relationship between Bitcoin and Altcoin from several indicators.

Future plans ・ Investigate the relationship between Bitcoin and Altcoin ・ Investigation of stocks that rise as the number of people infected with corona increases (or a state of emergency)

Calculation method

Average purchase price

[Dollar cost averaging] This is a method of constantly buying financial products whose prices fluctuate at a fixed price and at regular intervals over time. This equalizes risk and return and makes it less susceptible to major price movements.

The average purchase price using the dollar cost averaging method is calculated by the ** harmonic mean ** of the purchase price. The harmonic mean $ H $ of positive real numbers $ a_1, a_2, ..., a_n $ is expressed by the following equation.

H=\frac{1}{\frac{1}{n}(\frac{1}{a_1}+\frac{1}{a_2}+\dots+\frac{1}{a_n})}

Assuming that the monthly purchase price is $ m $ and the stock price to be purchased the $ i $ out of the total $ n $ purchases is $ p_i $, the number of shares purchased at that time is $ m/p_i , and the average purchase price. Is $ Average purchase price = \ frac {Total purchase price} {Total number of shares purchased} $$ Therefore

\begin{align}
Average purchase price&=\frac{nm}{\frac{m}{p_1}+\frac{m}{p_2}+\dots+\frac{m}{p_n}}\\
&=\frac{1}{\frac{1}{n}(\frac{1}{p_1}+\frac{1}{p_2}+\dots+\frac{1}{p_n})}
\end{align}

In Python it can be calculated as follows.

python


from statistics import harmonic_mean

harmonic_mean(price)

program

python


import pandas as pd
import numpy as np
from statistics import harmonic_mean

#Parameters
code="^GSPC"
period = 20

#Read the prepared data
data = pd.read_csv(code+".csv",index_col=0, parse_dates=True)
start = 2020-period+1
data = data[str(start):]

#Creating a data frame for calculating the average purchase price
row = range(1,32)
col = []
for y in range(start,2021,1):
    for m in range(1,13):
        col.append("{:0=4d}-{:0=2d}".format(y,m))
temp = pd.DataFrame(index=row,columns=col)

#Data allocation to the created data frame
for i in range(len(data.index)):
    y = data.index[i].year
    m = data.index[i].month
    d = data.index[i].day
    temp.at[d,"{}-{:0=2d}".format(y,m)] = data.Close[i]
    
#Calculate average purchase price
price = []
ave_price = []
for day in range(1,32):
    for i in range(len(temp.columns)):
        d = day-1
        count = 0
        #Use the next day's value if there is no data
        while (np.isnan(temp.iat[d,i])):
            d+=1
            if(d>=31):
                count+=1
                d = day-1-count
        else:
            price.append(temp.iat[d,i])
    
    #Calculate the average purchase price with the harmonic mean
    ave_price.append(harmonic_mean(price))
    prece = []

print(ave_price[i])

Recommended Posts

[Stable at the beginning of the month] Considering the purchase timing of funded investment
Shout Hello, Reiwa! At the beginning of Reiwa
The beginning of cif2cell
[GoLang] Set a space at the beginning of the comment
Get UNIXTIME at the beginning of today with a command
I want to output the beginning of the next month with Python
First Python 3 ~ The beginning of repetition ~
How to put a line number at the beginning of a CSV file