mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-11-30 02:48:57 +08:00
add CN_Manual, EV_Manual, SG_Manual
This commit is contained in:
parent
5da2b6e0ab
commit
6a1bd02b43
@ -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 */
|
||||
|
20
hikyuu_cpp/hikyuu/trade_sys/condition/crt/CN_Manual.h
Normal file
20
hikyuu_cpp/hikyuu/trade_sys/condition/crt/CN_Manual.h
Normal 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
|
@ -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
|
23
hikyuu_cpp/hikyuu/trade_sys/condition/imp/ManualCondition.h
Normal file
23
hikyuu_cpp/hikyuu/trade_sys/condition/imp/ManualCondition.h
Normal 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
|
@ -11,5 +11,6 @@
|
||||
|
||||
#include "crt/EV_TwoLine.h"
|
||||
#include "crt/EV_Bool.h"
|
||||
#include "crt/EV_Manual.h"
|
||||
|
||||
#endif /* ENVIRONMENT_BUILD_IN_H */
|
||||
|
20
hikyuu_cpp/hikyuu/trade_sys/environment/crt/EV_Manual.h
Normal file
20
hikyuu_cpp/hikyuu/trade_sys/environment/crt/EV_Manual.h
Normal 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
|
@ -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
|
@ -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
|
@ -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_ */
|
||||
|
20
hikyuu_cpp/hikyuu/trade_sys/signal/crt/SG_Manual.h
Normal file
20
hikyuu_cpp/hikyuu/trade_sys/signal/crt/SG_Manual.h
Normal 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
|
24
hikyuu_cpp/hikyuu/trade_sys/signal/imp/ManualSignal.cpp
Normal file
24
hikyuu_cpp/hikyuu/trade_sys/signal/imp/ManualSignal.cpp
Normal 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
|
23
hikyuu_cpp/hikyuu/trade_sys/signal/imp/ManualSignal.h
Normal file
23
hikyuu_cpp/hikyuu/trade_sys/signal/imp/ManualSignal.h
Normal 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
|
@ -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());
|
||||
}
|
||||
|
@ -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 */
|
||||
|
Loading…
Reference in New Issue
Block a user