# 3.2. Hàm chỉ số báo cáo tài chính

Mô tả cách sử dụng thư viện sau khi người dùng đã đăng nhập. Các ví dụ chi tiết được nêu ra ở cuối chương này.

```python
fi_dict = client.FundamentalAnalysis().get_ratios(
    tickers=tickers,
    years=years,
    quarters=quarters,
    type=type,
    fields=fields
)
```

**Tham số:**

| Tên tham số | Mô tả                                                                                                                                                                                                                             | Kiểu dữ liệu  | Mặc định | Bắt buộc |
| ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- | -------- | -------- |
| tickers     | Danh sách mã được viết in hoa.                                                                                                                                                                                                    | str hoặc list |          | Có       |
| years       | Năm của kỳ báo cáo, có thể chọn nhiều năm bằng cách liệt kê list các năm ra                                                                                                                                                       | list\[int]    |          | Có       |
| quarters    | Quý của kỳ báo cáo, nếu không truyền mặc định lấy báo cáo tài chính của năm dựa trên tham số year, có thể chọn nhiều quý bằng cách liệt kê list các quý ra                                                                        | list\[int]    | None     | Không    |
| type        | 1 trong 2 giá trị (‘consolidated’ hoặc ‘separate’). 'consolidated' là báo cáo tài chính hợp nhất, 'separate' là báo cáo tài chính công ty mẹ                                                                                      | str           |          | Có       |
| fields      | Trường dữ liệu cần lấy (không truyền sẽ lấy hết). Biến fields có thể truyền theo dạng đường dẫn phân cấp cách nhau bằng dấu chấm (ProfitabilityRatio'.'ROA' – Lấy chỉ số ROA) hoặc truyền thẳng sections là node cần lấy ('ROA'). | str           | None     | Không    |

Class nhận dữ liệu là FundamentalAnalysis và có phương thức nhận dữ liệu là get\_ratios()

```python
### pseudocode
import json

fi_dict = client.FundamentalAnalysis().get_ratios(
    tickers=tickers,
    years=[2024],
    quarters=[4],
    type="consolidated"
)

print(json.dumps(fi_dict, indent=4))
```

* Ví dụ lấy dữ liệu full chỉ số báo cáo tài chính hợp nhất của 4 quý trong năm 2024 của mã HPG

```python
import json

from FiinQuantX import FiinSession

username = 'REPLACE_WITH_YOUR_USER_NAME'
password = 'REPLACE_WITH_YOUR_PASS_WORD'

client = FiinSession(username=username, password=password).login()

tickers = ['HPG']

fi_dict = client.FundamentalAnalysis().get_ratios(
    tickers=tickers,
    years=[2024],
    quarters=[1,2,3,4],
    type="consolidated"
)

print(json.dumps(fi_dict, indent=4))
```

Kết quả trả ra sẽ có cấu trúc giống với mục [chi-so-co-ban](https://docs.fiinquant.vn/huong-dan-python/cau-truc-du-lieu-mau/chi-so-co-ban "mention")hoặc [mo-ta-truong-du-lieu-chi-so-bao-cao-tai-chinh-goi-nang-cao](https://docs.fiinquant.vn/huong-dan-python/cau-truc-du-lieu-mau/mo-ta-truong-du-lieu-chi-so-bao-cao-tai-chinh-goi-nang-cao "mention") tùy gói tài khoản

* Ví dụ lấy dữ liệu nhóm chỉ số báo cáo tài chính KHẢ NĂNG SINH LỢI dựa trên báo cáo tài chính hợp nhất của 4 quý năm 2024 của mã HPG

```python
import json

from FiinQuantX import FiinSession

username = 'REPLACE_WITH_YOUR_USER_NAME'
password = 'REPLACE_WITH_YOUR_PASS_WORD'

client = FiinSession(username=username, password=password).login()

tickers = ['HPG']

fi_dict = client.FundamentalAnalysis().get_ratios(
    tickers=tickers,
    years=[2024],
    quarters=[1,2,3,4],
    type="consolidated",
    fields=["ProfitabilityRatio"]
)

print(json.dumps(fi_dict, indent=4))
```

Kết quả trả ra:

```json
[
    {
        "ticker": "HPG",
        "year": 2024,
        "quarter": 1,
        "ratios": {
            "ProfitabilityRatio": {
                "GrossProfitMargin": 0.13464069,
                "EBITMargin": 0.10360069,
                "NetProfitMargin": 0.09299719,
                "ROA": 0.0503502,
                "ROE": 0.0917359,
                "ROIC": 0.06801845
            }
        }
    },
    {
        "ticker": "HPG",
        "year": 2024,
        "quarter": 2,
        "ratios": {
            "ProfitabilityRatio": {
                "GrossProfitMargin": 0.13266118,
                "EBITMargin": 0.10394387,
                "NetProfitMargin": 0.08392193,
                "ROA": 0.05802448,
                "ROE": 0.10720898,
                "ROIC": 0.07589163
            }
        }
    },
    {
        "ticker": "HPG",
        "year": 2024,
        "quarter": 3,
        "ratios": {
            "ProfitabilityRatio": {
                "GrossProfitMargin": 0.1393315,
                "EBITMargin": 0.10865351,
                "NetProfitMargin": 0.08898718,
                "ROA": 0.06034569,
                "ROE": 0.11376296,
                "ROIC": 0.07671273
            }
        }
    },
    {
        "ticker": "HPG",
        "year": 2024,
        "quarter": 4,
        "ratios": {
            "ProfitabilityRatio": {
                "GrossProfitMargin": 0.12655218,
                "EBITMargin": 0.10487897,
                "NetProfitMargin": 0.08145881,
                "ROA": 0.05831798,
                "ROE": 0.11073185,
                "ROIC": 0.07400689
            }
        }
    }
]
```

* Ví dụ lấy dữ liệu chỉ số ROA thuộc nhóm chỉ số báo cáo tài chính KHẢ NĂNG SINH LỢI dựa trên báo cáo tài chính hợp của 4 quý năm 2024 của mã HPG

```python
import json

from FiinQuantX import FiinSession

username = 'REPLACE_WITH_YOUR_USER_NAME'
password = 'REPLACE_WITH_YOUR_PASS_WORD'

client = FiinSession(username=username, password=password).login()

tickers = ['HPG']

fi_dict = client.FundamentalAnalysis().get_ratios(
    tickers=tickers,
    years=[2024],
    quarters=[1,2,3,4],
    type="consolidated",
    fields=["ProfitabilityRatio.ROA"]
)

print(json.dumps(fi_dict, indent=4))
```

Kết quả trả ra:

```json
[
    {
        "ticker": "HPG",
        "year": 2024,
        "quarter": 1,
        "ROA": 0.0503502
    },
    {
        "ticker": "HPG",
        "year": 2024,
        "quarter": 2,
        "ROA": 0.05802448
    },
    {
        "ticker": "HPG",
        "year": 2024,
        "quarter": 3,
        "ROA": 0.06034569
    },
    {
        "ticker": "HPG",
        "year": 2024,
        "quarter": 4,
        "ROA": 0.05831798
    }
]
```
