Which day of the week do you buy gold?

Which day is the best day to buy gold?

Securities companies handle pure gold (ETFs), and the stock code 1540 is as small as about 6000 yen per stock. There is a so-called "dollar cost averaging method" in which these stocks are bought by diversifying over time rather than buying them all at once. Some people will save daily, while others will save weekly or monthly. Here, we will focus on weekly data and explore which day of the week is best.

However, it is up to you to make the decision. And this article isn't about investing, it's about how the writer knows how to handle weekly data. Again, don't forget that investing is at your own risk.

Preprocessing

Let's prepare the data. In my case, I got the data for 160 days and prepared it by using replacement. Since I wanted more days of the week, I imported it into Excel once, added a day of the week column using a function, and created the following csv data "junkin.csv".

Day of the week,Date and time,Open price,High price,Low price,closing price,Volume,調整後closing price*
2020-1-6,5220,5260,5200,5250,135951,5250
Same as below, arranged in ascending order by date

Data capture

Import csv data. Some imports are unnecessary

import pandas as pd
%matplotlib inline
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn import datasets
plt.style.use('ggplot') #Magic
junkin = pd.read_csv("junkin.csv") #Read csv data
junkin.head() #Take a look at the overview

You can skip here as you won't use it later. Check the number of lines and type. It can be seen that the date and time were actually character type as well as 160 days. For the time being, add a column converted to date and time type.

n = len(junkin)
n

junkin['date'] = pd.to_datetime(junkin['Date and time'], format='%Y/%m/%d')
junkin.dtypes

2020-09-01 (2).png

Compared to the previous day, that is, the closing price on the current day-the closing price on the previous day is calculated and given as a column. Check the head 3 lines with .head (3).

junkin['The day before ratio'] = junkin['closing price'].diff()
junkin.head(3)

Extract Monday rows.

mon = junkin.query('Day of the week.str.endswith("Month")', engine='python')
mon.head(3)

Let's take a look at the summary statistics focused on Monday. The same applies from Tuesday to Friday.

mon.describe()

2020-09-01 (3).png

in conclusion

It is up to you to determine the calculated and output summary statistics. In order to judge "which day of the week you buy pure gold" that I personally stated, would you compare the average value from the previous day? You may try increasing the amount of data a little more.

keyword

・ Import csv data -Conversion to date type ・ Extraction of specific rows

Recommended Posts

Which day of the week do you buy gold?
Find out the day of the week with datetime
[Python] Get the day of the week (English & Japanese)
How much do you know the basics of Python?
The day of docker run (note)
Explaining the mechanism of Linux that you do not know unexpectedly
What to do if you get `locale.Error: unsupported locale setting` when getting the day of the week from a date in Python
Do you understand the Monty Hall problem?
Get the last day of the specified month
You will be an engineer in 100 days --Day 29 --Python --Basics of the Python language 5
You will be an engineer in 100 days --Day 33 --Python --Basics of the Python language 8
Get one day of the week from Zeller's joint ceremony ~ Incidentally, the perpetual calendar ~
You will be an engineer in 100 days --Day 32 --Python --Basics of the Python language 7
You will be an engineer in 100 days --Day 28 --Python --Basics of the Python language 4
Check the type of the variable you are using
Get a glimpse of which cryptocurrencies you should have bought a week ago at Poloniex