Starting Using TEJ Trial Database

The application and usage of TEJ API trial database

Photo Creds: Unsplash

Preface

With the increase of the calculation power of chips, Big Data has become more and more important, especially in the field of the financial markets. How to analyze a specific industry or company precisely? It always comes bias if we analyze by our intuition. Therefore, we could analyze based on numerous pieces of data to get more objective insight.

TEJ built the free database which provided variable financial data in recent one year. It includes operation, trade, finance, fund, future, option and real estate. This database is high cost-performance ratio for beginners to start coding. Let’s get started now!

The Editing Environment and Modules Required

We use Mac OS and Jupyter Notebook in this article

import tejapi
import pandas as pd
import numpy as np

Note: Please install tejapi by command prompt(Windows)/Terminal (Mac) and then type

pip install tejapi

The Highlights of the Article

  • Apply for the key of database
  • Get the data we need

Key Application

Step 1. Click the TEJ API link.

TEJ API home page

Step 2. Click Apply for Trial.

Step 3. Check the message and get the verification code.

Step 4. Type the verification code

Step 5. Success

Step 6. Check the email

Usage of Database

We can see the trial database in the TEJ API list. There is abundant data on this page.

Let’s try to get the daily price and volume of Evergreen Marine Corporation 2603. Click the Detailed description which is next to the listed unadjusted price.

Open the Jupyter Notebook.

tejapi.ApiConfig.api_key = "your key"

Replace ‘ your key ’ with the key we just applied for.

data = tejapi.get('TRAIL/TAPRCD')

Each database has its specific code. TRAIL/TAPRCD is code of database containing daily stock price and volume. We use attribution of tejapi ‘get’, and assign data to the variable data.

This method will download whole data. But we only need the data of 2603. Therefore, we have to filter the data by altering the column description to choose the data we need.

Filter

coid, ticker
mdate date, (gte : start date、lte : the last day)
opts columns, (date、close price、volumn)
chinese_column_name, column names shown in Chinese

data = tejapi.get('TRAIL/TAPRCD', 
                   coid='2603', 
                   mdate={'gte':'2020-01-01', 'lte':'2020-12-31'},
                   opts={'columns':['mdate','close_d', 'volume']},
                   chinese_column_name=True
                  )

Do you find there is a difference between your table and this picture? Try to add this line of code.

tejapi.ApiConfig.ignoretz = True

Finally, replace the index with the date column.

data.set_index('年月日', inplace=True)

Conclusion

Today, we display how to use the TEJ API trial database. There is still a lot of data waiting for us to dig. With this data, we can do more advanced analysis, such as formulating trading strategy, evaluating investment risks, etc. You can see other applications in the extended reading at the bottom of this article. If you want to use longer-term data or other professional financial data, it is recommended to use advanced schemes, which will be more perfect for formulating our strategy!

Related Link

想看更多內容?快來【登入會員】,享受更多閱讀文章的權限喔!
Back