add CN_Manual, EV_Manual, SG_Manual

This commit is contained in:
KongDong 2024-09-16 22:57:03 +08:00
parent 5da2b6e0ab
commit 6a1bd02b43
14 changed files with 217 additions and 30 deletions

View File

@ -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 */

View File

@ -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

View File

@ -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<ManualCondition>();
}
} // namespace hku

View File

@ -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

View File

@ -11,5 +11,6 @@
#include "crt/EV_TwoLine.h"
#include "crt/EV_Bool.h"
#include "crt/EV_Manual.h"
#endif /* ENVIRONMENT_BUILD_IN_H */

View File

@ -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

View File

@ -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<ManualEnvironment>();
}
} // namespace hku

View File

@ -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

View File

@ -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_ */

View File

@ -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

View File

@ -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<ManualSignal>();
}
} // namespace hku

View File

@ -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

View File

@ -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<bool>("support_borrow_cash", getParam<bool>("support_borrow_cash"));
m_tm->setParam<bool>("support_borrow_stock", getParam<bool>("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());
}

View File

@ -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<KData> m_kdata_list;
size_t m_cur_kdata{0};
@ -52,6 +53,7 @@ private:
template <class Archive>
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 */