-
Notifications
You must be signed in to change notification settings - Fork 724
Troubleshooting and FAQ
- Introduction
- Common Installation Issues
- Configuration Problems
- Data-Related Issues
- Performance Optimization
- FAQ
- Getting Additional Help
This troubleshooting and FAQ guide provides comprehensive solutions for common issues encountered when using the Hikyuu quantitative trading framework. The document covers installation problems, configuration errors, data-related issues, performance optimization tips, and frequently asked questions. All solutions are based on the actual codebase and error handling mechanisms implemented in Hikyuu.
The framework is designed for quantitative trading research, particularly focused on the Chinese A-share market. It provides a systematic approach to strategy development, backtesting, and real-time trading with high performance capabilities.
Section sources
- readme.md
Issue: When importing Hikyuu, you encounter an error message like "Please use pipdeptree -p hikyuu to check if there are missing dependency packages."
Cause: This occurs when required Python packages are not installed or when there are version conflicts between hikyuu and its dependencies.
Solution:
- Check for missing dependencies using:
pipdeptree -p hikyuu - Install missing packages using pip:
pip install package_name - Ensure compatibility between hikyuu and hikyuu_plugin versions. The major version numbers should match.
- If using conda, create a dedicated environment:
conda create -n hikyuu python=3.x
Section sources
- init.py
Issue: On Windows systems, you may encounter errors related to loading dynamic libraries (DLLs).
Cause: The system cannot locate the required C++ libraries that Hikyuu depends on.
Solution:
- Ensure the C++ library directory is added to the system PATH environment variable.
- The library path is automatically added in
__init__.pyusingos.add_dll_directory()and by modifying the PATH variable. - If issues persist, manually add the hikyuu/cpp directory to your system PATH.
Section sources
- init.py
Issue: You see a warning message: "hikyuu version (x.x.x) does not match hikyuu_plugin version (y.y.y), please ensure compatible versions!"
Cause: The hikyuu and hikyuu_plugin packages have different major version numbers, which can lead to compatibility issues.
Solution:
- Check the installed versions:
pip show hikyuuandpip show hikyuu_plugin - Update both packages to ensure version compatibility:
pip install --upgrade hikyuu hikyuu_plugin
- If using specific versions, ensure the major and minor version numbers match.
Section sources
- init.py
Issue: When calling load_hikyuu(), you receive the error: "Configuration file does not exist: ~/.hikyuu/hikyuu.ini"
Cause: The required configuration file has not been created in the user's home directory.
Solution:
- The system will automatically create a default configuration file when
load_hikyuu()is called without a specified config file. - The default configuration is generated by
generate_default_config()in hku_config_template.py. - On Windows, the default data directory is set to "c:\stock", while on Linux/macOS, it's "~/stock".
- You can also manually create the configuration file using the templates provided in the codebase.
Section sources
- init.py
- hku_config_template.py
Issue: Data cannot be loaded or saved, with errors indicating file or directory not found.
Cause: The data directory specified in the configuration file does not exist or has incorrect permissions.
Solution:
- Verify the
datadirsetting in your hikyuu.ini configuration file. - Ensure the directory exists and is writable.
- The default configuration automatically creates the data directory if it doesn't exist.
- Check that the path uses the correct format for your operating system (forward slashes for Linux/macOS, backslashes for Windows).
Section sources
- hku_config_template.py
Issue: Database connection errors when using MySQL or SQLite storage.
Cause: Incorrect database connection parameters or missing database files.
Solution:
- For SQLite: Ensure the database file path is correct and the directory exists.
- For MySQL: Verify the host, port, username, and password in the configuration.
- The framework automatically creates the database structure if it doesn't exist.
- Use the appropriate template (hdf5_template, mysql_template, or clickhouse_template) based on your storage preference.
Section sources
- hku_config_template.py
- common_sqlite3.py
- common_mysql.py
Issue: When attempting to retrieve stock data, you receive empty results or errors indicating no data available.
Cause: The required data has not been imported into the system.
Solution:
- Ensure you have imported stock data using one of the data import methods:
-
pytdx_to_h5.pyfor importing from TDX using pytdx -
tdx_to_h5.pyfor importing from local TDX files -
pytdx_to_mysql.pyfor importing to MySQL
-
- Verify that the data import process completed successfully by checking the log files.
- Confirm that the stock code and market are correct (e.g., 'SH600000' for Shanghai market).
Section sources
- pytdx_to_h5.py
- tdx_to_h5.py
Issue: Stock data appears to be outdated or missing recent trading days.
Cause: The data import process did not complete successfully or was interrupted.
Solution:
- Check the last update date in the database using
get_last_date()function. - Re-run the data import process, ensuring a stable internet connection.
- For real-time updates, use the
realtime_update()function:realtime_update(source='qq', delta=60)
- Verify that the data source (e.g., QQ, QMT) is accessible and not blocked.
Section sources
- pytdx_to_h5.py
- init.py
Issue: Data validation errors when importing or processing stock data.
Cause: Inconsistent data formats between the source and the expected format in Hikyuu.
Solution:
- The framework includes data validation in
import_one_stock_data()that checks for reasonable price movements (less than 2% difference from previous close). - If data validation fails, the import process will return 0 records.
- Ensure the data source provides data in the expected format (prices in yuan, volumes in shares).
- For custom data sources, implement proper data transformation before import.
Section sources
- pytdx_to_h5.py
Issue: Loading large amounts of data takes longer than expected.
Cause: Inefficient data access patterns or suboptimal configuration.
Solution:
- Use HDF5 format for data storage, which is optimized for fast access.
- Preload only the necessary data types and time ranges:
load_hikyuu(ktype_list=['day'], preload_num={'day_max': 1000})
- Increase the maximum number of preloaded records in the configuration file.
- Ensure you have sufficient RAM for caching data.
Section sources
- init.py
- hku_config_template.py
Issue: High memory consumption when working with large datasets.
Solution:
- Configure selective data loading in hikyuu.ini:
[preload] day = True week = False month = False - Load only specific stocks rather than all A-shares:
load_hikyuu(stock_list=['SH600000', 'SZ000001'])
- Disable loading of unnecessary data:
load_hikyuu(load_history_finance=False, load_weight=False)
- Use Query objects to limit the time range of data retrieved.
Section sources
- init.py
Issue: Data import process is slow or times out.
Solution:
- Use batch processing with appropriate step sizes:
- Daily data: 800 records per batch
- 5-minute data: 800 records per batch
- Increase the timeout settings if network latency is high.
- Use multiple threads for data import when supported.
- Consider using local TDX files instead of network APIs for faster import.
Section sources
- pytdx_to_h5.py
Q: How do I change the default data storage location?
A: Modify the datadir parameter in your hikyuu.ini configuration file. The default location is "c:\stock" on Windows and "~/stock" on Linux/macOS.
Q: What data formats are supported? A: Hikyuu supports HDF5, MySQL, ClickHouse, and SQLite for data storage. HDF5 is the default and recommended format due to its speed and efficiency.
Q: How do I update my data to the latest trading day?
A: Use the realtime_update() function or re-run the data import process. The system will automatically detect and import only new data.
Q: How do I create a simple trading strategy? A: Use the provided components to build your strategy:
my_tm = crtTM(init_cash=300000)
my_sg = SG_Flex(EMA(CLOSE(), n=5), slow_n=10)
my_mm = MM_FixedCount(1000)
sys = SYS_Simple(tm=my_tm, sg=my_sg, mm=my_mm)
sys.run(sm['sz000001'], Query(-150))Q: Can I use custom indicators in my strategies? A: Yes, you can create custom indicators by extending the Indicator class or by combining existing indicators using mathematical operations.
Q: How do I perform a backtest on multiple stocks? A: Use the block system to define a group of stocks and iterate through them:
for stock in blocka:
sys.run(stock, query)Q: How accurate are the backtesting results? A: The framework accounts for transaction costs, slippage, and other real-world factors. However, results may differ from actual trading due to market impact and other unpredictable factors.
Q: Can I backtest intraday strategies? A: Yes, the framework supports multiple time frames including minute data (1min, 5min, etc.) for intraday strategy testing.
Q: How do I configure the system to use MySQL instead of HDF5?
A: Change the type parameter in the [kdata] section of hikyuu.ini from 'hdf5' to 'mysql' and provide the appropriate connection details.
Q: What is the purpose of the preload settings? A: Preload settings determine which data types are loaded into memory when the system starts, balancing startup time and runtime performance.
Section sources
- readme.md
- init.py
- hku_config_template.py
When you encounter issues that cannot be resolved using this documentation, consider the following resources:
-
Official Documentation: Refer to the comprehensive help documentation at https://hikyuu.readthedocs.io/
-
Source Code: Examine the source code in the repository, particularly:
- Error handling in
hikyuu/util/mylog.py - Configuration templates in
hikyuu/data/hku_config_template.py - Data import scripts in the
hikyuu/data/directory
- Error handling in
-
Community Support: Join the official WeChat group or QQ group mentioned in the README for community support.
-
Issue Tracking: Report bugs or request features on the GitHub repository: https://github.com/fasiondog/hikyuu
-
Donation and Priority Support: Consider the donation plan for priority support from the developer.
When seeking help, please provide:
- The exact error message
- Your operating system and Python version
- The version of Hikyuu you are using
- A minimal code example that reproduces the issue
- Relevant log files (hikyuu.log and hikyuu_py.log from ~/.hikyuu/)
Section sources
- readme.md
- mylog.py