【Introduction(5)】Starting Using TEJ Trial Database

The application and usage of TEJ API trial database

TEJ 台灣經濟新報
TEJ-API Financial Data Analysis
4 min readJul 20, 2021

--

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!

Extended Reading

Related Link

You could give us encouragement by …
We will share financial database applications every week.
If you think today’s article is good, you can click on the
applause icon once.
If you think it is awesome, you can hold the
applause icon until 50 times.
If you have any feedback, please feel free to leave a comment below.

--

--

TEJ 台灣經濟新報
TEJ-API Financial Data Analysis

TEJ 為台灣本土第一大財經資訊公司,成立於 1990 年,提供金融市場基本分析所需資訊,以及信用風險、法遵科技、資產評價、量化分析及 ESG 等解決方案及顧問服務。鑒於財務金融領域日趨多元與複雜,TEJ 結合實務與學術界的精英人才,致力於開發機器學習、人工智慧 AI 及自然語言處理 NLP 等新技術,持續提供創新服務