# 6.1. Rebalance

Bằng cách nhập giá trị có thể mua và mã index, thuật toán sẽ tính ra số lượng cổ phiếu cần mua để có tỷ lệ giống với tỷ lệ cổ phiếu trong rổ chỉ số index nhất. Ứng dụng trong giao dịch arbitrage, passive investment.

{% hint style="info" %}
Phương pháp luận hàm **Rebalance:**

Hàm **Rebalance** sử dụng dữ liệu công bố của Sở giao dịch chứng khoán về Tỷ lệ FreeFloat, Giới hạn tỷ trọng kết hợp với giá đóng cửa (close price) realtime của hệ thống FiinGroup.

**Tái cơ cấu** được thực hiện theo nguyên tắc tỷ lệ về **Khối lượng không thay đổi trong một danh mục**, do vậy để có thể bám theo (tracking) một chỉ số, người quản trị danh mục chỉ cần xây dựng bộ **danh mục có tỷ lệ về số lượng giữa các cổ phiếu giống với tỷ lệ về chỉ số** cần theo dõi, sẽ đảm bảo đạt được độ lệch (Tracking Error) thấp nhất.

Kết quả trả ra là **"Share to Buy"** dựa trên input đầu vào là **Budget (VND)** và **Ticker (Chỉ số)** cần **Rebalance**.
{% endhint %}

<figure><img src="/files/a4wvKfK4eKf1szx4y7j3" alt="" width="375"><figcaption><p>Danh sách vã số lượng cần mua của mỗi mã cổ phiếu</p></figcaption></figure>

Danh sách các Index dùng cho hàm:

* VN30
* VN100
* VNX50
* VNMidcap
* VNFINSELECT
* VNDIAMOND
* VNFINLEAD

```python
from FiinQuantX import FiinSession

username = 'REPLACE_WITH_YOUR_USER_NAME'
password = 'REPLACE_WITH_YOUR_PASS_WORD'                     
                     
client = FiinSession(username=username, password=password).login()
df = client.Rebalance().get(Budget = 10000000000, Ticker = 'VN30')
print(df)
```

<figure><img src="/files/830F4J43PrFmVbFbXN6B" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.fiinquant.vn/ham-va-cong-thuc/6.-chien-luoc-and-cong-cu/6.1.-rebalance.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
