mirror of
https://github.com/quachtinh113/main-fx.git
synced 2026-08-19 13:28:04 +00:00
update data main fx
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import pandas as pd
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
def preprocess_all_symbols():
|
||||
symbols = ['EURUSDm', 'GBPUSDm', 'USDJPYm', 'USDCHFm', 'USDCADm', 'NZDUSDm']
|
||||
timeframes = ['M15', 'H1', 'H4']
|
||||
raw_base = Path("data/raw")
|
||||
processed_base = Path("data/processed")
|
||||
|
||||
print("--- BẮT ĐẦU TIỀN XỬ LÝ DỮ LIỆU ---")
|
||||
|
||||
for symbol in symbols:
|
||||
for tf in timeframes:
|
||||
file_path = raw_base / symbol / tf / f"{symbol}_{tf}.parquet"
|
||||
|
||||
if not file_path.exists():
|
||||
continue
|
||||
|
||||
# 1. Đọc dữ liệu
|
||||
df = pd.read_parquet(file_path)
|
||||
initial_count = len(df)
|
||||
|
||||
# 2. Xử lý logic cơ bản
|
||||
# Chuyển index sang datetime nếu chưa có
|
||||
df.index = pd.to_datetime(df['timestamp'])
|
||||
df = df.sort_index()
|
||||
|
||||
# Loại bỏ trùng lặp
|
||||
df = df[~df.index.duplicated(keep='first')]
|
||||
|
||||
# Loại bỏ nến lỗi (High < Low)
|
||||
df = df[df['high'] >= df['low']]
|
||||
|
||||
# Lọc từ năm 2022 trở lại đây như bạn yêu cầu
|
||||
df = df.loc['2022-01-01':]
|
||||
|
||||
# 3. Loại bỏ ngày cuối tuần (Forex nghỉ)
|
||||
df = df[df.index.dayofweek < 5]
|
||||
|
||||
# 4. Lưu dữ liệu sạch
|
||||
output_dir = processed_base / symbol / tf
|
||||
output_dir.mkdir(parents=True, exist_ok=True)
|
||||
output_path = output_dir / f"{symbol}_{tf}_clean.parquet"
|
||||
df.to_parquet(output_path)
|
||||
|
||||
print(f"[OK] {symbol} {tf}: {initial_count} -> {len(df)} nến (Đã lưu tại {output_path})")
|
||||
|
||||
print("--- HOÀN THÀNH ---")
|
||||
|
||||
if __name__ == "__main__":
|
||||
preprocess_all_symbols()
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,14 @@
|
||||
import pandas as pd
|
||||
|
||||
# Đường dẫn đến file vừa tải
|
||||
file_path = r"data\raw\EURUSDm\M15\EURUSDm_M15.parquet"
|
||||
|
||||
# Đọc dữ liệu
|
||||
df = pd.read_parquet(file_path)
|
||||
|
||||
# Xem 5 dòng đầu và 5 dòng cuối
|
||||
print(df.head())
|
||||
print(df.tail())
|
||||
|
||||
# Kiểm tra xem có ngày nào bị thiếu không
|
||||
print(f"Tổng số nến: {len(df)}")
|
||||
Reference in New Issue
Block a user