> For the complete documentation index, see [llms.txt](https://docs.fiinquant.vn/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.fiinquant.vn/ham-va-cong-thuc/5.-dinh-luong-and-phan-tich-nang-cao/5.3.-tuong-quan-and-so-sanh/5.3.2.-finddatecorrelation.md).

# 5.3.2. FindDateCorrelation

{% hint style="info" %}
Sử dụng function này để tìm mối tương quan giữa dữ liệu ngày hôm nay và dữ liệu trong quá khứ cho một mã nhất định.
{% endhint %}

<figure><img src="/files/dxAhFH3lP5Aa7DDBU0PQ" alt=""><figcaption><p>Ví dụ tìm kiếm tương quan cho VN30F1M trong 1 năm dữ liệu so với ngày hiện tại</p></figcaption></figure>

<pre class="language-python"><code class="lang-python">
 def intraday_Correlation(self, Ticker: Union[str, list[str]], Timeframe: str, 
                            t1: str = None, t2: str = None, method: str = "pearson correlation",
<strong>                            year: int = 1) -> None:
</strong></code></pre>

#### Tham số&#x20;

| Tham số     | Kiểu dữ liệu            | Mặc định | Giá trị mặc định        | Mô tả                                                                     |
| ----------- | ----------------------- | -------- | ----------------------- | ------------------------------------------------------------------------- |
| `Ticker`    | `Union[str, list[str]]` | Bắt buộc | Không có                | Mã chứng khoán hoặc danh sách mã chứng khoán cần phân tích.               |
| `Timeframe` | `str`                   | Bắt buộc | 1M                      | Khung thời gian của dữ liệu giao dịch nội ngày (ví dụ: "1m", "5m", "1h"). |
| `t1`        | `str`                   | Tùy chọn | 9am hoặc 13pm           | Thời gian bắt đầu (nếu cần).                                              |
| `t2`        | `str`                   | Tùy chọn | `None`                  | Thời gian kết thúc (nếu cần).                                             |
| `method`    | `str`                   | Tùy chọn | `"pearson correlation"` | Phương pháp đo khoảng cách (1: Euclidean, 2: DTW, 3: Pearson, 4: Cosine). |
| `year`      | `int`                   | Tùy chọn | `1`                     | Số năm dữ liệu quá khứ cần so sánh.                                       |

Copy đoạn code để chạy ví dụ trên&#x20;

```python

import pandas as pd
import datetime

from FiinQuantX import FiinSession
from datetime import datetime

username = 'REPLACE_WITH_YOUR_USER_NAME'
password = 'REPLACE_WITH_YOUR_PASS_WORD'
 
client = FiinSession(
    username=username,
    password=password
).login()

def user_input():
    default_timeframe = '1m'
    default_t1 = "09:00:00" if datetime.now().hour < 12 else "13:00:00"
    default_t2 = datetime.now().replace(microsecond=0).time().strftime("%H:%M:%S")
    default_method = "pearson correlation"
    default_year = 1
    print("")
    print("Chào mừng đến hệ thống dự báo biểu đồ CHỨNG KHOÁN theo THỜI GIAN THỰC của FIINQUANT")
    print("")
    print("Giải thích cách tìm top 5 ngày tương quan:")
    print("")
    print("- Tìm kiếm tất cả các pattern nến của tất cả các ngày trong vòng x năm kể từ thời điểm hiện tại")
    print("- Tìm 5 ngày có độ tương quan với ngày hiện tại nhất dựa trên các phương pháp tùy người chọn: Euclidean Distance, Pearson Correlation (mặc định), cosine")
    print("")
    print("Hệ thống sẽ sử dụng các tham số mặc định sau:")
    print(f"- Khung thời gian: {default_timeframe}")
    print(f"- Thời điểm bắt đầu: {default_t1}")
    print(f"- Thời điểm kết thúc (là thời điểm hiện tại): {default_t2}")
    print(f"- Phương pháp tính tương quan: {default_method}")
    print(f"- Số năm dữ liệu muốn quét kể từ thời điểm hiện tại: {default_year} năm")

    use_default = input("Bạn có muốn sử dụng các tham số mặc định không? (y/n): ").lower() == "y"

    if not use_default:
        timeframe = input("Nhập khung thời gian (ví dụ: 1m, 15m, 30m, 1h mặc định: 1m): ") or default_timeframe
        t1 = input("Nhập thời điểm bắt đầu (ví dụ: 09:00, 10:00, 11:00): ")
        t2 = input("Nhập thời điểm kết thúc (ví dụ: 13:00, 14:00, 15:00): ")
        
        print("Vui lòng lựa chọn phương pháp tính tương quan:")
        print("1. Pearson Correlation (mặc định)")
        print("2. Euclidean Distance")
        print("3. Cosine")
        print("4. Dynamic Time Wrapping")
        method = int(input("Lựa chọn của bạn (1/2/3): ")) or 1
        
        year = int(input("Nhập số năm dữ liệu muốn quét kể từ thời điểm hiện tại: ")) or 1
    else:
        timeframe = default_timeframe
        t1 = default_t1
        t2 = default_t2
        method = default_method
        year = default_year
    
    Ticker = input("Vui lòng nhập mã bạn muốn so tìm đường tương quan (ví dụ: VN30, VN30F1M, ACB): ")
    print("Đang tính toán, vui lòng đợi")
    client.FindDateCorrelation().intraday_Correlation(Ticker=Ticker, Timeframe=timeframe, t1=t1, t2=t2, method=method, year=year)


# Chạy chương trình
if __name__ == "__main__":
    user_input()
```

<figure><img src="/files/kiBSLJQC6ircVe3UEa32" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.fiinquant.vn/ham-va-cong-thuc/5.-dinh-luong-and-phan-tich-nang-cao/5.3.-tuong-quan-and-so-sanh/5.3.2.-finddatecorrelation.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
