Spaces:
Sleeping
Sleeping
Smart-Trader-EA commited on
Commit ยท
19848e6
1
Parent(s): 8b49703
Complete trading analysis system with preprocessing
Browse files- .DS_Store +0 -0
- app.py +458 -277
- data/{EURUSD2022_2025.csv โ raw/EURUSD2022_2025.csv} +0 -0
- pre_treat_data.rtf +25 -0
.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
app.py
CHANGED
|
@@ -1,360 +1,541 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
|
|
|
| 3 |
import plotly.graph_objects as go
|
| 4 |
from prophet import Prophet
|
| 5 |
import os
|
| 6 |
-
import
|
| 7 |
-
from datetime import datetime
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
#
|
| 10 |
os.environ["OMP_NUM_THREADS"] = "1"
|
| 11 |
os.environ["OPENBLAS_NUM_THREADS"] = "1"
|
| 12 |
os.environ["MKL_NUM_THREADS"] = "1"
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
|
| 16 |
-
|
|
|
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
try:
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
|
|
|
|
| 30 |
try:
|
| 31 |
-
df = pd.read_csv(
|
| 32 |
-
|
| 33 |
-
break
|
| 34 |
-
except UnicodeDecodeError:
|
| 35 |
continue
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
"data": df
|
| 68 |
-
}
|
| 69 |
-
print(f"โ
ๆๅๅ ่ฝฝ: {ticker_name} ({len(df)} ๆก่ฎฐๅฝ)")
|
| 70 |
-
except Exception as e:
|
| 71 |
-
print(f"โ ๅ ่ฝฝๅคฑ่ดฅ {filename}: {str(e)}")
|
| 72 |
-
else:
|
| 73 |
-
print(f"โ ๏ธ ่ญฆๅ: ๆฐๆฎ็ฎๅฝไธๅญๅจ - {DATA_DIR}")
|
| 74 |
|
| 75 |
-
def
|
| 76 |
-
"""
|
| 77 |
try:
|
| 78 |
-
|
| 79 |
-
if not available_tickers:
|
| 80 |
-
return "โ ้่ฏฏ: ๆฒกๆๆพๅฐไปปไฝๆฐๆฎๆไปถใ่ฏทๆฃๆฅdata/็ฎๅฝ", None, None
|
| 81 |
-
|
| 82 |
-
# ๆจก็ณๅน้
่ก็ฅจไปฃ็
|
| 83 |
-
ticker_upper = ticker.upper()
|
| 84 |
-
matched_ticker = None
|
| 85 |
|
| 86 |
-
#
|
| 87 |
-
if
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
matched_ticker = name
|
| 94 |
break
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
# ่ทๅๆฐๆฎ
|
| 101 |
-
hist = available_tickers[matched_ticker]["data"].copy()
|
| 102 |
|
| 103 |
-
#
|
| 104 |
required_cols = ['Open', 'High', 'Low', 'Close']
|
| 105 |
missing_cols = [col for col in required_cols if col not in hist.columns]
|
| 106 |
|
| 107 |
if missing_cols:
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
hist.rename(columns=col_mapping, inplace=True)
|
| 117 |
-
missing_cols = [col for col in required_cols if col not in hist.columns]
|
| 118 |
-
|
| 119 |
-
if missing_cols:
|
| 120 |
-
return (f"โ ๆฐๆฎๆ ผๅผ้่ฏฏ: ็ผบๅฐๅฟ
่ฆๅ: {', '.join(missing_cols)}\n"
|
| 121 |
-
f"ๅฏ็จๅ: {', '.join(hist.columns)}"), None, None
|
| 122 |
|
| 123 |
-
#
|
| 124 |
-
fig
|
| 125 |
x=hist.index,
|
| 126 |
open=hist['Open'],
|
| 127 |
high=hist['High'],
|
| 128 |
low=hist['Low'],
|
| 129 |
close=hist['Close'],
|
| 130 |
-
name='
|
| 131 |
-
)
|
| 132 |
|
| 133 |
-
#
|
| 134 |
if len(hist) >= 20:
|
| 135 |
hist['MA20'] = hist['Close'].rolling(window=20, min_periods=1).mean()
|
| 136 |
fig.add_trace(go.Scatter(
|
| 137 |
-
x=hist.index,
|
| 138 |
-
y=hist['MA20'],
|
| 139 |
-
mode='lines',
|
| 140 |
-
name='20
|
| 141 |
line=dict(color='blue', width=1.5)
|
| 142 |
))
|
| 143 |
|
| 144 |
if len(hist) >= 50:
|
| 145 |
hist['MA50'] = hist['Close'].rolling(window=50, min_periods=1).mean()
|
| 146 |
fig.add_trace(go.Scatter(
|
| 147 |
-
x=hist.index,
|
| 148 |
-
y=hist['MA50'],
|
| 149 |
-
mode='lines',
|
| 150 |
-
name='50
|
| 151 |
line=dict(color='orange', width=1.5)
|
| 152 |
))
|
| 153 |
|
|
|
|
| 154 |
fig.update_layout(
|
| 155 |
-
title=f"{
|
| 156 |
-
xaxis_title="
|
| 157 |
-
yaxis_title="
|
| 158 |
template="plotly_white",
|
| 159 |
hovermode="x unified",
|
| 160 |
-
height=500
|
|
|
|
| 161 |
)
|
| 162 |
|
| 163 |
-
#
|
|
|
|
|
|
|
|
|
|
| 164 |
try:
|
| 165 |
-
#
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
# ็งป้คNaNๅผ
|
| 170 |
-
df = df.dropna()
|
| 171 |
-
|
| 172 |
-
# ็กฎไฟๆ่ถณๅคๆฐๆฎ
|
| 173 |
-
if len(df) < 30:
|
| 174 |
-
raise ValueError("ๆฐๆฎ็นไธ่ถณ๏ผๆ ๆณ่ฟ่ก้ขๆต")
|
| 175 |
-
|
| 176 |
-
# ๅๅปบๅนถๆๅๆจกๅ (ไฟฎๅค: ็งป้คstan_backend)
|
| 177 |
-
model = Prophet(
|
| 178 |
-
daily_seasonality=True,
|
| 179 |
-
yearly_seasonality=True,
|
| 180 |
-
interval_width=0.95,
|
| 181 |
-
uncertainty_samples=1000
|
| 182 |
-
)
|
| 183 |
-
|
| 184 |
-
model.fit(df)
|
| 185 |
-
|
| 186 |
-
# ๅๅปบๆชๆฅๆฐๆฎๆก (30ๅคฉ้ขๆต)
|
| 187 |
-
future = model.make_future_dataframe(periods=30, freq='D')
|
| 188 |
-
forecast = model.predict(future)
|
| 189 |
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
|
| 239 |
-
|
| 240 |
-
|
|
|
|
| 241 |
|
|
|
|
| 242 |
current_price = hist['Close'].iloc[-1]
|
| 243 |
-
|
| 244 |
-
ma50 = hist['MA50'].iloc[-1] if 'MA50' in hist.columns else None
|
| 245 |
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
if ma20 is not None:
|
| 249 |
if current_price > ma20:
|
| 250 |
-
signal = "๐
|
| 251 |
else:
|
| 252 |
-
signal = "๐
|
| 253 |
|
| 254 |
-
if
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
|
|
|
| 259 |
|
| 260 |
-
#
|
| 261 |
-
|
|
|
|
|
|
|
| 262 |
|
|
|
|
| 263 |
result_text = (
|
| 264 |
-
f"๐ {
|
| 265 |
-
f"
|
| 266 |
-
f"
|
| 267 |
-
f"
|
| 268 |
-
f"
|
| 269 |
-
f"
|
| 270 |
-
f"
|
| 271 |
-
f"
|
| 272 |
)
|
| 273 |
|
| 274 |
-
|
| 275 |
-
|
|
|
|
| 276 |
except Exception as e:
|
| 277 |
-
error_msg = f"โ
|
| 278 |
print(error_msg)
|
|
|
|
|
|
|
| 279 |
return error_msg, None, None
|
| 280 |
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
return "โ
ๅฏ็จๆฐๆฎ: " + ", ".join(available_tickers.keys())
|
| 286 |
-
|
| 287 |
-
def get_app_version():
|
| 288 |
-
"""่ทๅๅบ็จ็ๆฌไฟกๆฏ"""
|
| 289 |
-
return f"๐ ๅคๆฑ/่ก็ฅจAIๅๆ็ณป็ป v2.1\n" \
|
| 290 |
-
f"๐ ๆๅๆดๆฐ: {datetime.now().strftime('%Y-%m-%d %H:%M')}\n" \
|
| 291 |
-
f"๐ ๅฏ็จๆฐๆฎ้: {len(available_tickers)}"
|
| 292 |
-
|
| 293 |
-
# ๅๅปบGradio็้ข
|
| 294 |
-
with gr.Blocks(title="ๅคๆฑAIๅๆ็ณป็ป", theme=gr.themes.Soft()) as demo:
|
| 295 |
-
gr.Markdown("# ๐ ๅคๆฑ/่ก็ฅจAIๅๆ็ณป็ป (ๆฌๅฐๆฐๆฎ็)")
|
| 296 |
-
gr.Markdown("โ
ไผๅฟ: ๆ ้็ฝ็ป๏ผๆฐๆฎ็จณๅฎ๏ผ้็งๅฎๅ
จ๏ผ้ๅไธญ้ฟๆๅๆ")
|
| 297 |
|
| 298 |
-
# ็ถๆไฟกๆฏ
|
| 299 |
with gr.Row():
|
| 300 |
-
|
| 301 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 302 |
|
| 303 |
-
# ๅๆๅบๅ
|
| 304 |
with gr.Row():
|
| 305 |
-
|
| 306 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 307 |
|
| 308 |
-
|
| 309 |
-
signal_output = gr.Textbox(label="ๅๆ็ปๆ", lines=6)
|
| 310 |
|
| 311 |
with gr.Row():
|
| 312 |
-
|
| 313 |
-
|
| 314 |
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
|
| 337 |
-
#
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
examples_per_page=3
|
| 348 |
-
)
|
| 349 |
|
| 350 |
-
#
|
| 351 |
analyze_btn.click(
|
| 352 |
-
fn=
|
| 353 |
-
inputs=
|
| 354 |
-
outputs=[
|
| 355 |
)
|
| 356 |
|
| 357 |
-
#
|
| 358 |
if __name__ == "__main__":
|
| 359 |
demo.launch(
|
| 360 |
server_name="0.0.0.0",
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
import plotly.graph_objects as go
|
| 5 |
from prophet import Prophet
|
| 6 |
import os
|
| 7 |
+
import re
|
| 8 |
+
from datetime import datetime, timedelta
|
| 9 |
+
import warnings
|
| 10 |
+
warnings.filterwarnings('ignore')
|
| 11 |
|
| 12 |
+
# Performance optimization for Apple Silicon
|
| 13 |
os.environ["OMP_NUM_THREADS"] = "1"
|
| 14 |
os.environ["OPENBLAS_NUM_THREADS"] = "1"
|
| 15 |
os.environ["MKL_NUM_THREADS"] = "1"
|
| 16 |
|
| 17 |
+
# Define data directories
|
| 18 |
+
RAW_DATA_DIR = "data/raw"
|
| 19 |
+
PROCESSED_DATA_DIR = "data/processed"
|
| 20 |
+
os.makedirs(PROCESSED_DATA_DIR, exist_ok=True)
|
| 21 |
|
| 22 |
+
# Predefined trading pairs with expected formats
|
| 23 |
+
TRADING_PAIRS = {
|
| 24 |
+
"EURUSD": {
|
| 25 |
+
"description": "Euro to US Dollar Forex Pair",
|
| 26 |
+
"date_format": "%d.%m.%Y %H:%M:%S.%f %z",
|
| 27 |
+
"has_timezone": True,
|
| 28 |
+
"decimal_separator": ".",
|
| 29 |
+
"required_columns": ["Open", "High", "Low", "Close"]
|
| 30 |
+
},
|
| 31 |
+
"BTCUSD": {
|
| 32 |
+
"description": "Bitcoin to US Dollar",
|
| 33 |
+
"date_format": "%Y-%m-%d %H:%M:%S",
|
| 34 |
+
"has_timezone": False,
|
| 35 |
+
"decimal_separator": ".",
|
| 36 |
+
"required_columns": ["Open", "High", "Low", "Close"]
|
| 37 |
+
},
|
| 38 |
+
"AAPL": {
|
| 39 |
+
"description": "Apple Inc. Stock",
|
| 40 |
+
"date_format": "%Y-%m-%d",
|
| 41 |
+
"has_timezone": False,
|
| 42 |
+
"decimal_separator": ".",
|
| 43 |
+
"required_columns": ["Open", "High", "Low", "Close", "Volume"]
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
def preprocess_data_file(raw_file_path, pair_name):
|
| 48 |
+
"""Preprocess raw data file to standardized format"""
|
| 49 |
+
print(f"๐ Preprocessing data for {pair_name}...")
|
| 50 |
+
|
| 51 |
+
try:
|
| 52 |
+
# Get pair configuration
|
| 53 |
+
config = TRADING_PAIRS.get(pair_name, TRADING_PAIRS["EURUSD"])
|
| 54 |
+
|
| 55 |
+
# Read raw data with proper encoding
|
| 56 |
+
encodings = ['utf-8', 'latin1', 'ISO-8859-1', 'cp1252']
|
| 57 |
+
df = None
|
| 58 |
+
|
| 59 |
+
for encoding in encodings:
|
| 60 |
try:
|
| 61 |
+
df = pd.read_csv(raw_file_path, encoding=encoding)
|
| 62 |
+
print(f"โ
Successfully read {pair_name} data with {encoding} encoding")
|
| 63 |
+
break
|
| 64 |
+
except (UnicodeDecodeError, pd.errors.ParserError):
|
| 65 |
+
continue
|
| 66 |
+
|
| 67 |
+
if df is None:
|
| 68 |
+
raise Exception(f"โ Failed to read {pair_name} data with any encoding")
|
| 69 |
+
|
| 70 |
+
# Standardize column names (case-insensitive)
|
| 71 |
+
column_mapping = {}
|
| 72 |
+
for col in df.columns:
|
| 73 |
+
col_lower = col.lower()
|
| 74 |
+
|
| 75 |
+
if any(keyword in col_lower for keyword in ['date', 'time', 'timestamp']):
|
| 76 |
+
column_mapping[col] = 'datetime'
|
| 77 |
+
elif 'open' in col_lower:
|
| 78 |
+
column_mapping[col] = 'Open'
|
| 79 |
+
elif 'high' in col_lower:
|
| 80 |
+
column_mapping[col] = 'High'
|
| 81 |
+
elif 'low' in col_lower:
|
| 82 |
+
column_mapping[col] = 'Low'
|
| 83 |
+
elif 'close' in col_lower:
|
| 84 |
+
column_mapping[col] = 'Close'
|
| 85 |
+
elif 'volume' in col_lower:
|
| 86 |
+
column_mapping[col] = 'Volume'
|
| 87 |
+
|
| 88 |
+
if column_mapping:
|
| 89 |
+
df.rename(columns=column_mapping, inplace=True)
|
| 90 |
+
print(f"๐ท๏ธ Standardized columns: {list(column_mapping.keys())} โ {list(column_mapping.values())}")
|
| 91 |
+
|
| 92 |
+
# Process datetime column
|
| 93 |
+
datetime_col = None
|
| 94 |
+
for col in ['datetime', 'date', 'time', 'timestamp']:
|
| 95 |
+
if col in df.columns:
|
| 96 |
+
datetime_col = col
|
| 97 |
+
break
|
| 98 |
+
|
| 99 |
+
if datetime_col is None:
|
| 100 |
+
raise Exception("โ No datetime column found in data")
|
| 101 |
+
|
| 102 |
+
# Handle special EURUSD format with GMT
|
| 103 |
+
if pair_name == "EURUSD" and df[datetime_col].astype(str).str.contains('GMT').any():
|
| 104 |
+
print("๐ Handling EURUSD special datetime format...")
|
| 105 |
+
# Clean GMT format
|
| 106 |
+
df[datetime_col] = df[datetime_col].str.replace(' GMT', '', regex=False)
|
| 107 |
+
|
| 108 |
+
# Parse with specified format
|
| 109 |
+
df[datetime_col] = pd.to_datetime(
|
| 110 |
+
df[datetime_col],
|
| 111 |
+
format=config['date_format'],
|
| 112 |
+
errors='coerce',
|
| 113 |
+
utc=True
|
| 114 |
+
)
|
| 115 |
+
else:
|
| 116 |
+
# Standard datetime parsing
|
| 117 |
+
df[datetime_col] = pd.to_datetime(
|
| 118 |
+
df[datetime_col],
|
| 119 |
+
errors='coerce',
|
| 120 |
+
utc=config['has_timezone']
|
| 121 |
+
)
|
| 122 |
+
|
| 123 |
+
# Remove rows with invalid dates
|
| 124 |
+
before_count = len(df)
|
| 125 |
+
df = df.dropna(subset=[datetime_col])
|
| 126 |
+
print(f"๐งน Removed {before_count - len(df)} rows with invalid dates")
|
| 127 |
+
|
| 128 |
+
# Set datetime as index
|
| 129 |
+
df.set_index(datetime_col, inplace=True)
|
| 130 |
+
df.sort_index(inplace=True)
|
| 131 |
+
|
| 132 |
+
# Handle decimal separators if needed
|
| 133 |
+
if config['decimal_separator'] != '.':
|
| 134 |
+
for col in ['Open', 'High', 'Low', 'Close', 'Volume']:
|
| 135 |
+
if col in df.columns:
|
| 136 |
+
df[col] = df[col].astype(str).str.replace(',', '.').astype(float)
|
| 137 |
+
|
| 138 |
+
# Fill missing values
|
| 139 |
+
for col in ['Open', 'High', 'Low', 'Close']:
|
| 140 |
+
if col in df.columns:
|
| 141 |
+
missing_before = df[col].isna().sum()
|
| 142 |
+
if missing_before > 0:
|
| 143 |
+
df[col] = df[col].fillna(method='ffill').fillna(method='bfill')
|
| 144 |
+
print(f" ๐ Filled {missing_before} missing values in {col}")
|
| 145 |
+
|
| 146 |
+
# Remove duplicates
|
| 147 |
+
before_count = len(df)
|
| 148 |
+
df = df[~df.index.duplicated(keep='first')]
|
| 149 |
+
print(f"๐งน Removed {before_count - len(df)} duplicate entries")
|
| 150 |
+
|
| 151 |
+
# Validate required columns
|
| 152 |
+
missing_cols = [col for col in config['required_columns'] if col not in df.columns]
|
| 153 |
+
if missing_cols:
|
| 154 |
+
print(f"โ Missing required columns: {missing_cols}")
|
| 155 |
+
print(f"Available columns: {df.columns.tolist()}")
|
| 156 |
+
return None
|
| 157 |
+
|
| 158 |
+
# Save preprocessed data
|
| 159 |
+
processed_file = os.path.join(PROCESSED_DATA_DIR, f"{pair_name}_processed.csv")
|
| 160 |
+
df.to_csv(processed_file)
|
| 161 |
+
print(f"โ
Saved preprocessed data to {processed_file}")
|
| 162 |
+
|
| 163 |
+
return df
|
| 164 |
+
|
| 165 |
+
except Exception as e:
|
| 166 |
+
print(f"โ Preprocessing error for {pair_name}: {str(e)}")
|
| 167 |
+
return None
|
| 168 |
+
|
| 169 |
+
def load_available_data():
|
| 170 |
+
"""Load and preprocess all available data files"""
|
| 171 |
+
available_data = {}
|
| 172 |
+
|
| 173 |
+
if not os.path.exists(RAW_DATA_DIR):
|
| 174 |
+
print(f"โ ๏ธ Raw data directory not found: {RAW_DATA_DIR}")
|
| 175 |
+
return available_data
|
| 176 |
+
|
| 177 |
+
print(f"๐ Scanning for data files in {RAW_DATA_DIR}...")
|
| 178 |
+
|
| 179 |
+
# Scan for CSV files in raw data directory
|
| 180 |
+
for filename in os.listdir(RAW_DATA_DIR):
|
| 181 |
+
if filename.endswith('.csv'):
|
| 182 |
+
# Extract pair name from filename
|
| 183 |
+
pair_name = filename.split('.')[0].upper()
|
| 184 |
+
|
| 185 |
+
# Check if we have config for this pair, or use default
|
| 186 |
+
if pair_name not in TRADING_PAIRS:
|
| 187 |
+
TRADING_PAIRS[pair_name] = {
|
| 188 |
+
"description": f"{pair_name} Trading Pair",
|
| 189 |
+
"date_format": "%Y-%m-%d %H:%M:%S",
|
| 190 |
+
"has_timezone": False,
|
| 191 |
+
"decimal_separator": ".",
|
| 192 |
+
"required_columns": ["Open", "High", "Low", "Close"]
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
raw_file_path = os.path.join(RAW_DATA_DIR, filename)
|
| 196 |
+
processed_file_path = os.path.join(PROCESSED_DATA_DIR, f"{pair_name}_processed.csv")
|
| 197 |
+
|
| 198 |
+
# Check if preprocessed file exists and is newer than raw file
|
| 199 |
+
if os.path.exists(processed_file_path):
|
| 200 |
+
raw_mod_time = os.path.getmtime(raw_file_path)
|
| 201 |
+
processed_mod_time = os.path.getmtime(processed_file_path)
|
| 202 |
|
| 203 |
+
if processed_mod_time > raw_mod_time:
|
| 204 |
+
print(f"โ
Using existing preprocessed data for {pair_name}")
|
| 205 |
try:
|
| 206 |
+
df = pd.read_csv(processed_file_path, index_col=0, parse_dates=True)
|
| 207 |
+
available_data[pair_name] = df
|
|
|
|
|
|
|
| 208 |
continue
|
| 209 |
+
except Exception as e:
|
| 210 |
+
print(f"โ ๏ธ Error loading preprocessed file: {str(e)}")
|
| 211 |
+
|
| 212 |
+
# Preprocess the file
|
| 213 |
+
print(f"๐ Processing {pair_name} data...")
|
| 214 |
+
df = preprocess_data_file(raw_file_path, pair_name)
|
| 215 |
+
if df is not None:
|
| 216 |
+
available_data[pair_name] = df
|
| 217 |
+
print(f"โ
Successfully loaded {pair_name} with {len(df)} records")
|
| 218 |
+
else:
|
| 219 |
+
print(f"โ Failed to load {pair_name} data")
|
| 220 |
+
|
| 221 |
+
return available_data
|
| 222 |
+
|
| 223 |
+
# Load available data at startup
|
| 224 |
+
print("๐ Initializing data processing system...")
|
| 225 |
+
available_data = load_available_data()
|
| 226 |
+
print(f"๐ Available trading pairs: {list(available_data.keys())}")
|
| 227 |
+
|
| 228 |
+
def get_available_pairs():
|
| 229 |
+
"""Get list of available trading pairs with status"""
|
| 230 |
+
if not available_data:
|
| 231 |
+
return "โ ๏ธ No data files found. Please upload CSV files to the 'data/raw' directory."
|
| 232 |
+
|
| 233 |
+
status = "โ
Available trading pairs:\n"
|
| 234 |
+
for pair in sorted(available_data.keys()):
|
| 235 |
+
df = available_data[pair]
|
| 236 |
+
records = len(df)
|
| 237 |
+
date_range = f"{df.index.min().strftime('%Y-%m-%d')} to {df.index.max().strftime('%Y-%m-%d')}"
|
| 238 |
+
status += f"โข {pair}: {records} records ({date_range})\n"
|
| 239 |
+
return status
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
|
| 241 |
+
def analyze_trading_pair(pair_name):
|
| 242 |
+
"""Analyze a specific trading pair"""
|
| 243 |
try:
|
| 244 |
+
print(f"\n๐ Starting analysis for {pair_name}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
|
| 246 |
+
# Check if data is available
|
| 247 |
+
if pair_name not in available_data:
|
| 248 |
+
# Try case-insensitive match
|
| 249 |
+
matched_pair = None
|
| 250 |
+
for available_pair in available_data.keys():
|
| 251 |
+
if pair_name.upper() == available_pair.upper():
|
| 252 |
+
matched_pair = available_pair
|
|
|
|
| 253 |
break
|
| 254 |
+
|
| 255 |
+
if matched_pair is None:
|
| 256 |
+
available_pairs = ", ".join(available_data.keys())
|
| 257 |
+
return (
|
| 258 |
+
f"โ Data not available for '{pair_name}'\n"
|
| 259 |
+
f"Available pairs: {available_pairs}\n"
|
| 260 |
+
f"Upload your data to 'data/raw' directory and restart the app",
|
| 261 |
+
None, None
|
| 262 |
+
)
|
| 263 |
+
pair_name = matched_pair
|
| 264 |
|
| 265 |
+
# Get the data
|
| 266 |
+
hist = available_data[pair_name].copy()
|
| 267 |
+
print(f"๐ Loaded {len(hist)} records for {pair_name}")
|
|
|
|
|
|
|
|
|
|
| 268 |
|
| 269 |
+
# Basic data validation
|
| 270 |
required_cols = ['Open', 'High', 'Low', 'Close']
|
| 271 |
missing_cols = [col for col in required_cols if col not in hist.columns]
|
| 272 |
|
| 273 |
if missing_cols:
|
| 274 |
+
return (
|
| 275 |
+
f"โ Missing required columns: {', '.join(missing_cols)}\n"
|
| 276 |
+
f"Available columns: {', '.join(hist.columns)}",
|
| 277 |
+
None, None
|
| 278 |
+
)
|
| 279 |
+
|
| 280 |
+
# Create candlestick chart
|
| 281 |
+
fig = go.Figure()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 282 |
|
| 283 |
+
# Add candlestick
|
| 284 |
+
fig.add_trace(go.Candlestick(
|
| 285 |
x=hist.index,
|
| 286 |
open=hist['Open'],
|
| 287 |
high=hist['High'],
|
| 288 |
low=hist['Low'],
|
| 289 |
close=hist['Close'],
|
| 290 |
+
name='Price'
|
| 291 |
+
))
|
| 292 |
|
| 293 |
+
# Add moving averages if enough data
|
| 294 |
if len(hist) >= 20:
|
| 295 |
hist['MA20'] = hist['Close'].rolling(window=20, min_periods=1).mean()
|
| 296 |
fig.add_trace(go.Scatter(
|
| 297 |
+
x=hist.index,
|
| 298 |
+
y=hist['MA20'],
|
| 299 |
+
mode='lines',
|
| 300 |
+
name='20-period MA',
|
| 301 |
line=dict(color='blue', width=1.5)
|
| 302 |
))
|
| 303 |
|
| 304 |
if len(hist) >= 50:
|
| 305 |
hist['MA50'] = hist['Close'].rolling(window=50, min_periods=1).mean()
|
| 306 |
fig.add_trace(go.Scatter(
|
| 307 |
+
x=hist.index,
|
| 308 |
+
y=hist['MA50'],
|
| 309 |
+
mode='lines',
|
| 310 |
+
name='50-period MA',
|
| 311 |
line=dict(color='orange', width=1.5)
|
| 312 |
))
|
| 313 |
|
| 314 |
+
# Update layout
|
| 315 |
fig.update_layout(
|
| 316 |
+
title=f"{pair_name} Price Analysis",
|
| 317 |
+
xaxis_title="Date",
|
| 318 |
+
yaxis_title="Price",
|
| 319 |
template="plotly_white",
|
| 320 |
hovermode="x unified",
|
| 321 |
+
height=500,
|
| 322 |
+
margin=dict(l=50, r=50, t=50, b=50)
|
| 323 |
)
|
| 324 |
|
| 325 |
+
# Create forecast using Prophet
|
| 326 |
+
forecast_fig = None
|
| 327 |
+
forecast_result = ""
|
| 328 |
+
|
| 329 |
try:
|
| 330 |
+
# Prepare data for Prophet
|
| 331 |
+
prophet_df = hist[['Close']].reset_index()
|
| 332 |
+
prophet_df.columns = ['ds', 'y']
|
| 333 |
+
prophet_df = prophet_df.dropna()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 334 |
|
| 335 |
+
if len(prophet_df) < 30:
|
| 336 |
+
forecast_result = "โ ๏ธ Not enough data points for reliable forecasting (need at least 30)"
|
| 337 |
+
else:
|
| 338 |
+
# Create and fit model
|
| 339 |
+
model = Prophet(
|
| 340 |
+
daily_seasonality=True,
|
| 341 |
+
yearly_seasonality=True,
|
| 342 |
+
interval_width=0.95,
|
| 343 |
+
changepoint_prior_scale=0.05
|
| 344 |
+
)
|
| 345 |
+
|
| 346 |
+
with warnings.catch_warnings():
|
| 347 |
+
warnings.simplefilter("ignore")
|
| 348 |
+
model.fit(prophet_df)
|
| 349 |
+
|
| 350 |
+
# Create future dataframe (30 days forecast)
|
| 351 |
+
future = model.make_future_dataframe(periods=30, freq='D')
|
| 352 |
+
forecast = model.predict(future)
|
| 353 |
+
|
| 354 |
+
# Create forecast chart
|
| 355 |
+
forecast_fig = go.Figure()
|
| 356 |
+
|
| 357 |
+
# Historical data
|
| 358 |
+
forecast_fig.add_trace(go.Scatter(
|
| 359 |
+
x=prophet_df['ds'],
|
| 360 |
+
y=prophet_df['y'],
|
| 361 |
+
mode='lines',
|
| 362 |
+
name='Historical',
|
| 363 |
+
line=dict(color='blue', width=2)
|
| 364 |
+
))
|
| 365 |
+
|
| 366 |
+
# Forecast data
|
| 367 |
+
forecast_fig.add_trace(go.Scatter(
|
| 368 |
+
x=forecast['ds'],
|
| 369 |
+
y=forecast['yhat'],
|
| 370 |
+
mode='lines',
|
| 371 |
+
name='Forecast',
|
| 372 |
+
line=dict(color='red', width=2, dash='dash')
|
| 373 |
+
))
|
| 374 |
+
|
| 375 |
+
# Confidence interval
|
| 376 |
+
forecast_fig.add_trace(go.Scatter(
|
| 377 |
+
x=forecast['ds'].tolist() + forecast['ds'][::-1].tolist(),
|
| 378 |
+
y=forecast['yhat_upper'].tolist() + forecast['yhat_lower'][::-1].tolist(),
|
| 379 |
+
fill='toself',
|
| 380 |
+
fillcolor='rgba(255,0,0,0.1)',
|
| 381 |
+
line=dict(color='rgba(255,255,255,0)'),
|
| 382 |
+
name='95% CI'
|
| 383 |
+
))
|
| 384 |
+
|
| 385 |
+
forecast_fig.update_layout(
|
| 386 |
+
title=f"{pair_name} 30-Day Price Forecast",
|
| 387 |
+
xaxis_title="Date",
|
| 388 |
+
yaxis_title="Price",
|
| 389 |
+
template="plotly_white",
|
| 390 |
+
height=500,
|
| 391 |
+
hovermode="x unified"
|
| 392 |
+
)
|
| 393 |
+
|
| 394 |
+
# Get last forecast values
|
| 395 |
+
last_forecast = forecast.iloc[-1]
|
| 396 |
+
forecast_result = (
|
| 397 |
+
f"๐ฎ 30-Day Forecast:\n"
|
| 398 |
+
f"Predicted price: {last_forecast['yhat']:.5f}\n"
|
| 399 |
+
f"Range: {last_forecast['yhat_lower']:.5f} to {last_forecast['yhat_upper']:.5f}"
|
| 400 |
+
)
|
| 401 |
|
| 402 |
+
except Exception as e:
|
| 403 |
+
forecast_result = f"โ ๏ธ Forecasting error: {str(e)}"
|
| 404 |
+
print(forecast_result)
|
| 405 |
|
| 406 |
+
# Technical analysis
|
| 407 |
current_price = hist['Close'].iloc[-1]
|
| 408 |
+
signal = "๐ Analyzing market conditions..."
|
|
|
|
| 409 |
|
| 410 |
+
if 'MA20' in hist.columns:
|
| 411 |
+
ma20 = hist['MA20'].iloc[-1]
|
|
|
|
| 412 |
if current_price > ma20:
|
| 413 |
+
signal = "๐ BULLISH: Price above 20-period MA"
|
| 414 |
else:
|
| 415 |
+
signal = "๐ BEARISH: Price below 20-period MA"
|
| 416 |
|
| 417 |
+
if 'MA50' in hist.columns:
|
| 418 |
+
ma50 = hist['MA50'].iloc[-1]
|
| 419 |
+
if current_price > ma20 and ma20 > ma50:
|
| 420 |
+
signal = "๐ STRONG BULLISH: Golden Cross pattern"
|
| 421 |
+
elif current_price < ma20 and ma20 < ma50:
|
| 422 |
+
signal = "๐ฃ STRONG BEARISH: Death Cross pattern"
|
| 423 |
|
| 424 |
+
# Calculate performance metrics
|
| 425 |
+
start_price = hist['Close'].iloc[0]
|
| 426 |
+
total_return = (current_price / start_price - 1) * 100
|
| 427 |
+
volatility = hist['Close'].pct_change().std() * np.sqrt(252) * 100 # Annualized volatility
|
| 428 |
|
| 429 |
+
# Create result text
|
| 430 |
result_text = (
|
| 431 |
+
f"๐ {pair_name} Analysis Report\n"
|
| 432 |
+
f"{'=' * 40}\n"
|
| 433 |
+
f"๐ฐ Current Price: {current_price:.5f}\n"
|
| 434 |
+
f"๐ Total Return: {total_return:.2f}%\n"
|
| 435 |
+
f"โก Volatility: {volatility:.2f}%\n"
|
| 436 |
+
f"๐ฏ Signal: {signal}\n"
|
| 437 |
+
f"{'=' * 40}\n"
|
| 438 |
+
f"{forecast_result}"
|
| 439 |
)
|
| 440 |
|
| 441 |
+
print(f"โ
Analysis completed for {pair_name}")
|
| 442 |
+
return result_text, fig, forecast_fig
|
| 443 |
+
|
| 444 |
except Exception as e:
|
| 445 |
+
error_msg = f"โ Analysis error: {str(e)}"
|
| 446 |
print(error_msg)
|
| 447 |
+
import traceback
|
| 448 |
+
traceback.print_exc()
|
| 449 |
return error_msg, None, None
|
| 450 |
|
| 451 |
+
# Create Gradio interface
|
| 452 |
+
with gr.Blocks(title="Trading Pair AI Analyzer", theme=gr.themes.Soft()) as demo:
|
| 453 |
+
gr.Markdown("# ๐ Trading Pair AI Analysis System")
|
| 454 |
+
gr.Markdown("### Analyze forex, stocks, and crypto with AI-powered insights")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 455 |
|
|
|
|
| 456 |
with gr.Row():
|
| 457 |
+
with gr.Column(scale=2):
|
| 458 |
+
data_status = gr.Textbox(
|
| 459 |
+
label="๐ Available Data",
|
| 460 |
+
value=get_available_pairs(),
|
| 461 |
+
interactive=False,
|
| 462 |
+
lines=5
|
| 463 |
+
)
|
| 464 |
+
|
| 465 |
+
with gr.Column(scale=1):
|
| 466 |
+
gr.Markdown("### โน๏ธ System Information")
|
| 467 |
+
system_info = gr.Textbox(
|
| 468 |
+
value=f"๐ Trading Analysis System v2.0\n"
|
| 469 |
+
f"๐ Last updated: {datetime.now().strftime('%Y-%m-%d %H:%M')}\n"
|
| 470 |
+
f"๐งฎ Loaded pairs: {len(available_data)}",
|
| 471 |
+
interactive=False
|
| 472 |
+
)
|
| 473 |
|
|
|
|
| 474 |
with gr.Row():
|
| 475 |
+
with gr.Column():
|
| 476 |
+
pair_input = gr.Textbox(
|
| 477 |
+
label="๐ Trading Pair",
|
| 478 |
+
value="EURUSD",
|
| 479 |
+
placeholder="Enter pair name (e.g., EURUSD, BTCUSD, AAPL)"
|
| 480 |
+
)
|
| 481 |
+
analyze_btn = gr.Button("๐ Analyze", variant="primary")
|
| 482 |
+
|
| 483 |
+
with gr.Column():
|
| 484 |
+
gr.Markdown("### ๐ก Quick Tips")
|
| 485 |
+
gr.Markdown("""
|
| 486 |
+
- Use pair names from the available data list
|
| 487 |
+
- System automatically preprocesses your data
|
| 488 |
+
- First analysis may take 30-60 seconds
|
| 489 |
+
- Ensure your CSV has Open, High, Low, Close columns
|
| 490 |
+
""")
|
| 491 |
|
| 492 |
+
result_output = gr.Textbox(label="๐ Analysis Results", lines=8)
|
|
|
|
| 493 |
|
| 494 |
with gr.Row():
|
| 495 |
+
price_chart = gr.Plot(label="๐ Price Chart & Technical Indicators")
|
| 496 |
+
forecast_chart = gr.Plot(label="๐ฎ 30-Day Price Forecast")
|
| 497 |
|
| 498 |
+
with gr.Accordion("๐ Data Upload Instructions", open=False):
|
| 499 |
+
gr.Markdown("""
|
| 500 |
+
### How to Add Your Own Data
|
| 501 |
+
|
| 502 |
+
1. **Prepare your CSV file** with these columns:
|
| 503 |
+
- Date/Time column (any format)
|
| 504 |
+
- Open, High, Low, Close prices
|
| 505 |
+
- Volume (optional)
|
| 506 |
+
|
| 507 |
+
2. **Upload to Hugging Face Space**:
|
| 508 |
+
- Go to your Space Files tab
|
| 509 |
+
- Create directories: `data/raw/`
|
| 510 |
+
- Upload your CSV files to `data/raw/`
|
| 511 |
+
- Example filenames: `EURUSD.csv`, `BTCUSD.csv`
|
| 512 |
+
|
| 513 |
+
3. **Restart the application**:
|
| 514 |
+
- Go to Settings โ Restart Space
|
| 515 |
+
- Wait 2-3 minutes for rebuild
|
| 516 |
+
|
| 517 |
+
4. **Your data will be automatically preprocessed** and ready for analysis!
|
| 518 |
+
""")
|
| 519 |
|
| 520 |
+
# Examples for quick testing
|
| 521 |
+
examples = gr.Examples(
|
| 522 |
+
examples=[
|
| 523 |
+
["EURUSD"],
|
| 524 |
+
["BTCUSD"],
|
| 525 |
+
["AAPL"]
|
| 526 |
+
],
|
| 527 |
+
inputs=pair_input,
|
| 528 |
+
label="Try these examples:"
|
| 529 |
+
)
|
|
|
|
|
|
|
| 530 |
|
| 531 |
+
# Analysis function
|
| 532 |
analyze_btn.click(
|
| 533 |
+
fn=analyze_trading_pair,
|
| 534 |
+
inputs=pair_input,
|
| 535 |
+
outputs=[result_output, price_chart, forecast_chart]
|
| 536 |
)
|
| 537 |
|
| 538 |
+
# Launch the app
|
| 539 |
if __name__ == "__main__":
|
| 540 |
demo.launch(
|
| 541 |
server_name="0.0.0.0",
|
data/{EURUSD2022_2025.csv โ raw/EURUSD2022_2025.csv}
RENAMED
|
File without changes
|
pre_treat_data.rtf
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{\rtf1\ansi\ansicpg1252\cocoartf2822
|
| 2 |
+
\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
|
| 3 |
+
{\colortbl;\red255\green255\blue255;}
|
| 4 |
+
{\*\expandedcolortbl;;}
|
| 5 |
+
\margl1440\margr1440\vieww11520\viewh8400\viewkind0
|
| 6 |
+
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0
|
| 7 |
+
|
| 8 |
+
\f0\fs24 \cf0 # \uc0\u22312 \u26412 \u22320 Mac \u19978 \u36816 \u34892 \
|
| 9 |
+
import pandas as pd\
|
| 10 |
+
\
|
| 11 |
+
# \uc0\u35835 \u21462 \u21407 \u22987 \u25991 \u20214 \
|
| 12 |
+
df = pd.read_csv('data/EURUSD2022_2025.csv')\
|
| 13 |
+
\
|
| 14 |
+
# \uc0\u20551 \u35774 \u26085 \u26399 \u21015 \u21517 \u20026 'Date'\
|
| 15 |
+
if 'Date' in df.columns:\
|
| 16 |
+
# \uc0\u31227 \u38500 GMT \u37096 \u20998 \u24182 \u26631 \u20934 \u21270 \u26684 \u24335 \
|
| 17 |
+
df['Date'] = df['Date'].str.replace(' GMT', '', regex=False)\
|
| 18 |
+
df['Date'] = pd.to_datetime(df['Date'], format='%d.%m.%Y %H:%M:%S.%f %z', utc=True)\
|
| 19 |
+
\
|
| 20 |
+
# \uc0\u37325 \u32622 \u32034 \u24341 \
|
| 21 |
+
df.set_index('Date', inplace=True)\
|
| 22 |
+
\
|
| 23 |
+
# \uc0\u20445 \u23384 \u26631 \u20934 \u21270 \u25991 \u20214 \
|
| 24 |
+
df.to_csv('data/EURUSD_standard.csv')\
|
| 25 |
+
print("\uc0\u9989 \u24050 \u21019 \u24314 \u26631 \u20934 \u21270 \u25991 \u20214 : data/EURUSD_standard.csv")}
|