Plot the Nikkei Stock Average with pandas

What to do

If you're playing with Python's data processing library pandas (http://pandas.pydata.org/),

  1. Get Finance information from the Web
  2. Plot

I posted it because it was wonderful because it was made only with code.

Code and commentary

import pandas.io.data as web
import matplotlib.pyplot as plt
import datetime

#Specify the range of days to get
start = datetime.datetime(2014, 1, 1)
end = datetime.datetime(2014, 9, 1)

#From Yahoo Finance^N225 (Nikkei Stock Average)To
#I will get it.
f = web.DataReader('^N225', 'yahoo', start, end)

plt.title('Nikkei 255 from 2014.1.1 to 2014.9.1')

# fill_Plot the highest and lowest values of the day with between
plt.fill_between(f.index, f['Low'], f['High'], color="b", alpha=0.2)

#Plot the opening price with plot.
#Since Index is automatically set to Date, the horizontal axis is time.

f['Open'].plot()
print f[:10]
plt.show()

Execution result

The pandas DataFrame object looks like this Data is retained as a table.

                Open      High       Low     Close  Volume  Adj Close
Date                                                                 
2014-01-06  16147.54  16164.01  15864.44  15908.88  192700   15908.88
2014-01-07  15835.41  15935.37  15784.25  15814.37  165900   15814.37
2014-01-08  15943.68  16121.45  15906.57  16121.45  206700   16121.45
2014-01-09  16002.88  16004.56  15838.44  15880.33  217400   15880.33
2014-01-10  15785.15  15922.14  15754.70  15912.06  237500   15912.06
2014-01-13  15912.06  15912.06  15912.06  15912.06       0   15912.06
2014-01-14  15657.20  15661.71  15383.69  15422.40  214500   15422.40
2014-01-15  15649.07  15808.73  15636.57  15808.73  185800   15808.73
2014-01-16  15845.15  15941.08  15710.14  15747.20  214200   15747.20
2014-01-17  15695.46  15783.37  15621.80  15734.46  180100   15734.46

Click here for plot results. nikkei.png

By the way

If you change ^ N225 to ʻAAPL`, you can get Apple's stock price. There doesn't seem to be an access API for the Japanese market yet.

Recommended Posts

Plot the Nikkei Stock Average with pandas
Compare nighttime and daytime returns on the Nikkei Stock Average with python
scraping the Nikkei 225 with playwright-python
Reformat the timeline of the pandas time series plot with matplotlib
Extract the maximum value with pandas.
[Stock price analysis] Learn pandas with Nikkei 225 (004: Change read data to Nikkei 225)
[Stock price analysis] Learning pandas on the Nikkei average (005: Grouping by year / month-confirmation of statistical information)
Stock price plummeted with "new corona"? I tried to get the Nikkei Stock Average by web scraping
I compared the moving average of IIR filter type with pandas and scipy
Note that the calculation of average pairwise correlation was very easy with pandas
Find the sum of unique values with pandas crosstab
Drawing on Jupyter using the plot function of pandas
Extract the maximum value with pandas and change that value
3D plot Pandas DataFrame
Quickly visualize with Pandas
2-axis plot with Matplotlib
Processing datasets with pandas (1)
Bootstrap sampling with Pandas
Convert 202003 to 2020-03 with pandas
Processing datasets with pandas (2)
Merge datasets with pandas
Learn Pandas with Cheminformatics
Moving average with numpy
I want to find a stock that will rise 5 minutes after the Nikkei Stock Average rises
How to scrape stock prices of individual stocks from the Nikkei newspaper website with Python
[In 3 lines] Plot the population pyramid (bar graph of age group / gender) with Pandas alone
Data visualization with pandas
Data manipulation with Pandas!
Shuffle data with pandas
3D plot with matplotlib
Enlarge the plot display.
Create a new csv with pandas based on the local csv
Display only the lower half (upper half) with seaborn pair plot
I tried to find the average of the sequence with TensorFlow
Check what line caused the error with apply () (dataframe, Pandas)
Calculate the time difference between two columns with Pandas DataFrame
I evaluated the strategy of stock system trading with Python.
[Stock price analysis] Learning pandas with fictitious data (002: Log output)
Get Japanese stock price information from yahoo finance with pandas