Select stocks based on P/E and Devidend Yeild
In this project, we use the P/E ratio and dividend yield to select and hold stocks in the Vietnamese stock market. The portfolio is rebalanced on the first day of each month; if that day is a holiday, rebalancing is carried out on the next trading day.
In value investing, one common approach to stock selection involves identifying undervalued companies with strong income potential. This strategy leverages two key financial metrics: the Price-to-Earnings (P/E) ratio and the dividend yield. The P/E ratio helps assess whether a stock is trading at a reasonable price relative to its earnings, while the dividend yield highlights its income-generating potential.
The core idea is to select stocks with a low P/E ratio and a high dividend yield, as these stocks may represent undervalued opportunities that also offer steady cash returns. This method is particularly effective in mature or stable markets, such as the Vietnamese stock market, where dividend-paying companies are often more established and financially sound.
We filter and maintain a portfolio of stocks with a price-to-earnings (P/E) ratio within the range of (0, 15) and a dividend yield (DY) greater than 0.01. The dividend yield is calculated as:
- DY = DPS / Price
where DPS denotes dividends per share. Existing holdings are sold before purchasing new stocks at each rebalancing period.
- Data source: Algotrade database
- Data period: from 2022-01-01 to 2025-01-01
- Financial and closing price data are extracted and stored in a .csv file to reduce the time required for subsequent actions.
- Each sell or buy side will be charge 0.035% fee.
- The daily close price is collected from Algotrade database using SQL queries.
- The data is collected using the script
data_loader.py
- The data is stored in the
data/pe_dps.csv
anddata/vnindex.csv
files.
- P/E and DPS are calculated based on:
- Net Profit After Tax Atributed To Shareholder
- Outstanding share
- Dividends paid
- The data is also collected using the
data_loader.py
file.
- Set up python virtual environment
python -m venv venv
source venv/bin/activate # for Linux/MacOS
.\venv\Scripts\activate.bat # for Windows command line
.\venv\Scripts\Activate.ps1 # for Windows PowerShell
- Install the required packages
pip install -r requirements.txt
- (OPTIONAL) Create
.env
file in the root directory of the project and fill in the required information. The.env
file is used to store environment variables that are used in the project. The following is an example of a.env
file:
DB_NAME=<database name>
DB_USER=<database user name>
DB_PASSWORD=<database password>
DB_HOST=<host name or IP address>
DB_PORT=<database port>
Data can be download directly from Google Drive. The data files are stored in the data
folder with the following folder structure:
data
├── is
│ ├── pe_dps.csv
│ └── vnindex.csv
└── os
├── pe_dps.csv
└── vnindex.csv
You should place this folder to the current PYTHONPATH
for the following steps.
To collect data from database, run this command below in the root directory:
python data_loader.py
The result will be stored in the data/pe_dps.csv
and data/vnindex.csv
Specify period and parameters in parameter/backtesting_parameter.json
file.
python backtesting.py
The results are stored in the result/backtest/
folder.
To run the optimization, execute the command in the root folder:
python optimization.py
The optimization parameter are store in parameter/optimization_parameter.json
. After optimizing, the optimized parameters are stored in parameter/optimized_parameter.json
.
To run the out-of-sample backtesting results, execute this command
python evaluation.py
The script will get value from parameter/optimized_parameter.json
to execute. The results are stored in the result/optimization
folder.
Running the in-sample backtesting by execute the command:
python backtesting.py
- Backtesting results are stored in the
result/backtest/
folder. - Used metrics to compare with VNINDEX are:
- Sharpe ratio (SR)
- Sortino ratio (SoR)
- Information ratio (Inf)
- Maximum drawdown (MDD)
- We use a risk-free rate of 6% per annum, equivalent to approximately 0.023% per day, as a benchmark for evaluating the Sharpe Ratio (SR) and Sortino Ratio (SoR).
- The backtesting results with VNINDEX benchmark is constructuted from 2019-01-01 to 2022-01-01.
| Metric | Value |
|------------------------|------------------------------------|
| Sharpe Ratio | 1.2971 |
| Information Ratio | 0.0298 |
| Sortino Ratio | 1.7297 |
| Maximum Drawdown (MDD) | -0.2828 |
- The NAV chart. The chart is located at:
result/backtest/nav.png
- Drawdown chart. The chart is located at
result/backtest/drawdown.png
The configuration of optimization is stored in parameter/optimization_parameter.json
you can adjust the range of parameters. Random seed is used for reconstructing the optimization process. The optimized parameter is stored in parameter/optimized_parameter.json
The optimization process can be reproduced by executing the command:
python optimization.py
The currently found optimized parameters with the seed 2024
are:
{
"pe": [0, 15],
"dy": [0.01, 1e6]
}
- Specify the out-sample period and parameters in
parameter/backtesting_parameter.json
file. - The out-sample data is loaded on the previous step. Refer to section Data for more information.
- To evaluate the out-sample data run the command below
python evaluation.py
- The out-sample backtesting results with VNINDEX benchmark is constructuted from 2022-01-01 to 2024-01-01.
| Metric | Value |
|------------------------|------------------------------------|
| Sharpe Ratio | -0.6420 |
| Information Ratio | 0.0206 |
| Sortino Ratio | -0.7986 |
| Maximum Drawdown (MDD) | -0.4715 |
- The NAV chart. The chart is located at
result/optimization/nav.png
. - Drawdown chart. The chart is located at
result/optimization/drawdown.png
.
[1] ALGOTRADE, Algorithmic Trading Theory and Practice - A Practical Guide with Applications on the Vietnamese Stock Market, 1st ed. DIMI BOOK, 2023, pp. 64–67. Accessed: Apr. 30, 2025. [Online]. Available: Link
[2] ALGOTRADE, “Weighting Methods Used in Smart-Beta Strategy,” Website, Jul. 10, 2024. Available: Link (accessed Apr. 30, 2025).