# 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="https://3318188420-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fkme4XYjWbuM3iRJzUu9r%2Fuploads%2Funn2psxlKOHZxiPPZFt3%2Fimage.png?alt=media&#x26;token=b9569c87-dbf4-4b47-b9c1-be14e159a7fc" 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="https://3318188420-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fkme4XYjWbuM3iRJzUu9r%2Fuploads%2FahvAI3OuDTBWE0vTyUe4%2Fimage.png?alt=media&#x26;token=c594f5a7-3a06-41a3-87b4-a196f13134d2" alt=""><figcaption></figcaption></figure>
