2021-02-11 00:47:22 +08:00
|
|
|
|
/*
|
|
|
|
|
* Copyright(C) 2021 hikyuu.org
|
|
|
|
|
*
|
|
|
|
|
* Create on: 2021-02-10
|
|
|
|
|
* Author: fasiondog
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "DataType.h"
|
2021-02-19 01:12:50 +08:00
|
|
|
|
#include "KQuery.h"
|
2021-02-11 00:47:22 +08:00
|
|
|
|
|
|
|
|
|
namespace hku {
|
|
|
|
|
|
2024-09-01 01:38:11 +08:00
|
|
|
|
/**
|
|
|
|
|
* 策略上下文,定义策略执行时包含的证券/K线级别信息
|
|
|
|
|
* @ingroup Strategy
|
|
|
|
|
*
|
|
|
|
|
*/
|
2024-09-01 04:58:54 +08:00
|
|
|
|
class HKU_API StrategyContext {
|
2021-02-11 00:47:22 +08:00
|
|
|
|
public:
|
2024-09-01 01:38:11 +08:00
|
|
|
|
StrategyContext() = default;
|
2024-09-01 04:58:54 +08:00
|
|
|
|
virtual ~StrategyContext() = default;
|
2021-02-11 00:47:22 +08:00
|
|
|
|
|
2024-09-01 16:11:27 +08:00
|
|
|
|
/**
|
|
|
|
|
* 构造函数
|
|
|
|
|
* @note 未指定 ktypelist 时,默认按预加载参数加载全部
|
|
|
|
|
* @param stockCodeList 指定的证券代码列表,如:如:{"sz000001", "sz000002"}
|
|
|
|
|
*/
|
2024-09-01 01:38:11 +08:00
|
|
|
|
explicit StrategyContext(const vector<string>& stockCodeList);
|
2021-02-17 19:43:59 +08:00
|
|
|
|
|
2024-09-01 01:38:11 +08:00
|
|
|
|
/**
|
|
|
|
|
* 构造函数
|
|
|
|
|
* @note 证券列表中如果包含 ("ALL") 则表示全部证券;
|
2024-09-01 16:11:27 +08:00
|
|
|
|
* 指定K线类型列表同时影响着K线数据的优先加载顺序,靠前的将优先加载。同时受系统配置中预加载参数影响!
|
2024-09-01 01:38:11 +08:00
|
|
|
|
* @param stockCodeList 指定的证券代码列表,如:{"sh000001", "sz000001"}
|
|
|
|
|
* @param ktypeList 指定的 K线数据列表,如:{"day", "min"}
|
|
|
|
|
*/
|
|
|
|
|
StrategyContext(const vector<string>& stockCodeList, const vector<KQuery::KType>& ktypeList);
|
2024-08-25 22:11:25 +08:00
|
|
|
|
|
2024-09-01 04:58:54 +08:00
|
|
|
|
// 自定义移动构造与赋值会引起 python 中无法正常退出
|
|
|
|
|
// StrategyContext(const StrategyContext&) = default;
|
|
|
|
|
// StrategyContext(StrategyContext&& rv) = delete;
|
|
|
|
|
// StrategyContext& operator=(const StrategyContext&) = default;
|
|
|
|
|
// StrategyContext& operator=(StrategyContext&&) = delete;
|
2021-02-11 00:47:22 +08:00
|
|
|
|
|
2024-09-01 01:38:11 +08:00
|
|
|
|
/**
|
2024-09-01 16:11:27 +08:00
|
|
|
|
* 是否为加载全部证券,只要 stockCodeList 包含 "ALL"(不区分大小写) ,即认为加载全部
|
2024-09-01 01:38:11 +08:00
|
|
|
|
* @return true
|
|
|
|
|
* @return false
|
|
|
|
|
*/
|
2024-08-21 12:34:12 +08:00
|
|
|
|
bool isAll() const noexcept;
|
2021-02-19 01:12:50 +08:00
|
|
|
|
|
2024-09-01 16:11:27 +08:00
|
|
|
|
bool empty() const noexcept {
|
|
|
|
|
return m_stockCodeList.empty();
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-21 12:34:12 +08:00
|
|
|
|
Datetime startDatetime() const noexcept {
|
2021-02-11 00:47:22 +08:00
|
|
|
|
return m_startDatetime;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-01 01:38:11 +08:00
|
|
|
|
void setStockCodeList(const vector<string>& stockList) {
|
|
|
|
|
_removeDuplicateCode(stockList);
|
|
|
|
|
}
|
2021-02-11 00:47:22 +08:00
|
|
|
|
|
2024-09-01 01:38:11 +08:00
|
|
|
|
const vector<string>& getStockCodeList() const noexcept {
|
2021-02-11 00:47:22 +08:00
|
|
|
|
return m_stockCodeList;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-01 01:38:11 +08:00
|
|
|
|
void setKTypeList(const vector<KQuery::KType>& ktypeList) {
|
|
|
|
|
_checkAndRemoveDuplicateKType(ktypeList);
|
|
|
|
|
}
|
2021-02-19 01:12:50 +08:00
|
|
|
|
|
2024-09-01 01:38:11 +08:00
|
|
|
|
const vector<KQuery::KType>& getKTypeList() const noexcept {
|
2021-02-19 01:12:50 +08:00
|
|
|
|
return m_ktypeList;
|
|
|
|
|
}
|
2021-02-17 16:08:24 +08:00
|
|
|
|
|
2024-09-01 01:38:11 +08:00
|
|
|
|
/**
|
|
|
|
|
* 隐含的默认必须被加载的证券列表
|
|
|
|
|
* @note 影响交易日历判断、和某些常被作为默认比较基准的证券,通常被作为某些函数的默认值
|
|
|
|
|
*/
|
|
|
|
|
const vector<string>& getMustLoadStockCodeList() const noexcept {
|
2024-08-31 10:12:42 +08:00
|
|
|
|
return m_mustLoad;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-01 01:38:11 +08:00
|
|
|
|
/**
|
|
|
|
|
* 返回所有需要加载的证券列表(含指定的证券列表和默认包含必须加载的证券列表)
|
|
|
|
|
* @return vector<string>
|
|
|
|
|
*/
|
|
|
|
|
vector<string> getAllNeedLoadStockCodeList() const noexcept;
|
|
|
|
|
|
2024-09-01 16:11:27 +08:00
|
|
|
|
string str() const;
|
|
|
|
|
|
2024-09-01 01:38:11 +08:00
|
|
|
|
private:
|
|
|
|
|
void _removeDuplicateCode(const vector<string>& stockCodeList);
|
|
|
|
|
void _checkAndRemoveDuplicateKType(const vector<KQuery::KType>& ktypeList);
|
2024-08-31 10:12:42 +08:00
|
|
|
|
|
2021-02-11 00:47:22 +08:00
|
|
|
|
private:
|
2024-05-07 01:49:38 +08:00
|
|
|
|
Datetime m_startDatetime{19901219};
|
2024-08-31 10:12:42 +08:00
|
|
|
|
vector<string> m_mustLoad{"sh000001", "sh000300"}; // 默认必须加载的 stock
|
2021-02-11 00:47:22 +08:00
|
|
|
|
vector<string> m_stockCodeList;
|
2021-02-19 01:12:50 +08:00
|
|
|
|
vector<KQuery::KType> m_ktypeList;
|
2021-02-11 00:47:22 +08:00
|
|
|
|
};
|
|
|
|
|
|
2024-09-01 16:11:27 +08:00
|
|
|
|
HKU_API std::ostream& operator<<(std::ostream& os, const StrategyContext& context);
|
|
|
|
|
|
2021-02-11 00:47:22 +08:00
|
|
|
|
} // namespace hku
|