Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add macosx support #299

Merged
merged 11 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions .github/workflows/macos_arm64.yml → .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
matrix:
os: [macos-14]
arch: [arm64]
kind: [shared]
kind: [static]

runs-on: ${{ matrix.os }}

Expand Down Expand Up @@ -46,8 +46,16 @@ jobs:

- name: config
run: |
xmake f -c -k ${{ matrix.kind }} -y -vD --mysql=n --hdf5=n
xmake f -c -k ${{ matrix.kind }} -y -vD --feedback=n

- name: build
run: |
xmake -b core
xmake -b core

- name: build
run: |
xmake -b small-test

- name: test
run: |
xmake r small-test
3 changes: 2 additions & 1 deletion hikyuu/draw/drawplot/matplotlib_draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def set_mpl_params():
rcParams['font.family'] = 'sans-serif'
rcParams['axes.unicode_minus'] = False

expected_fonts = ['Microsoft YaHei', 'SimSun', 'SimHei', 'Source Han Sans CN', 'Noto Sans CJK JP']
expected_fonts = ['Microsoft YaHei', 'SimSun', 'SimHei',
'Source Han Sans CN', 'Noto Sans CJK JP', 'Arial Unicode MS']
current_fonts = matplotlib.rcParams['font.sans-serif']
for font in expected_fonts:
if font in current_fonts:
Expand Down
24 changes: 12 additions & 12 deletions hikyuu/test/Datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# -*- coding: utf8 -*-
# cp936

#===============================================================================
# ===============================================================================
# 作者:fasiondog
# 历史:1)20120927, Added by fasiondog
#===============================================================================
# ===============================================================================

import unittest

Expand All @@ -24,16 +24,16 @@ def test_Datetime(self):
self.assertEqual(Datetime(140001010000), Datetime.min())
self.assertEqual(Datetime(999912310000), Datetime.max())

self.assert_(d == Datetime(201209272301))
self.assert_(d != Datetime(200101010000))
self.assert_(d >= Datetime(201209272301))
self.assert_(d >= Datetime(201209272259))
self.assert_(d <= Datetime(201209272301))
self.assert_(d <= Datetime(201209272302))
self.assert_(not (d > Datetime(201209272301)))
self.assert_(d > Datetime(201209272259))
self.assert_(not (d < Datetime(201209272301)))
self.assert_(d < Datetime(201209272302))
self.assertEqual(d, Datetime(201209272301))
self.assertNotEqual(d, Datetime(200101010000))
self.assertGreaterEqual(d, Datetime(201209272301))
self.assertTrue(d >= Datetime(201209272259))
self.assertTrue(d <= Datetime(201209272301))
self.assertTrue(d <= Datetime(201209272302))
self.assertTrue(not (d > Datetime(201209272301)))
self.assertTrue(d > Datetime(201209272259))
self.assertTrue(not (d < Datetime(201209272301)))
self.assertTrue(d < Datetime(201209272302))

d = Datetime(200101010159)
self.assertEqual(str(d), "2001-01-01 01:59:00")
Expand Down
72 changes: 36 additions & 36 deletions hikyuu/test/Indicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,21 @@ def test_PythonIndicator(self):
self.assertEqual(m.name, "AddIndicator")
self.assertEqual(len(m), 4)
self.assertEqual(m.empty(), False)
self.assert_(abs(m[0] - 1) < 0.0001)
self.assert_(abs(m[1] - 2) < 0.0001)
self.assert_(abs(m[2] - 3) < 0.0001)
self.assert_(abs(m[3] - 4) < 0.0001)
self.assertTrue(abs(m[0] - 1) < 0.0001)
self.assertTrue(abs(m[1] - 2) < 0.0001)
self.assertTrue(abs(m[2] - 3) < 0.0001)
self.assertTrue(abs(m[3] - 4) < 0.0001)

b = toPriceList([1, 2, 3, 4])
x = PRICELIST(b)
m.get_imp()._calculate(m)
m = m(x)
self.assertEqual(len(m), 4)
self.assertEqual(m.empty(), False)
self.assert_(abs(m[0] - 2) < 0.0001)
self.assert_(abs(m[1] - 3) < 0.0001)
self.assert_(abs(m[2] - 4) < 0.0001)
self.assert_(abs(m[3] - 5) < 0.0001)
self.assertTrue(abs(m[0] - 2) < 0.0001)
self.assertTrue(abs(m[1] - 3) < 0.0001)
self.assertTrue(abs(m[2] - 4) < 0.0001)
self.assertTrue(abs(m[3] - 5) < 0.0001)

def test_operator(self):
a = toPriceList([0, 1, 2, 3, 5])
Expand All @@ -76,16 +76,16 @@ def test_operator(self):
self.assertEqual(a[3], 7)

a = x1 + 1.1
self.assert_(abs(a[0] - 1.1) < 0.0001)
self.assert_(abs(a[1] - 2.1) < 0.0001)
self.assert_(abs(a[2] - 3.1) < 0.0001)
self.assert_(abs(a[3] - 4.1) < 0.0001)
self.assertTrue(abs(a[0] - 1.1) < 0.0001)
self.assertTrue(abs(a[1] - 2.1) < 0.0001)
self.assertTrue(abs(a[2] - 3.1) < 0.0001)
self.assertTrue(abs(a[3] - 4.1) < 0.0001)

a = 2.1 + x1
self.assert_(abs(a[0] - 2.1) < 0.0001)
self.assert_(abs(a[1] - 3.1) < 0.0001)
self.assert_(abs(a[2] - 4.1) < 0.0001)
self.assert_(abs(a[3] - 5.1) < 0.0001)
self.assertTrue(abs(a[0] - 2.1) < 0.0001)
self.assertTrue(abs(a[1] - 3.1) < 0.0001)
self.assertTrue(abs(a[2] - 4.1) < 0.0001)
self.assertTrue(abs(a[3] - 5.1) < 0.0001)

a = x2 - x1
self.assertEqual(a[0], 1)
Expand Down Expand Up @@ -124,10 +124,10 @@ def test_operator(self):
self.assertEqual(a[3], 6)

a = x2 / x1
self.assert_(isinf(a[0]))
self.assertTrue(isinf(a[0]))
self.assertEqual(a[1], 2)
self.assertEqual(a[2], 1.5)
self.assert_(abs(a[3] - 4.0 / 3.0) < 0.0001)
self.assertTrue(abs(a[3] - 4.0 / 3.0) < 0.0001)

a = x1 / 0.5
self.assertEqual(a[0], 0)
Expand All @@ -136,10 +136,10 @@ def test_operator(self):
self.assertEqual(a[3], 6)

a = 2. / x1
self.assert_(isinf(a[0]))
self.assertTrue(isinf(a[0]))
self.assertEqual(a[1], 2.0)
self.assertEqual(a[2], 1.)
self.assert_(abs(a[3] - 2.0/3.0) < 0.0001)
self.assertTrue(abs(a[3] - 2.0/3.0) < 0.0001)

a = x1 > x2
self.assertEqual(a[0], 0 > 1)
Expand Down Expand Up @@ -180,30 +180,30 @@ def test_IKDATA(self):
self.assertEqual(a.empty(), False)
self.assertEqual(v.empty(), False)

self.assert_(abs(o[0] - 96.05) < 0.0001)
self.assert_(abs(h[0] - 99.98) < 0.0001)
self.assert_(abs(l[0] - 95.79) < 0.0001)
self.assert_(abs(c[0] - 99.98) < 0.0001)
self.assert_(abs(a[0] - 49.4) < 0.0001)
self.assert_(abs(v[0] - 1260) < 0.0001)
self.assertTrue(abs(o[0] - 96.05) < 0.0001)
self.assertTrue(abs(h[0] - 99.98) < 0.0001)
self.assertTrue(abs(l[0] - 95.79) < 0.0001)
self.assertTrue(abs(c[0] - 99.98) < 0.0001)
self.assertTrue(abs(a[0] - 49.4) < 0.0001)
self.assertTrue(abs(v[0] - 1260) < 0.0001)

self.assert_(abs(o[1] - 104.3) < 0.0001)
self.assert_(abs(h[1] - 104.39) < 0.0001)
self.assert_(abs(l[1] - 99.98) < 0.0001)
self.assert_(abs(c[1] - 104.39) < 0.0001)
self.assert_(abs(a[1] - 8.4) < 0.0001)
self.assert_(abs(v[1] - 197) < 0.0001)
self.assertTrue(abs(o[1] - 104.3) < 0.0001)
self.assertTrue(abs(h[1] - 104.39) < 0.0001)
self.assertTrue(abs(l[1] - 99.98) < 0.0001)
self.assertTrue(abs(c[1] - 104.39) < 0.0001)
self.assertTrue(abs(a[1] - 8.4) < 0.0001)
self.assertTrue(abs(v[1] - 197) < 0.0001)

def test_MA(self):
a = toPriceList([0, 1, 2, 3])
x = PRICELIST(a)
m = MA(x, 2)
self.assertEqual(len(m), 4)
self.assertEqual(m.discard, 0)
self.assert_(abs(m[0] - 0.0) < 0.0001)
self.assert_(abs(m[1] - 0.5) < 0.0001)
self.assert_(abs(m[2] - 1.5) < 0.0001)
self.assert_(abs(m[3] - 2.5) < 0.0001)
self.assertTrue(abs(m[0] - 0.0) < 0.0001)
self.assertTrue(abs(m[1] - 0.5) < 0.0001)
self.assertTrue(abs(m[2] - 1.5) < 0.0001)
self.assertTrue(abs(m[3] - 2.5) < 0.0001)

def test_pickle(self):
if not constant.pickle_support:
Expand Down
22 changes: 11 additions & 11 deletions hikyuu/test/KData.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# -*- coding: utf8 -*-
# gb18030

#===============================================================================
# ===============================================================================
# 作者:fasiondog
# 历史:1)20130220, Added by fasiondog
#===============================================================================
# ===============================================================================

import unittest

Expand Down Expand Up @@ -33,14 +33,14 @@ def test_kdata(self):
self.assertEqual(k.end_pos, 10)
self.assertEqual(k.last_pos, 9)
self.assertEqual(k[0].datetime, Datetime(199012190000))
self.assert_(abs(k[0].open - 96.05) < 0.0001)
self.assert_(abs(k[0].high - 99.980) < 0.0001)
self.assert_(abs(k[0].low - 95.79) < 0.0001)
self.assert_(abs(k[0].close - 99.98) < 0.0001)
self.assert_(abs(k[0].amount - 49.4) < 0.0001)
self.assert_(abs(k[0].volume - 1260) < 0.0001)
self.assert_(abs(k[1].open - 104.3) < 0.0001)
self.assert_(abs(k[9].open - 127.61) < 0.0001)
self.assertTrue(abs(k[0].open - 96.05) < 0.0001)
self.assertTrue(abs(k[0].high - 99.980) < 0.0001)
self.assertTrue(abs(k[0].low - 95.79) < 0.0001)
self.assertTrue(abs(k[0].close - 99.98) < 0.0001)
self.assertTrue(abs(k[0].amount - 49.4) < 0.0001)
self.assertTrue(abs(k[0].volume - 1260) < 0.0001)
self.assertTrue(abs(k[1].open - 104.3) < 0.0001)
self.assertTrue(abs(k[9].open - 127.61) < 0.0001)

def test_pickle(self):
if not constant.pickle_support:
Expand All @@ -61,4 +61,4 @@ def test_pickle(self):


def suite():
return unittest.TestLoader().loadTestsFromTestCase(KDataTest)
return unittest.TestLoader().loadTestsFromTestCase(KDataTest)
20 changes: 10 additions & 10 deletions hikyuu/test/Stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ def test_stock(self):

s1 = sm['sh000001']
s2 = sm['sh000001']
self.assert_(s1 == s2)
self.assert_(not (s1 != s2))
self.assertTrue(s1 == s2)
self.assertTrue(not (s1 != s2))

s2 = sm['sz000001']
self.assert_(not (s1 == s2))
self.assert_(s1 != s2)
self.assertTrue(not (s1 == s2))
self.assertTrue(s1 != s2)

def test_pickle(self):
if not constant.pickle_support:
Expand Down Expand Up @@ -79,7 +79,7 @@ def test_external_stock(self):

self.assertEqual(stk.valid, False)
stk.valid = True
self.assert_(stk.valid)
self.assertTrue(stk.valid)

self.assertNotEqual(stk.type, constant.STOCKTYPE_A)
stk.type = constant.STOCKTYPE_A
Expand Down Expand Up @@ -113,14 +113,14 @@ def test_external_stock(self):
self.assertEqual(len(k), 1)
self.assertEqual(k[0], KRecord(Datetime(20010101), 5.0, 9.0, 4.0, 6.5, 1000.0, 100000.0))

self.assert_(stk not in sm)
self.assertTrue(stk not in sm)
sm.add_stock(stk)
self.assert_(stk in sm)
self.assertTrue(stk in sm)
stk2 = sm['ab000001']
self.assert_(not stk2.is_null())
self.assert_(stk2, stk)
self.assertTrue(not stk2.is_null())
self.assertTrue(stk2, stk)
sm.remove_stock("ab000001")
self.assert_(stk not in sm)
self.assertTrue(stk not in sm)


def suite():
Expand Down
4 changes: 3 additions & 1 deletion hikyuu_cpp/hikyuu/DataType.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define NOMINMAX
#endif

#include "config.h"
#include <boost/config.hpp>

#include <stdio.h>
Expand All @@ -28,8 +29,9 @@
// #include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>

#include "config.h"
#include "utilities/Log.h"
#include "utilities/osdef.h"
#include "utilities/cppdef.h"
Expand Down
2 changes: 1 addition & 1 deletion hikyuu_cpp/hikyuu/indicator/imp/IRecover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void IRecover::_checkParam(const string& name) const {
}

void IRecover::checkInputIndicator(const Indicator& ind) {
HKU_CHECK(typeid(*(ind.getImp())) == typeid(IKData),
HKU_CHECK(dynamic_cast<IKData*>(ind.getImp().get()) != nullptr,
"Only the following indicators are accepted: OPEN|HIGH|CLOSE|LOW");
string part = ind.getParam<string>("kpart");
HKU_CHECK(part == "CLOSE" || part == "OPEN" || part == "HIGH" || part == "LOW",
Expand Down
25 changes: 25 additions & 0 deletions hikyuu_cpp/hikyuu/trade_manage/OrderBrokerBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,33 @@ class HKU_API OrderBrokerBase {

protected:
string m_name;

//============================================
// 序列化支持
//============================================
#if HKU_SUPPORT_SERIALIZATION
private:
friend class boost::serialization::access;
template <class Archive>
void save(Archive& ar, const unsigned int version) const {
ar& BOOST_SERIALIZATION_NVP(m_name);
ar& BOOST_SERIALIZATION_NVP(m_params);
}

template <class Archive>
void load(Archive& ar, const unsigned int version) {
ar& BOOST_SERIALIZATION_NVP(m_name);
ar& BOOST_SERIALIZATION_NVP(m_params);
}

BOOST_SERIALIZATION_SPLIT_MEMBER()
#endif /* HKU_SUPPORT_SERIALIZATION */
};

#if HKU_SUPPORT_SERIALIZATION
BOOST_SERIALIZATION_ASSUME_ABSTRACT(OrderBrokerBase)
#endif

/**
* 客户程序应使用此类型进行实际操作
* @ingroup OrderBroker
Expand Down
4 changes: 0 additions & 4 deletions hikyuu_cpp/hikyuu/trade_manage/TradeManagerBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -737,10 +737,6 @@ class HKU_API TradeManagerBase {
#endif /* HKU_SUPPORT_SERIALIZATION */
};

#if HKU_SUPPORT_SERIALIZATION
BOOST_SERIALIZATION_ASSUME_ABSTRACT(TradeManagerBase)
#endif

inline void TradeManagerBase::baseCheckParam(const string& name) const {
if ("precision" == name) {
int precision = getParam<int>("precision");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ IndicatorList ICIRMultiFactor::_calculate(const vector<IndicatorList>& all_stk_i

return all_factors;
#else
return parallel_for_index(0, stk_count, [&, this, discard, ind_count, days_total](size_t si) {
return parallel_for_index(0, stk_count, [&, discard, ind_count, days_total](size_t si) {
PriceList new_values(days_total, 0.0);
PriceList sum_weight(days_total, 0.0);
for (size_t di = 0; di < discard; di++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ IndicatorList ICMultiFactor::_calculate(const vector<IndicatorList>& all_stk_ind
return all_factors;

#else
return parallel_for_index(0, stk_count, [&, this, ind_count, days_total, discard](size_t si) {
return parallel_for_index(0, stk_count, [&, ind_count, days_total, discard](size_t si) {
PriceList new_values(days_total, 0.0);
PriceList sum_weight(days_total, 0.0);
for (size_t di = 0; di < discard; di++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class PerformanceOptimalSelector : public OptimalSelectorBase {
virtual void _checkParam(const string& name) const override;
virtual void calculate(const SystemList& pf_realSysList, const KQuery& query) override;

virtual SystemWeightList getSelected(Datetime date);
virtual SystemWeightList getSelected(Datetime date) override;
virtual SelectorPtr _clone() override;
virtual void _reset() override;

Expand Down
Loading