-
Notifications
You must be signed in to change notification settings - Fork 621
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
141 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright (c) 2024 hikyuu.org | ||
* | ||
* Created on: 2024-02-03 | ||
* Author: fasiondog | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "hikyuu/indicator/Indicator.h" | ||
#include "hikyuu/trade_sys/environment/EnvironmentBase.h" | ||
|
||
namespace hku { | ||
|
||
/** | ||
* 布尔信号指标市场环境 | ||
* @param ind bool类型的指标,指标中相应位置>0则代表市场有效,否则无效 | ||
* @param market 指定的市场,用于获取相应的交易日历 | ||
* @return | ||
*/ | ||
EVPtr HKU_API EV_Bool(const Indicator& ind, const string& market = "SH"); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
hikyuu_cpp/hikyuu/trade_sys/environment/imp/BoolEnvironment.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (c) 2024 hikyuu.org | ||
* | ||
* Created on: 2024-02-03 | ||
* Author: fasiondog | ||
*/ | ||
|
||
#include "hikyuu/StockManager.h" | ||
#include "BoolEnvironment.h" | ||
|
||
#if HKU_SUPPORT_SERIALIZATION | ||
BOOST_CLASS_EXPORT(hku::BoolEnvironment) | ||
#endif | ||
|
||
namespace hku { | ||
|
||
BoolEnvironment::BoolEnvironment() : EnvironmentBase("EV_Bool") { | ||
setParam<string>("market", "SH"); | ||
} | ||
|
||
BoolEnvironment::BoolEnvironment(const Indicator& ind) : EnvironmentBase("EV_Bool"), m_ind(ind) { | ||
setParam<string>("market", "SH"); | ||
} | ||
|
||
BoolEnvironment::~BoolEnvironment() {} | ||
|
||
EnvironmentPtr BoolEnvironment::_clone() { | ||
return make_shared<BoolEnvironment>(m_ind.clone()); | ||
} | ||
|
||
void BoolEnvironment::_calculate() { | ||
string market = getParam<string>("market"); | ||
const StockManager& sm = StockManager::instance(); | ||
MarketInfo market_info = sm.getMarketInfo(market); | ||
HKU_ERROR_IF_RETURN(market_info == Null<MarketInfo>(), void(), "Can't find maket({}) info!", | ||
market); | ||
|
||
Stock stock = sm.getStock(market + market_info.code()); | ||
KData kdata = stock.getKData(m_query); | ||
|
||
auto ds = kdata.getDatetimeList(); | ||
m_ind.setContext(kdata); | ||
for (size_t i = m_ind.discard(), len = m_ind.size(); i < len; i++) { | ||
if (!std::isnan(m_ind[i]) && m_ind[i] > 0.) { | ||
_addValid(ds[i]); | ||
} | ||
} | ||
} | ||
|
||
EVPtr HKU_API EV_Bool(const Indicator& ind, const string& market) { | ||
BoolEnvironment* p = new BoolEnvironment(ind); | ||
p->setParam<string>("market", market); | ||
return EVPtr(p); | ||
} | ||
|
||
} // namespace hku |
40 changes: 40 additions & 0 deletions
40
hikyuu_cpp/hikyuu/trade_sys/environment/imp/BoolEnvironment.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright (c) 2024 hikyuu.org | ||
* | ||
* Created on: 2024-02-03 | ||
* Author: fasiondog | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "hikyuu/indicator/Indicator.h" | ||
#include "hikyuu/trade_sys/environment/EnvironmentBase.h" | ||
|
||
namespace hku { | ||
|
||
class BoolEnvironment : public EnvironmentBase { | ||
public: | ||
BoolEnvironment(); | ||
BoolEnvironment(const Indicator& ind); | ||
virtual ~BoolEnvironment(); | ||
|
||
virtual void _calculate() override; | ||
virtual EnvironmentPtr _clone() override; | ||
|
||
private: | ||
Indicator m_ind; | ||
|
||
//============================================ | ||
// 序列化支持 | ||
//============================================ | ||
#if HKU_SUPPORT_SERIALIZATION | ||
friend class boost::serialization::access; | ||
template <class Archive> | ||
void serialize(Archive& ar, const unsigned int version) { | ||
ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(EnvironmentBase); | ||
ar& BOOST_SERIALIZATION_NVP(m_ind); | ||
} | ||
#endif | ||
}; | ||
|
||
} // namespace hku |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters