add Strategy continue

This commit is contained in:
fasiondog 2021-02-17 00:56:19 +08:00
parent 82ae061b92
commit 8e6b2e0f42
6 changed files with 105 additions and 0 deletions

View File

@ -0,0 +1,10 @@
/*
* Copyright(C) 2021 hikyuu.org
*
* Create on: 2021-02-16
* Author: fasiondog
*/
#include "StrategyBase.h"
namespace hku {} // namespace hku

View File

@ -0,0 +1,46 @@
/*
* Copyright(C) 2021 hikyuu.org
*
* Create on: 2021-02-16
* Author: fasiondog
*/
#pragma once
#include "../DataType.h"
#include "../StrategyContext.h"
#include "../utilities/Parameter.h"
#include "../trade_sys/portfolio/Portfolio.h"
namespace hku {
class HKU_API StrategyBase {
PARAMETER_SUPPORT
public:
StrategyBase() {}
virtual ~StrategyBase() {}
const string& name() const {
return m_name;
}
void name(const string& name) {
m_name = name;
}
// virtual void start() = 0;
virtual void on_bar() = 0;
private:
string m_name;
StrategyContext m_context;
TMPtr m_tm;
SYSPtr m_sys;
PFPtr m_portfolio;
};
typedef shared_ptr<StrategyBase> StrategyPtr;
} // namespace hku

View File

@ -37,6 +37,7 @@ class HKU_API TradeManagerBase {
public:
TradeManagerBase();
virtual ~TradeManagerBase() {}
/** 账户名称 */
const string& name() const {

View File

@ -41,6 +41,7 @@ void export_trade_sys_main();
void export_agent_main();
void export_StrategeContext();
void export_strategy_main();
KData Py_GetKData(const string& market_code, py::object start = py::long_(0),
py::object end = py::long_(Null<int64_t>()), KQuery::KType ktype = KQuery::DAY,
@ -123,6 +124,7 @@ BOOST_PYTHON_MODULE(core) {
export_trade_manage_main(); // must after export_trade_sys_main
export_StrategeContext();
export_strategy_main();
export_agent_main();

View File

@ -0,0 +1,34 @@
/*
* Copyright(C) 2021 hikyuu.org
*
* Create on: 2021-02-16
* Author: fasiondog
*/
#include <boost/python.hpp>
#include <hikyuu/strategy/StrategyBase.h>
#include "../_Parameter.h"
using namespace boost::python;
using namespace hku;
class StrategyBaseWrap : public StrategyBase, public wrapper<StrategyBase> {
public:
StrategyBaseWrap() : StrategyBase() {}
virtual ~StrategyBaseWrap() {}
void on_bar() override {
this->get_override("on_bar")();
}
};
const string& (StrategyBase::*strategy_get_name)() const = &StrategyBase::name;
void (StrategyBase::*strategy_set_name)(const string&) = &StrategyBase::name;
void export_Strategy() {
class_<StrategyBaseWrap, boost::noncopyable>("StrategyBase", init<>())
.add_property("name",
make_function(strategy_get_name, return_value_policy<copy_const_reference>()),
strategy_set_name)
.def("on_bar", pure_virtual(&StrategyBase::on_bar));
}

View File

@ -0,0 +1,12 @@
/*
* Copyright(C) 2021 hikyuu.org
*
* Create on: 2021-02-16
* Author: fasiondog
*/
void export_Strategy();
void export_strategy_main() {
export_Strategy();
}