progress
This commit is contained in:
parent
2272a31765
commit
705330a9f7
@ -45,7 +45,6 @@ Each configuration dictionary specifies:
|
|||||||
- `instruments`: A list of symbols to consider for forming trading pairs.
|
- `instruments`: A list of symbols to consider for forming trading pairs.
|
||||||
- `trading_hours`: Defines the session start and end times, crucial for equity markets.
|
- `trading_hours`: Defines the session start and end times, crucial for equity markets.
|
||||||
- `price_column`: The column in the data to be used as the price (e.g., "close").
|
- `price_column`: The column in the data to be used as the price (e.g., "close").
|
||||||
- `min_required_points`: Minimum data points needed for statistical calculations.
|
|
||||||
- `zero_threshold`: A small value to handle potential division by zero.
|
- `zero_threshold`: A small value to handle potential division by zero.
|
||||||
- `dis-equilibrium_open_trshld`: The threshold (in standard deviations) of the dis-equilibrium for opening a trade.
|
- `dis-equilibrium_open_trshld`: The threshold (in standard deviations) of the dis-equilibrium for opening a trade.
|
||||||
- `dis-equilibrium_close_trshld`: The threshold (in standard deviations) of the dis-equilibrium for closing an open trade.
|
- `dis-equilibrium_close_trshld`: The threshold (in standard deviations) of the dis-equilibrium for closing an open trade.
|
||||||
|
|||||||
@ -13,7 +13,6 @@
|
|||||||
"timezone": "UTC"
|
"timezone": "UTC"
|
||||||
},
|
},
|
||||||
"price_column": "close",
|
"price_column": "close",
|
||||||
"min_required_points": 30,
|
|
||||||
"zero_threshold": 1e-10,
|
"zero_threshold": 1e-10,
|
||||||
"dis-equilibrium_open_trshld": 2.0,
|
"dis-equilibrium_open_trshld": 2.0,
|
||||||
"dis-equilibrium_close_trshld": 0.5,
|
"dis-equilibrium_close_trshld": 0.5,
|
||||||
|
|||||||
@ -13,15 +13,27 @@
|
|||||||
"timezone": "America/New_York"
|
"timezone": "America/New_York"
|
||||||
},
|
},
|
||||||
"price_column": "close",
|
"price_column": "close",
|
||||||
"min_required_points": 30,
|
"funding_per_pair": 2000.0,
|
||||||
"zero_threshold": 1e-10,
|
"zero_threshold": 1e-10,
|
||||||
|
#
|
||||||
"dis-equilibrium_open_trshld": 2.0,
|
"dis-equilibrium_open_trshld": 2.0,
|
||||||
"dis-equilibrium_close_trshld": 1.0,
|
"dis-equilibrium_close_trshld": 1.0,
|
||||||
"training_minutes": 120,
|
"training_minutes": 150,
|
||||||
"funding_per_pair": 2000.0,
|
|
||||||
"fit_method_class": "pt_trading.sliding_fit.SlidingFit",
|
"fit_method_class": "pt_trading.sliding_fit.SlidingFit",
|
||||||
# "fit_method_class": "pt_trading.static_fit.StaticFit",
|
|
||||||
"exclude_instruments": ["CAN"],
|
"exclude_instruments": ["CAN"],
|
||||||
"close_outstanding_positions": false
|
|
||||||
|
# ====== Stop Conditions ======
|
||||||
|
"stop_conditions": {
|
||||||
|
"profit": 1.0,
|
||||||
|
"loss": -0.5
|
||||||
|
}
|
||||||
|
|
||||||
|
# ====== End of Session Closeout ======
|
||||||
|
"close_outstanding_positions": true,
|
||||||
|
# "close_outstanding_positions": false,
|
||||||
|
"trading_hours": {
|
||||||
|
"begin_session": "9:30:00",
|
||||||
|
"end_session": "15:30:00",
|
||||||
|
"timezone": "America/New_York"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -13,7 +13,6 @@
|
|||||||
"timezone": "America/New_York"
|
"timezone": "America/New_York"
|
||||||
},
|
},
|
||||||
"price_column": "close",
|
"price_column": "close",
|
||||||
"min_required_points": 30,
|
|
||||||
"zero_threshold": 1e-10,
|
"zero_threshold": 1e-10,
|
||||||
"dis-equilibrium_open_trshld": 2.0,
|
"dis-equilibrium_open_trshld": 2.0,
|
||||||
"dis-equilibrium_close_trshld": 1.0,
|
"dis-equilibrium_close_trshld": 1.0,
|
||||||
|
|||||||
@ -170,7 +170,24 @@ def store_config_in_database(
|
|||||||
|
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
|
def convert_timestamp(timestamp: Any) -> Optional[datetime]:
|
||||||
|
"""Convert pandas Timestamp to Python datetime object for SQLite compatibility."""
|
||||||
|
if timestamp is None:
|
||||||
|
return None
|
||||||
|
if isinstance(timestamp, pd.Timestamp):
|
||||||
|
return timestamp.to_pydatetime()
|
||||||
|
elif isinstance(timestamp, datetime):
|
||||||
|
return timestamp
|
||||||
|
elif isinstance(timestamp, date):
|
||||||
|
return datetime.combine(timestamp, datetime.min.time())
|
||||||
|
elif isinstance(timestamp, str):
|
||||||
|
return datetime.strptime(timestamp, "%Y-%m-%d %H:%M:%S")
|
||||||
|
elif isinstance(timestamp, int):
|
||||||
|
return datetime.fromtimestamp(timestamp)
|
||||||
|
else:
|
||||||
|
raise ValueError(f"Unsupported timestamp type: {type(timestamp)}")
|
||||||
|
|
||||||
|
|
||||||
def store_results_in_database(
|
def store_results_in_database(
|
||||||
db_path: str, datafile: str, bt_result: "BacktestResult"
|
db_path: str, datafile: str, bt_result: "BacktestResult"
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -180,14 +197,6 @@ def store_results_in_database(
|
|||||||
if db_path.upper() == "NONE":
|
if db_path.upper() == "NONE":
|
||||||
return
|
return
|
||||||
|
|
||||||
def convert_timestamp(timestamp: Any) -> Optional[datetime]:
|
|
||||||
"""Convert pandas Timestamp to Python datetime object for SQLite compatibility."""
|
|
||||||
if timestamp is None:
|
|
||||||
return None
|
|
||||||
if hasattr(timestamp, "to_pydatetime"):
|
|
||||||
return timestamp.to_pydatetime()
|
|
||||||
return timestamp
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Extract date from datafile name (assuming format like 20250528.mktdata.ohlcv.db)
|
# Extract date from datafile name (assuming format like 20250528.mktdata.ohlcv.db)
|
||||||
filename = os.path.basename(datafile)
|
filename = os.path.basename(datafile)
|
||||||
@ -489,7 +498,11 @@ class BacktestResult:
|
|||||||
price = row.price
|
price = row.price
|
||||||
disequilibrium = getattr(row, "disequilibrium", None)
|
disequilibrium = getattr(row, "disequilibrium", None)
|
||||||
scaled_disequilibrium = getattr(row, "scaled_disequilibrium", None)
|
scaled_disequilibrium = getattr(row, "scaled_disequilibrium", None)
|
||||||
timestamp = getattr(row, "time", None)
|
if hasattr(row, "time"):
|
||||||
|
timestamp = getattr(row, "time")
|
||||||
|
else:
|
||||||
|
timestamp = convert_timestamp(row.Index)
|
||||||
|
|
||||||
self.add_trade(
|
self.add_trade(
|
||||||
pair_nm=str(row.pair),
|
pair_nm=str(row.pair),
|
||||||
action=str(action),
|
action=str(action),
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user