-
Notifications
You must be signed in to change notification settings - Fork 724
API Reference
- Introduction
- Data Management
- Indicators
- Trading Components
- Backtesting
- Utility Functions
- C++ Core API
- Python Interface
- [Data Management](Data Management/Data Management.md)
- [Base Info Drivers](Data Management/Base Info Drivers.md)
- [Block Info Drivers](Data Management/Block Info Drivers.md)
- [Data Driver Factory](Data Management/Data Driver Factory.md)
- [KData Drivers](Data Management/KData Drivers.md)
- [Indicator System](Indicator System/Indicator System.md)
- [Built-in Indicators](Indicator System/Built-in Indicators.md)
- [Custom Indicator Development](Indicator System/Custom Indicator Development.md)
- [TA-Lib Integration Indicators](Indicator System/TA-Lib Integration Indicators.md)
- [Trading System Components](Trading System Components/Trading System Components.md)
- [Allocation Funds](Trading System Components/Allocation Funds.md)
- [Money Management](Trading System Components/Money Management.md)
- [Profit Goals](Trading System Components/Profit Goals.md)
- [Signal Indicators](Trading System Components/Signal Indicators.md)
- [Slippage Models](Trading System Components/Slippage Models.md)
- [Stop Loss Algorithms](Trading System Components/Stop Loss Algorithms.md)
- [Trading Conditions](Trading System Components/Trading Conditions.md)
- [Utilities and Helpers](Utilities and Helpers/Utilities and Helpers.md)
- [Core Utilities](Utilities and Helpers/Core Utilities.md)
- [Database Connectivity](Utilities and Helpers/Database Connectivity.md)
- [Datetime Utilities](Utilities and Helpers/Datetime Utilities.md)
- [INI Parser](Utilities and Helpers/INI Parser.md)
- [Plugin System](Utilities and Helpers/Plugin System.md)
- [Threading and Concurrency](Utilities and Helpers/Threading and Concurrency.md)
The Hikyuu framework is a comprehensive quantitative trading system that provides tools for financial data management, technical indicator calculation, trading strategy development, and backtesting. This API reference documents the public interfaces exposed by both the C++ core and Python interface, organized by functional areas. The framework follows an object-oriented design with clear separation of concerns between data management, analysis components, and trading systems.
The framework's architecture is built around several key components:
- StockManager: Central repository for all stock and market data
- Indicator System: Comprehensive technical analysis engine with over 100 built-in indicators
- Trading System: Modular backtesting framework with configurable components
- Data Drivers: Flexible data access layer supporting multiple storage backends
The Python interface provides a high-level, user-friendly API that wraps the high-performance C++ core, allowing for both rapid prototyping and production-grade quantitative analysis.
The data management system in Hikyuu provides comprehensive functionality for accessing and manipulating financial market data. The core component is the StockManager, which serves as the central repository for all stock and market information.
classDiagram
class StockManager {
+instance() StockManager
+getStock(market_code) Stock
+get_block(category, name) Block
+get_trading_calendar(query, market) DatetimeList
+init(base_param, block_param, kdata_param, preload_param, hku_param, context) void
}
class Stock {
+market_code() string
+name() string
+type() int
+market() string
+get_kdata(query) KData
+realtime_update(krecord) void
+is_null() bool
}
class Block {
+name() string
+category() string
+add(stock) void
+remove(stock) void
+size() int
}
class KData {
+size() int
+open() Indicator
+close() Indicator
+high() Indicator
+low() Indicator
+vol() Indicator
+amo() Indicator
+get_datetime_list() DatetimeList
}
class Query {
+Query(start, end, ktype, recover_type)
+DATE QueryType
+INDEX QueryType
+DAY string
+WEEK string
+MONTH string
+NO_RECOVER RecoverType
+FORWARD RecoverType
+BACKWARD RecoverType
}
StockManager --> Stock : "contains"
StockManager --> Block : "contains"
Stock --> KData : "has"
KData --> Query : "uses"
Diagram sources
- init.py
- core.py
- main.cpp
- hikyuu.h
Section sources
- init.py
- core.py
- main.cpp
The indicator system in Hikyuu provides a comprehensive set of technical analysis tools for financial market analysis. Indicators are implemented as C++ classes wrapped with Python interfaces, providing high-performance calculations with a user-friendly API.
classDiagram
class Indicator {
+size() int
+discard() int
+name() string
+get_context() KData
+set_context(kdata) void
+to_numpy() numpy.ndarray
+to_pandas() pandas.DataFrame
+get_parameter() Parameter
+haveIndParam(name) bool
+setIndParam(name, indicator) void
+getIndParam(name) IndParam
}
class IndicatorImp {
+name() string
+discard() int
+getResultNumber() int
+getParameter() Parameter
+isNeedContext() bool
+supportIndParam() bool
+_clone() IndicatorImpPtr
+_calculate(ind) void
}
class IndParam {
+IndParam()
+IndParam(indicator)
+getImp() IndicatorImpPtr
+get() Indicator
}
class Parameter {
+set(name, value) void
+get(name) any
+has(name) bool
+get_name_list() list
+to_dict() dict
}
Indicator --> IndicatorImp : "implements"
Indicator --> IndParam : "uses"
IndicatorImp --> Parameter : "has"
IndParam --> IndicatorImp : "contains"
Diagram sources
- indicator.py
- Indicator.h
- IndicatorImp.h
- IndParam.h
- extend.py
The trading components in Hikyuu provide a modular framework for implementing trading strategies and managing trade execution. The system is designed with a component-based architecture that allows for flexible strategy construction.
classDiagram
class TradeManagerBase {
+currentCash() price_t
+getTotalNumber(stock) double
+getAvailableNumber(stock) double
+getBuyCost(datetime, stock, price, number) CostRecord
+getSellCost(datetime, stock, price, number) CostRecord
+buy(datetime, stock, real_price, number, stoploss, goal_price, plan_price, part, remark) TradeRecord
+sell(datetime, stock, real_price, number, stoploss, goal_price, plan_price, part, remark) TradeRecord
+getTradeList() TradeRecordList
+getPerformance() Performance
}
class OrderBrokerBase {
+name() string
+buy(tm, trade_record) bool
+sell(tm, trade_record) bool
+get_position(stock) BrokerPositionRecord
+get_all_positions() list[BrokerPositionRecord]
}
class TradeRecord {
+datetime Datetime
+stock Stock
+business int
+planPrice price_t
+realPrice price_t
+goalPrice price_t
+number double
+cost CostRecord
+stoploss price_t
+cash price_t
+from SystemPart
+remark string
}
class CostRecord {
+realPrice price_t
+number double
+total price_t
+brokage price_t
+stamp_tax price_t
+transfer_fee price_t
}
class BrokerPositionRecord {
+stock Stock
+number double
+available double
+buy_date Datetime
+cost_price price_t
}
TradeManagerBase --> TradeRecord : "manages"
TradeManagerBase --> CostRecord : "calculates"
OrderBrokerBase --> BrokerPositionRecord : "tracks"
TradeManagerBase --> OrderBrokerBase : "notifies"
Diagram sources
- BrokerTradeManager.cpp
- OrderBrokerBase.h
- _TradeManager.cpp
The backtesting system in Hikyuu provides a comprehensive framework for evaluating trading strategies. The system is designed with a modular architecture that allows for flexible strategy construction and evaluation.
classDiagram
class System {
+run(stock, query) void
+getTM() TradeManagerBase
+getSG() Signal
+getMM() MoneyManager
+getST() Stoploss
+getTP() TakeProfit
+getPG() ProfitGoal
+getEV() Environment
+setTM(tm) void
+setSG(sg) void
+setMM(mm) void
+setST(st) void
+setTP(tp) void
+setPG(pg) void
+setEV(ev) void
+readyForRun() bool
}
class Signal {
+isValid(datetime) bool
+getBuySignal(datetime) int
+getSellSignal(datetime) int
}
class MoneyManager {
+getNumber(datetime, stock, price, risk) double
}
class Stoploss {
+getStoploss(datetime, stock, price) price_t
}
class TakeProfit {
+getGoalPrice(datetime, stock, price) price_t
}
class ProfitGoal {
+getGoalPrice(datetime, stock, price) price_t
}
class Environment {
+isValid(datetime) bool
}
System --> Signal : "uses"
System --> MoneyManager : "uses"
System --> Stoploss : "uses"
System --> TakeProfit : "uses"
System --> ProfitGoal : "uses"
System --> Environment : "uses"
System --> TradeManagerBase : "controls"
Diagram sources
- trade_sys/init.py
- trade_manage/init.py
Hikyuu provides a comprehensive set of utility functions for common tasks in quantitative analysis. These functions are designed to simplify common operations and provide a consistent interface across the framework.
classDiagram
class UtilityFunctions {
+load_hikyuu(**kwargs) void
+hku_save(var, filename) void
+hku_load(filename) object
+set_global_context(stk, query) void
+get_global_context() KData
+select(cond, start, end, print_out) list[Stock]
+select2(inds, start, end, stks) pandas.DataFrame
+realtime_update(source, delta, stk_list) void
+get_part(name, **kwargs) object
+get_part_info(name) dict
+print_part_info(name) void
+search_part(name, hub, part_type, label) list[string]
}
class GlobalVariables {
+sm StockManager
+O Indicator
+C Indicator
+H Indicator
+L Indicator
+A Indicator
+V Indicator
+Q Query
+blocka Block
+zsbk_a Block
+blocksh Block
+zsbk_sh Block
+blocksz Block
+zsbk_sz Block
+blockbj Block
+zsbk_bj Block
+blockg Block
+zsbk_cyb Block
+blockstart Block
+blockzxb Block
+zsbk_zxb Block
+zsbk_sh50 Block
+zsbk_sh180 Block
+zsbk_hs300 Block
+zsbk_zz100 Block
}
UtilityFunctions --> GlobalVariables : "modifies"
Diagram sources
- init.py
- hub.py
- interactive.py
The C++ core of Hikyuu provides high-performance implementations of all framework components. The API is designed with a focus on performance and memory efficiency, while providing a clean, object-oriented interface.
classDiagram
class HikyuuCore {
+hikyuu_init(config_file_name, ignore_preload, context) void
+getConfigFromIni(config_file_name, baseParam, blockParam, kdataParam, preloadParam, hkuParam) void
+get_version() string
+get_stock(market_code) Stock
+get_block(category, name) Block
+getKData(market_code, query) KData
+setPythonInJupyter(flag) void
+setPythonInInteractive(flag) void
}
HikyuuCore --> StockManager : "initializes"
HikyuuCore --> Stock : "creates"
HikyuuCore --> Block : "creates"
HikyuuCore --> KData : "creates"
Diagram sources
- hikyuu.h
- main.cpp
The Python interface for Hikyuu provides a high-level, user-friendly API that wraps the high-performance C++ core. The interface is designed to be intuitive and easy to use, while providing access to all the functionality of the underlying C++ implementation.
classDiagram
class PythonInterface {
+from hikyuu import *
+load_hikyuu(**kwargs) void
+hku_save(var, filename) void
+hku_load(filename) object
+set_global_context(stk, query) void
+get_global_context() KData
+select(cond, start, end, print_out) list[Stock]
+select2(inds, start, end, stks) pandas.DataFrame
+realtime_update(source, delta, stk_list) void
+get_part(name, **kwargs) object
+get_part_info(name) dict
+print_part_info(name) void
+search_part(name, hub, part_type, label) list[string]
}
PythonInterface --> CppCore : "wraps"
PythonInterface --> UtilityFunctions : "exposes"
PythonInterface --> GlobalVariables : "exposes"
Diagram sources
- init.py
- core.py
- extend.py
- hub.py