Add initial implementation of backtesting framework with CLI interface. Introduce core modules for data loading, trade management, performance metrics, and logging. Include Supertrend indicator calculations and slippage estimation. Update .gitignore to exclude logs and CSV files.
This commit is contained in:
24
data.py
Normal file
24
data.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from __future__ import annotations
|
||||
import pandas as pd
|
||||
from pathlib import Path
|
||||
|
||||
def load_data(start: str, end: str, timeframe_minutes: int, csv_path: Path) -> tuple[pd.DataFrame, pd.DataFrame]:
|
||||
df_1min = pd.read_csv(csv_path)
|
||||
df_1min["Timestamp"] = pd.to_datetime(df_1min["Timestamp"], unit="s", utc=True)
|
||||
df_1min = df_1min[(df_1min["Timestamp"] >= pd.Timestamp(start, tz="UTC")) &
|
||||
(df_1min["Timestamp"] <= pd.Timestamp(end, tz="UTC"))] \
|
||||
.sort_values("Timestamp").reset_index(drop=True)
|
||||
|
||||
if timeframe_minutes != 1:
|
||||
g = df_1min.set_index("Timestamp").resample(f"{timeframe_minutes}min")
|
||||
df = pd.DataFrame({
|
||||
"Open": g["Open"].first(),
|
||||
"High": g["High"].max(),
|
||||
"Low": g["Low"].min(),
|
||||
"Close": g["Close"].last(),
|
||||
"Volume": g["Volume"].sum(),
|
||||
}).dropna().reset_index()
|
||||
else:
|
||||
df = df_1min.copy()
|
||||
|
||||
return df_1min, df
|
||||
Reference in New Issue
Block a user