mirror of
https://github.com/NicolasBohn/NexQuant.git
synced 2026-08-03 02:17:43 +00:00
fix: prevent calendar index overflow when signal data ends early (#1324)
* fix: prevent calendar index overflow when signal data ends early * fix: make test_end optional to resolve Qlib backtest calendar misalignment * fix: enhance GPU information output in get_gpu_info function * fix: improve GPU information output in get_gpu_info function for better clarity --------- Co-authored-by: Xu Yang <peteryang@vip.qq.com>
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
from typing import Optional
|
||||
|
||||
from pydantic_settings import SettingsConfigDict
|
||||
|
||||
from rdagent.components.workflow.conf import BasePropSetting
|
||||
@@ -43,7 +45,7 @@ class ModelBasePropSetting(BasePropSetting):
|
||||
test_start: str = "2017-01-01"
|
||||
"""Start date of the test / backtest segment"""
|
||||
|
||||
test_end: str = "2020-12-31"
|
||||
test_end: Optional[str] = None
|
||||
"""End date of the test / backtest segment"""
|
||||
|
||||
|
||||
@@ -87,7 +89,7 @@ class FactorBasePropSetting(BasePropSetting):
|
||||
test_start: str = "2017-01-01"
|
||||
"""Start date of the test / backtest segment"""
|
||||
|
||||
test_end: str = "2020-12-31"
|
||||
test_end: Optional[str] = None
|
||||
"""End date of the test / backtest segment"""
|
||||
|
||||
|
||||
@@ -164,7 +166,7 @@ class QuantBasePropSetting(BasePropSetting):
|
||||
test_start: str = "2017-01-01"
|
||||
"""Start date of the test / backtest segment"""
|
||||
|
||||
test_end: str = "2020-12-31"
|
||||
test_end: Optional[str] = None
|
||||
"""End date of the test / backtest segment"""
|
||||
|
||||
|
||||
|
||||
@@ -89,8 +89,9 @@ class QlibFactorRunner(CachedRunner[QlibFactorExperiment]):
|
||||
"valid_start": fbps.valid_start,
|
||||
"valid_end": fbps.valid_end,
|
||||
"test_start": fbps.test_start,
|
||||
"test_end": fbps.test_end,
|
||||
}
|
||||
if fbps.test_end is not None:
|
||||
env_to_use.update({"test_end": fbps.test_end})
|
||||
|
||||
if exp.based_experiments:
|
||||
SOTA_factor = None
|
||||
|
||||
@@ -67,8 +67,9 @@ class QlibModelRunner(CachedRunner[QlibModelExperiment]):
|
||||
"valid_start": mbps.valid_start,
|
||||
"valid_end": mbps.valid_end,
|
||||
"test_start": mbps.test_start,
|
||||
"test_end": mbps.test_end,
|
||||
}
|
||||
if mbps.test_end is not None:
|
||||
env_to_use.update({"test_end": mbps.test_end})
|
||||
|
||||
training_hyperparameters = exp.sub_tasks[0].training_hyperparameters
|
||||
if training_hyperparameters:
|
||||
|
||||
@@ -21,5 +21,4 @@ RUN python -m pip install -e .
|
||||
|
||||
RUN pip install catboost
|
||||
RUN pip install xgboost
|
||||
RUN pip install scipy==1.11.4
|
||||
RUN pip install tables
|
||||
|
||||
@@ -7,7 +7,7 @@ benchmark: &benchmark SH000300
|
||||
|
||||
data_handler_config: &data_handler_config
|
||||
start_time: {{ train_start | default("2008-01-01", true) }}
|
||||
end_time: {{ test_end | default("2020-08-01", true) }}
|
||||
end_time: {{ test_end | default(null, true) }}
|
||||
fit_start_time: {{ train_start | default("2008-01-01", true) }}
|
||||
fit_end_time: {{ train_end | default("2014-12-31", true) }}
|
||||
instruments: *market
|
||||
@@ -43,7 +43,7 @@ port_analysis_config: &port_analysis_config
|
||||
n_drop: 5
|
||||
backtest:
|
||||
start_time: {{ test_start | default("2017-01-01", true) }}
|
||||
end_time: {{ test_end | default("2020-08-01", true) }}
|
||||
end_time: {{ test_end | default(null, true) }}
|
||||
account: 100000000
|
||||
benchmark: *benchmark
|
||||
exchange_kwargs:
|
||||
@@ -77,7 +77,7 @@ task:
|
||||
segments:
|
||||
train: [{{ train_start | default("2008-01-01", true) }}, {{ train_end | default("2014-12-31", true) }}]
|
||||
valid: [{{ valid_start | default("2015-01-01", true) }}, {{ valid_end | default("2016-12-31", true) }}]
|
||||
test: [{{ test_start | default("2017-01-01", true) }}, {{ test_end | default("2020-08-01", true) }}]
|
||||
test: [{{ test_start | default("2017-01-01", true) }}, {{ test_end | default(null, true) }}]
|
||||
record:
|
||||
- class: SignalRecord
|
||||
module_path: qlib.workflow.record_temp
|
||||
|
||||
@@ -7,7 +7,7 @@ benchmark: &benchmark SH000300
|
||||
|
||||
data_handler_config: &data_handler_config
|
||||
start_time: {{ train_start | default("2008-01-01", true) }}
|
||||
end_time: {{ test_end | default("2020-08-01", true) }}
|
||||
end_time: {{ test_end | default(null, true) }}
|
||||
instruments: *market
|
||||
data_loader:
|
||||
class: NestedDataLoader
|
||||
@@ -51,7 +51,7 @@ port_analysis_config: &port_analysis_config
|
||||
n_drop: 5
|
||||
backtest:
|
||||
start_time: {{ test_start | default("2017-01-01", true) }}
|
||||
end_time: {{ test_end | default("2020-08-01", true) }}
|
||||
end_time: {{ test_end | default(null, true) }}
|
||||
account: 100000000
|
||||
benchmark: *benchmark
|
||||
exchange_kwargs:
|
||||
@@ -86,7 +86,7 @@ task:
|
||||
segments:
|
||||
train: [{{ train_start | default("2008-01-01", true) }}, {{ train_end | default("2014-12-31", true) }}]
|
||||
valid: [{{ valid_start | default("2015-01-01", true) }}, {{ valid_end | default("2016-12-31", true) }}]
|
||||
test: [{{ test_start | default("2017-01-01", true) }}, {{ test_end | default("2020-08-01", true) }}]
|
||||
test: [{{ test_start | default("2017-01-01", true) }}, {{ test_end | default(null, true) }}]
|
||||
record:
|
||||
- class: SignalRecord
|
||||
module_path: qlib.workflow.record_temp
|
||||
|
||||
+3
-3
@@ -7,7 +7,7 @@ benchmark: &benchmark SH000300
|
||||
|
||||
data_handler_config: &data_handler_config
|
||||
start_time: {{ train_start | default("2008-01-01", true) }}
|
||||
end_time: {{ test_end | default("2020-08-01", true) }}
|
||||
end_time: {{ test_end | default(null, true) }}
|
||||
instruments: *market
|
||||
data_loader:
|
||||
class: NestedDataLoader
|
||||
@@ -61,7 +61,7 @@ port_analysis_config: &port_analysis_config
|
||||
n_drop: 5
|
||||
backtest:
|
||||
start_time: {{ test_start | default("2017-01-01", true) }}
|
||||
end_time: {{ test_end | default("2020-08-01", true) }}
|
||||
end_time: {{ test_end | default(null, true) }}
|
||||
account: 100000000
|
||||
benchmark: *benchmark
|
||||
exchange_kwargs:
|
||||
@@ -100,7 +100,7 @@ task:
|
||||
segments:
|
||||
train: [{{ train_start | default("2008-01-01", true) }}, {{ train_end | default("2014-12-31", true) }}]
|
||||
valid: [{{ valid_start | default("2015-01-01", true) }}, {{ valid_end | default("2016-12-31", true) }}]
|
||||
test: [{{ test_start | default("2017-01-01", true) }}, {{ test_end | default("2020-08-01", true) }}]
|
||||
test: [{{ test_start | default("2017-01-01", true) }}, {{ test_end | default(null, true) }}]
|
||||
{% if step_len %}step_len: {{ step_len }}{% endif %}
|
||||
record:
|
||||
- class: SignalRecord
|
||||
|
||||
@@ -5,7 +5,7 @@ market: &market csi300
|
||||
benchmark: &benchmark SH000300
|
||||
data_handler_config: &data_handler_config
|
||||
start_time: {{ train_start | default("2008-01-01", true) }}
|
||||
end_time: {{ test_end | default("2020-08-01", true) }}
|
||||
end_time: {{ test_end | default(null, true) }}
|
||||
fit_start_time: {{ train_start | default("2008-01-01", true) }}
|
||||
fit_end_time: {{ train_end | default("2014-12-31", true) }}
|
||||
instruments: *market
|
||||
@@ -41,7 +41,7 @@ port_analysis_config: &port_analysis_config
|
||||
n_drop: 5
|
||||
backtest:
|
||||
start_time: {{ test_start | default("2017-01-01", true) }}
|
||||
end_time: {{ test_end | default("2020-08-01", true) }}
|
||||
end_time: {{ test_end | default(null, true) }}
|
||||
account: 100000000
|
||||
benchmark: *benchmark
|
||||
exchange_kwargs:
|
||||
@@ -80,7 +80,7 @@ task:
|
||||
segments:
|
||||
train: [{{ train_start | default("2008-01-01", true) }}, {{ train_end | default("2014-12-31", true) }}]
|
||||
valid: [{{ valid_start | default("2015-01-01", true) }}, {{ valid_end | default("2016-12-31", true) }}]
|
||||
test: [{{ test_start | default("2017-01-01", true) }}, {{ test_end | default("2020-08-01", true) }}]
|
||||
test: [{{ test_start | default("2017-01-01", true) }}, {{ test_end | default(null, true) }}]
|
||||
{% if step_len %}step_len: {{ step_len }}{% endif %}
|
||||
record:
|
||||
- class: SignalRecord
|
||||
|
||||
@@ -7,7 +7,7 @@ benchmark: &benchmark SH000300
|
||||
|
||||
data_handler_config: &data_handler_config
|
||||
start_time: {{ train_start | default("2008-01-01", true) }}
|
||||
end_time: {{ test_end | default("2020-08-01", true) }}
|
||||
end_time: {{ test_end | default(null, true) }}
|
||||
instruments: *market
|
||||
data_loader:
|
||||
class: NestedDataLoader
|
||||
@@ -61,7 +61,7 @@ port_analysis_config: &port_analysis_config
|
||||
n_drop: 5
|
||||
backtest:
|
||||
start_time: {{ test_start | default("2017-01-01", true) }}
|
||||
end_time: {{ test_end | default("2020-08-01", true) }}
|
||||
end_time: {{ test_end | default(null, true) }}
|
||||
account: 100000000
|
||||
benchmark: *benchmark
|
||||
exchange_kwargs:
|
||||
@@ -100,7 +100,7 @@ task:
|
||||
segments:
|
||||
train: [{{ train_start | default("2008-01-01", true) }}, {{ train_end | default("2014-12-31", true) }}]
|
||||
valid: [{{ valid_start | default("2015-01-01", true) }}, {{ valid_end | default("2016-12-31", true) }}]
|
||||
test: [{{ test_start | default("2017-01-01", true) }}, {{ test_end | default("2020-08-01", true) }}]
|
||||
test: [{{ test_start | default("2017-01-01", true) }}, {{ test_end | default(null, true) }}]
|
||||
{% if step_len %}step_len: {{ step_len }}{% endif %}
|
||||
record:
|
||||
- class: SignalRecord
|
||||
|
||||
@@ -17,10 +17,30 @@ def get_gpu_info():
|
||||
if torch.cuda.is_available():
|
||||
print("\n=== GPU Info (via PyTorch) ===")
|
||||
print(f"CUDA Version: {torch.version.cuda}")
|
||||
print(f"GPU Device: {torch.cuda.get_device_name(0)}")
|
||||
print(f"Total GPU Memory: {torch.cuda.get_device_properties(0).total_memory / 1024**3:.2f} GB")
|
||||
print(f"Allocated Memory: {torch.cuda.memory_allocated(0) / 1024**3:.2f} GB")
|
||||
print(f"Cached Memory: {torch.cuda.memory_reserved(0) / 1024**3:.2f} GB")
|
||||
print(f"GPU Count: {torch.cuda.device_count()}")
|
||||
if torch.cuda.device_count() > 0:
|
||||
gpu_name_list = []
|
||||
gpu_total_mem_list = []
|
||||
gpu_allocated_mem_list = []
|
||||
gpu_cached_mem_list = []
|
||||
|
||||
for i in range(torch.cuda.device_count()):
|
||||
gpu_name_list.append(torch.cuda.get_device_name(i))
|
||||
gpu_total_mem_list.append(torch.cuda.get_device_properties(i).total_memory)
|
||||
gpu_allocated_mem_list.append(torch.cuda.memory_allocated(i))
|
||||
gpu_cached_mem_list.append(torch.cuda.memory_reserved(i))
|
||||
|
||||
for i in range(torch.cuda.device_count()):
|
||||
print(f" - GPU {i}: {gpu_name_list[i]}")
|
||||
print(f" Total Memory: {gpu_total_mem_list[i] / 1024**3:.2f} GB")
|
||||
print(f" Allocated Memory: {gpu_allocated_mem_list[i] / 1024**3:.2f} GB")
|
||||
print(f" Cached Memory: {gpu_cached_mem_list[i] / 1024**3:.2f} GB")
|
||||
print(" - All GPUs Summary:")
|
||||
print(f" Total Memory: {sum(gpu_total_mem_list) / 1024**3:.2f} GB")
|
||||
print(f" Total Allocated Memory: {sum(gpu_allocated_mem_list) / 1024**3:.2f} GB")
|
||||
print(f" Total Cached Memory: {sum(gpu_cached_mem_list) / 1024**3:.2f} GB")
|
||||
else:
|
||||
print("No CUDA GPU detected (PyTorch)!")
|
||||
else:
|
||||
print("\nNo CUDA GPU detected (PyTorch).")
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ def filter_redundant_text(stdout: str) -> str:
|
||||
filtered_stdout = try_regex_sub(progress_bar_pattern, filtered_stdout, flags=regex.VERBOSE)
|
||||
|
||||
# Collapse any excessive blank lines/spaces
|
||||
filtered_stdout = try_regex_sub(r"\s*\n\s*", filtered_stdout, replace_with="\n")
|
||||
filtered_stdout = try_regex_sub(r"\s*\n", filtered_stdout, replace_with="\n")
|
||||
|
||||
# remove repeated lines
|
||||
lines_to_count: dict[str, int] = {}
|
||||
|
||||
@@ -687,7 +687,7 @@ class QlibCondaEnv(LocalEnv[QlibCondaConf]):
|
||||
shell=True,
|
||||
)
|
||||
subprocess.check_call(
|
||||
f"conda run -n {self.conf.conda_env_name} pip install catboost xgboost scipy==1.11.4 tables torch",
|
||||
f"conda run -n {self.conf.conda_env_name} pip install catboost xgboost tables torch",
|
||||
shell=True,
|
||||
)
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user