diff --git a/hikyuu_cpp/hikyuu/trade_sys/condition/build_in.h b/hikyuu_cpp/hikyuu/trade_sys/condition/build_in.h index 49adcd9c..a5efbc28 100644 --- a/hikyuu_cpp/hikyuu/trade_sys/condition/build_in.h +++ b/hikyuu_cpp/hikyuu/trade_sys/condition/build_in.h @@ -12,5 +12,6 @@ #include "crt/CN_Bool.h" #include "crt/CN_OPLine.h" #include "crt/CN_Logic.h" +#include "crt/CN_Manual.h" #endif /* CONDITION_BUILD_IN_H */ diff --git a/hikyuu_cpp/hikyuu/trade_sys/condition/crt/CN_Manual.h b/hikyuu_cpp/hikyuu/trade_sys/condition/crt/CN_Manual.h new file mode 100644 index 00000000..762eae41 --- /dev/null +++ b/hikyuu_cpp/hikyuu/trade_sys/condition/crt/CN_Manual.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2019~2023, hikyuu.org + * + * History: + * 1. 20240916 added by fasiondog + */ + +#pragma once + +#include "../ConditionBase.h" + +namespace hku { + +/** + * 仅能手工添加有效性的CN,用于测试或其他特殊用途 + * @return CNPtr + */ +CNPtr HKU_API CN_Manual(); + +} // namespace hku \ No newline at end of file diff --git a/hikyuu_cpp/hikyuu/trade_sys/condition/imp/ManualCondition.cpp b/hikyuu_cpp/hikyuu/trade_sys/condition/imp/ManualCondition.cpp new file mode 100644 index 00000000..fa418ffb --- /dev/null +++ b/hikyuu_cpp/hikyuu/trade_sys/condition/imp/ManualCondition.cpp @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2019~2023, hikyuu.org + * + * History: + * 1. 20240916 added by fasiondog + */ + +#include "ManualCondition.h" + +#if HKU_SUPPORT_SERIALIZATION +BOOST_CLASS_EXPORT(hku::ManualCondition) +#endif + +namespace hku { + +ManualCondition::ManualCondition() : ConditionBase("CN_Manual") {} + +void ManualCondition::_calculate() {} + +CNPtr HKU_API CN_Manual() { + return make_shared(); +} + +} // namespace hku \ No newline at end of file diff --git a/hikyuu_cpp/hikyuu/trade_sys/condition/imp/ManualCondition.h b/hikyuu_cpp/hikyuu/trade_sys/condition/imp/ManualCondition.h new file mode 100644 index 00000000..3af92136 --- /dev/null +++ b/hikyuu_cpp/hikyuu/trade_sys/condition/imp/ManualCondition.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2019~2023, hikyuu.org + * + * History: + * 1. 20240916 added by fasiondog + */ + +#pragma once + +#include "../ConditionBase.h" + +namespace hku { + +class ManualCondition : public ConditionBase { + CONDITION_IMP(ManualCondition) + CONDITION_NO_PRIVATE_MEMBER_SERIALIZATION + +public: + ManualCondition(); + virtual ~ManualCondition() = default; +}; + +} // namespace hku \ No newline at end of file diff --git a/hikyuu_cpp/hikyuu/trade_sys/environment/build_in.h b/hikyuu_cpp/hikyuu/trade_sys/environment/build_in.h index 46397738..e2631a8d 100644 --- a/hikyuu_cpp/hikyuu/trade_sys/environment/build_in.h +++ b/hikyuu_cpp/hikyuu/trade_sys/environment/build_in.h @@ -11,5 +11,6 @@ #include "crt/EV_TwoLine.h" #include "crt/EV_Bool.h" +#include "crt/EV_Manual.h" #endif /* ENVIRONMENT_BUILD_IN_H */ diff --git a/hikyuu_cpp/hikyuu/trade_sys/environment/crt/EV_Manual.h b/hikyuu_cpp/hikyuu/trade_sys/environment/crt/EV_Manual.h new file mode 100644 index 00000000..83bed1c3 --- /dev/null +++ b/hikyuu_cpp/hikyuu/trade_sys/environment/crt/EV_Manual.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2019~2023, hikyuu.org + * + * History: + * 1. 20240916 added by fasiondog + */ + +#pragma once + +#include "../EnvironmentBase.h" + +namespace hku { + +/** + * 仅能手工添加系统环境有效性的EV,用于测试或其他用途 + * @return EVPtr + */ +EVPtr HKU_API EV_Manual(); + +} // namespace hku diff --git a/hikyuu_cpp/hikyuu/trade_sys/environment/imp/ManualEnvironment.cpp b/hikyuu_cpp/hikyuu/trade_sys/environment/imp/ManualEnvironment.cpp new file mode 100644 index 00000000..ff6ee7d0 --- /dev/null +++ b/hikyuu_cpp/hikyuu/trade_sys/environment/imp/ManualEnvironment.cpp @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2019~2023, hikyuu.org + * + * History: + * 1. 20240916 added by fasiondog + */ + +#include "ManualEnvironment.h" + +#if HKU_SUPPORT_SERIALIZATION +BOOST_CLASS_EXPORT(hku::ManualEnvironment) +#endif + +namespace hku { + +ManualEnvironment::ManualEnvironment() : EnvironmentBase("EV_Manual") {} + +void ManualEnvironment::_calculate() {} + +EVPtr HKU_API EV_Manual() { + return make_shared(); +} + +} // namespace hku \ No newline at end of file diff --git a/hikyuu_cpp/hikyuu/trade_sys/environment/imp/ManualEnvironment.h b/hikyuu_cpp/hikyuu/trade_sys/environment/imp/ManualEnvironment.h new file mode 100644 index 00000000..59cd043f --- /dev/null +++ b/hikyuu_cpp/hikyuu/trade_sys/environment/imp/ManualEnvironment.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2019~2023, hikyuu.org + * + * History: + * 1. 20240916 added by fasiondog + */ + +#pragma once + +#include "../EnvironmentBase.h" + +namespace hku { + +class ManualEnvironment : public EnvironmentBase { + ENVIRONMENT_IMP(ManualEnvironment) + ENVIRONMENT_NO_PRIVATE_MEMBER_SERIALIZATION + +public: + ManualEnvironment(); + virtual ~ManualEnvironment() = default; +}; + +} // namespace hku \ No newline at end of file diff --git a/hikyuu_cpp/hikyuu/trade_sys/signal/build_in.h b/hikyuu_cpp/hikyuu/trade_sys/signal/build_in.h index ba577ff9..204bda4b 100644 --- a/hikyuu_cpp/hikyuu/trade_sys/signal/build_in.h +++ b/hikyuu_cpp/hikyuu/trade_sys/signal/build_in.h @@ -17,5 +17,6 @@ #include "crt/SG_Single.h" #include "crt/SG_Bool.h" #include "crt/SG_Band.h" +#include "crt/SG_Manual.h" #endif /* SIGNAL_BUILD_IN_H_ */ diff --git a/hikyuu_cpp/hikyuu/trade_sys/signal/crt/SG_Manual.h b/hikyuu_cpp/hikyuu/trade_sys/signal/crt/SG_Manual.h new file mode 100644 index 00000000..b82351f4 --- /dev/null +++ b/hikyuu_cpp/hikyuu/trade_sys/signal/crt/SG_Manual.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2019~2023, hikyuu.org + * + * History: + * 1. 20240916 added by fasiondog + */ + +#pragma once + +#include "../SignalBase.h" + +namespace hku { + +/** + * 仅能手动添加信号的信号指示器,用于测试或其他特殊用途 + * @return SignalPtr + */ +SignalPtr HKU_API SG_Manual(); + +} // namespace hku \ No newline at end of file diff --git a/hikyuu_cpp/hikyuu/trade_sys/signal/imp/ManualSignal.cpp b/hikyuu_cpp/hikyuu/trade_sys/signal/imp/ManualSignal.cpp new file mode 100644 index 00000000..c9995668 --- /dev/null +++ b/hikyuu_cpp/hikyuu/trade_sys/signal/imp/ManualSignal.cpp @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2019~2023, hikyuu.org + * + * History: + * 1. 20240916 added by fasiondog + */ + +#include "ManualSignal.h" + +#if HKU_SUPPORT_SERIALIZATION +BOOST_CLASS_EXPORT(hku::ManualSignal) +#endif + +namespace hku { + +ManualSignal::ManualSignal() : SignalBase("SG_Manual") {} + +void ManualSignal::_calculate(const KData&) {} + +SignalPtr HKU_API SG_Manual() { + return make_shared(); +} + +} // namespace hku \ No newline at end of file diff --git a/hikyuu_cpp/hikyuu/trade_sys/signal/imp/ManualSignal.h b/hikyuu_cpp/hikyuu/trade_sys/signal/imp/ManualSignal.h new file mode 100644 index 00000000..b075111c --- /dev/null +++ b/hikyuu_cpp/hikyuu/trade_sys/signal/imp/ManualSignal.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2019~2023, hikyuu.org + * + * History: + * 1. 20240916 added by fasiondog + */ + +#pragma once + +#include "../SignalBase.h" + +namespace hku { + +class ManualSignal : public SignalBase { + SIGNAL_IMP(ManualSignal) + SIGNAL_NO_PRIVATE_MEMBER_SERIALIZATION + +public: + ManualSignal(); + virtual ~ManualSignal() = default; +}; + +} // namespace hku \ No newline at end of file diff --git a/hikyuu_cpp/hikyuu/trade_sys/system/imp/WalkForwardSystem.cpp b/hikyuu_cpp/hikyuu/trade_sys/system/imp/WalkForwardSystem.cpp index fc4a9701..68d4af13 100644 --- a/hikyuu_cpp/hikyuu/trade_sys/system/imp/WalkForwardSystem.cpp +++ b/hikyuu_cpp/hikyuu/trade_sys/system/imp/WalkForwardSystem.cpp @@ -5,6 +5,7 @@ * Author: fasiondog */ +#include "hikyuu/trade_manage/crt/crtTM.h" #include "hikyuu/trade_sys/selector/crt/SE_Optimal.h" #include "hikyuu/trade_sys/selector/imp/OptimalSelector.h" #include "WalkForwardSystem.h" @@ -15,11 +16,15 @@ BOOST_CLASS_EXPORT(hku::WalkForwardSystem) namespace hku { -WalkForwardSystem::WalkForwardSystem() : System("SYS_Optimal"), m_se(SE_Optimal()) {} +WalkForwardSystem::WalkForwardSystem() +: System("SYS_Optimal"), m_se(SE_Optimal()), m_train_tm(crtTM()) {} -WalkForwardSystem::WalkForwardSystem(const SystemList& candidate_sys_list) +WalkForwardSystem::WalkForwardSystem(const SystemList& candidate_sys_list, + const TradeManagerPtr& train_tm) : System("SYS_Optimal"), m_se(SE_Optimal()) { + HKU_ASSERT(train_tm); m_se->addSystemList(candidate_sys_list); + m_train_tm = train_tm->clone(); } void WalkForwardSystem::_reset() { @@ -50,6 +55,7 @@ void WalkForwardSystem::_forceResetAll() { SystemPtr WalkForwardSystem::_clone() { WalkForwardSystem* p = new WalkForwardSystem(); + p->m_train_tm = m_train_tm->clone(); p->m_se = m_se->clone(); p->m_se->reset(); return SystemPtr(p); @@ -124,35 +130,10 @@ void WalkForwardSystem::syncDataToSystem(const SYSPtr& sys) { void WalkForwardSystem::readyForRun() { HKU_CHECK(m_tm, "Not setTradeManager! {}", name()); - HKU_CHECK(m_mm, "Not setMoneyManager! {}", name()); - HKU_CHECK(m_sg, "Not setSignal! {}", name()); - - // 如果存在市场环境判断策略,则需要将默认的前一日市场有效标志置为false - // 因为需要由市场环境判断策略全权判定市场是否有效 - if (m_ev) - m_pre_ev_valid = false; - - if (m_cn) { - m_cn->setTM(m_tm); - m_cn->setSG(m_sg); - m_pre_cn_valid = false; // 默认的前一日市场有效标志置为false - } - - m_mm->setTM(m_tm); - if (m_pg) - m_pg->setTM(m_tm); - if (m_st) - m_st->setTM(m_tm); - if (m_tp) - m_tp->setTM(m_tm); - - m_tm->setParam("support_borrow_cash", getParam("support_borrow_cash")); - m_tm->setParam("support_borrow_stock", getParam("support_borrow_stock")); - m_se->reset(); const auto& candidate_sys_list = m_se->getProtoSystemList(); for (const auto& sys : candidate_sys_list) { - sys->setTM(getTM()->clone()); + sys->setTM(m_train_tm->clone()); } m_se->calculate(SystemList(), m_kdata.getQuery()); } diff --git a/hikyuu_cpp/hikyuu/trade_sys/system/imp/WalkForwardSystem.h b/hikyuu_cpp/hikyuu/trade_sys/system/imp/WalkForwardSystem.h index c616ee25..0a73f6ef 100644 --- a/hikyuu_cpp/hikyuu/trade_sys/system/imp/WalkForwardSystem.h +++ b/hikyuu_cpp/hikyuu/trade_sys/system/imp/WalkForwardSystem.h @@ -15,7 +15,7 @@ namespace hku { class HKU_API WalkForwardSystem : public System { public: WalkForwardSystem(); - WalkForwardSystem(const SystemList& candidate_sys_list); + WalkForwardSystem(const SystemList& candidate_sys_list, const TradeManagerPtr& train_tm); virtual ~WalkForwardSystem() = default; virtual void readyForRun() override; @@ -38,7 +38,8 @@ private: void syncDataToSystem(const SYSPtr&); private: - SEPtr m_se; + SEPtr m_se; // 寻优SE + TMPtr m_train_tm; // 用于优化评估计算的账户 SYSPtr m_cur_sys; vector m_kdata_list; size_t m_cur_kdata{0}; @@ -52,6 +53,7 @@ private: template void serialize(Archive& ar, const unsigned int version) { ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(System); + ar& BOOST_SERIALIZATION_NVP(m_train_tm); ar& BOOST_SERIALIZATION_NVP(m_se); } #endif /* HKU_SUPPORT_SERIALIZATION */