MG

muhgalihhh

Back to Works

ImplementasiAlgoritmaGenetikauntukPenentuanKomposisiPortofolioSahamOptimaldenganPendekatanMulti-Objektif

Data Science & AnalysisMachine Learning, Data Science & Analysis (Asignment) · Universitas Jenderal Soedirman
PandasNumPyPython
Implementasi Algoritma Genetika untuk Penentuan Komposisi Portofolio Saham Optimal dengan Pendekatan Multi-Objektif screenshot 1

Overview

How should money be split across stocks to get the best balance of risk and return? This study uses a Real-Coded Genetic Algorithm to find the optimal weights for a portfolio of Indonesian bank stocks, scoring each candidate on four financial ratios at once.

  • Context: Research paper, Informatics, Universitas Jenderal Soedirman

  • Team: 2 people

  • Tools: Python, Pandas, NumPy, yfinance

Data

10 bank stocks listed on the Indonesia Stock Exchange (IDX): BBRI, BBNI, BBCA, BMRI, PNBN, BNGA, BBSI, NISP, MARI and BSIM. Daily closing prices since 1 January 2020 were pulled from Yahoo Finance via yfinance and converted to daily returns.

Fitness Function

F(w) = 0.4 × Sharpe + 0.3 × Calmar + 0.2 × Sortino + 0.1 × Information Ratio

  • Sharpe Ratio: excess return per unit of volatility

  • Calmar Ratio: return relative to maximum drawdown

  • Sortino Ratio: excess return per unit of downside risk

  • Information Ratio: return above a benchmark per unit of volatility

GA Setup

Component

Setting

Chromosome

Real-valued weights, each ≥ 0, summing to 1

Population / generations

150 / 300

Selection

Tournament, size 5

Crossover

Extended intermediate, rate 0.8

Mutation

Reciprocal exchange, rate 0.1

Elitism

Top 10%

Results

Metric

GA portfolio

Equal-weight

Fitness score

1.8709

1.3886

Annual return

32.07%

25.66%

Annual volatility

19.95%

18.59%

Max drawdown

15.31%

19.47%

Sharpe Ratio

1.46

1.22

Calmar Ratio

2.09

1.32

Sortino Ratio

2.70

2.05

Information Ratio

1.21

0.95

The optimized portfolio scored 34.73% higher than the equal-weight portfolio. It earned more with a smaller maximum drawdown, at the cost of slightly higher volatility.

Optimal allocation

Stock

Weight

BNGA

28.73%

NISP

27.21%

BBSI

19.31%

BMRI

9.39%

MARI

6.18%

PNBN

3.76%

BBNI

3.23%

BSIM

1.94%

BBCA

0.17%

BBRI

0.08%

Three stocks, BNGA, NISP and BBSI, hold about 75% of the portfolio.

Parameter Experiments

Population sizes of 100 and 200 were tested against 200 and 500 generations. Population size mattered more than the number of generations: 200 individuals over 500 generations converged fastest and most stably, while a population of 100 got stuck in local optima more easily.