Giter Site home page Giter Site logo

ta_cn's People

Contributors

wukan1986 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ta_cn's Issues

COUNT 很慢

ta_cn 版本

测试环境

用 conda 创建虚拟环境

  • CentOS Linux release 7.9.2009 (Core)
  • conda 4.12.0
  • Python 3.10.6
  • Flask 2.2.2
  • gunicorn 20.1.0

测试数据

每支股票 340 条数据

测试策略

F1=COUNT(L==LLV(L,60),10)>=1;
XH=F1;

测试方式

遍历执行上面策略大概4000次(类比四千只股)

运行结果

使用 mytt 的 count 执行了 3.326728343963623s
使用 from ta_cn.tdx import COUNT 的 count 执行了 8.872456312179565s

alpha191中alpha036 公式错误

RANK(SUM(CORR(RANK(VOLUME), RANK(VWAP)), 6), 2)中corr没有Period, 以我的理解应该改为:
RANK(SUM(CORR(RANK(VOLUME), RANK(VWAP), 6), 2))

Alpha10公式有疑问

image
原先这个RANK是没有参数的,源码中传入5应该被忽略
原先研报中是否是
先取5日MAX,再取RANK
(RANK(TSMAX(((RET < 0) ? STD(RET, 20) : CLOSE)^2),5)))

Alpha143公式计算有问题

def alpha_143(CLOSE, **kwargs):
"""Alpha143 CLOSE>DELAY(CLOSE,1)?(CLOSE-DELAY(CLOSE,1))/DELAY(CLOSE,1)*SELF:SELF"""
t1 = DELAY(CLOSE, 1)
t2 = IF(CLOSE > t1, CLOSE / t1 - 1., 1.)
return CUMPROD(t2)

没有看到对于self(上一期结果)的处理

alpha83 报错

Traceback (most recent call last):
  File "/Users/xxx/code/futudata/main.py", line 46, in <module>
    ret = func(**kwargs)
  File "/Users/xxx/.conda/envs/futudata/lib/python3.10/site-packages/ta_cn/alphas/alpha191.py", line 622, in alpha_083
    t1 = COVIANCE(RANK(HIGH), RANK(VOLUME), 5)
  File "/Users/xxx/.conda/envs/futudata/lib/python3.10/site-packages/ta_cn/utils_long.py", line 88, in decorated
    s3 = s2.groupby(by=by, group_keys=False).apply(to_pd(dataframe_split(func)), **_kwargs)
  File "/Users/xxx/.conda/envs/futudata/lib/python3.10/site-packages/pandas/core/groupby/groupby.py", line 1423, in apply
    result = self._python_apply_general(f, self._selected_obj)
  File "/Users/xxx/.conda/envs/futudata/lib/python3.10/site-packages/pandas/core/groupby/groupby.py", line 1464, in _python_apply_general
    values, mutated = self.grouper.apply(f, data, self.axis)
  File "/Users/xxx/.conda/envs/futudata/lib/python3.10/site-packages/pandas/core/groupby/ops.py", line 761, in apply
    res = f(group)
  File "/Users/xxx/.conda/envs/futudata/lib/python3.10/site-packages/pandas/core/groupby/groupby.py", line 1397, in f
    return func(g, *args, **kwargs)
  File "/Users/xxx/.conda/envs/futudata/lib/python3.10/site-packages/ta_cn/utils.py", line 14, in decorated
    return np_to_pd(func(*args, **kwargs),
  File "/Users/xxx/.conda/envs/futudata/lib/python3.10/site-packages/ta_cn/utils_long.py", line 107, in decorated
    return func(*args_input, *args, **kwargs_input, **kwargs)
  File "/Users/xxx/.conda/envs/futudata/lib/python3.10/site-packages/ta_cn/statistics.py", line 79, in COVAR
    return numpy_rolling_apply([pd_to_np(real0), pd_to_np(real1)],
  File "/Users/xxx/.conda/envs/futudata/lib/python3.10/site-packages/ta_cn/nb.py", line 289, in numpy_rolling_apply
    return func1(*arrs, out, window, func2, *args)
  File "/Users/xxx/.conda/envs/futudata/lib/python3.10/site-packages/numba/core/dispatcher.py", line 468, in _compile_for_args
    error_rewrite(e, 'typing')
  File "/Users/xxx/.conda/envs/futudata/lib/python3.10/site-packages/numba/core/dispatcher.py", line 409, in error_rewrite
    raise e.with_traceback(None)
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(<function cov at 0x10408ecb0>) found for signature:
 
 >>> cov(readonly array(float64, 1d, A), readonly array(float64, 1d, A))
 
There are 2 candidate implementations:
  - Of which 2 did not match due to:
  Overload in function 'np_cov': File: numba/np/arraymath.py: Line 2888.
    With argument(s): '(readonly array(float64, 1d, A), readonly array(float64, 1d, A))':
   Rejected as the implementation raised a specific error:
     TypingError: Failed in nopython mode pipeline (step: nopython frontend)
   No implementation of function Function(<function np_cov_impl_inner at 0x148201240>) found for signature:
    
    >>> np_cov_impl_inner(array(float64, 2d, C), Literal[bool](False), none)
    
   There are 2 candidate implementations:
         - Of which 2 did not match due to:
         Overload in function 'register_jitable.<locals>.wrap.<locals>.ov_wrap': File: numba/core/extending.py: Line 159.
           With argument(s): '(array(float64, 2d, C), bool, none)':
          Rejected as the implementation raised a specific error:
            TypingError: Failed in nopython mode pipeline (step: nopython frontend)
          No implementation of function Function(<function dot at 0x103259870>) found for signature:
           
           >>> dot(array(float64, 2d, C), array(float64, 2d, F))
           
          There are 4 candidate implementations:
                - Of which 4 did not match due to:
                Overload in function '_OverloadWrapper._build.<locals>.ol_generated': File: numba/core/overload_glue.py: Line 131.
                  With argument(s): '(array(float64, 2d, C), array(float64, 2d, F))':
                 Rejected as the implementation raised a specific error:
                   LoweringError: Failed in nopython mode pipeline (step: native lowering)
                 scipy 0.16+ is required for linear algebra
                 
                 File "<string>", line 3:
                 <source missing, REPL/exec in use?>
                 
                 During: lowering "$8call_function.3 = call $2load_global.0(tmp0, tmp1, func=$2load_global.0, args=[Var(tmp0, <string>:3), Var(tmp1, <string>:3)], kws=(), vararg=None, target=None)" at <string> (3)
            raised from /Users/xxx/.conda/envs/futudata/lib/python3.10/site-packages/numba/core/errors.py:837
          
          During: resolving callee type: Function(<function dot at 0x103259870>)
          During: typing of call at /Users/xxx/.conda/envs/futudata/lib/python3.10/site-packages/numba/np/arraymath.py (2739)
          
          
          File "../../.conda/envs/futudata/lib/python3.10/site-packages/numba/np/arraymath.py", line 2739:
          def np_cov_impl_inner(X, bias, ddof):
              <source elided>
              # calculate result - requires blas
              c = np.dot(X, np.conj(X.T))
              ^
   
     raised from /Users/xxx/.conda/envs/futudata/lib/python3.10/site-packages/numba/core/typeinfer.py:1086
   
   During: resolving callee type: Function(<function np_cov_impl_inner at 0x148201240>)
   During: typing of call at /Users/xxx/.conda/envs/futudata/lib/python3.10/site-packages/numba/np/arraymath.py (2927)
   
   
   File "../../.conda/envs/futudata/lib/python3.10/site-packages/numba/np/arraymath.py", line 2927:
       def np_cov_impl(m, y=None, rowvar=True, bias=False, ddof=None):
           <source elided>
           else:
               return np_cov_impl_inner(X, bias, ddof)
               ^

  raised from /Users/xxx/.conda/envs/futudata/lib/python3.10/site-packages/numba/core/typeinfer.py:1086

During: resolving callee type: Function(<function cov at 0x10408ecb0>)
During: typing of call at /Users/xxx/.conda/envs/futudata/lib/python3.10/site-packages/ta_cn/nb.py (207)


File "../../.conda/envs/futudata/lib/python3.10/site-packages/ta_cn/nb.py", line 207:
def _cov_nb(arr0, arr1):
    <source elided>
    """协方差矩阵"""
    return _np.cov(arr0, arr1)[0, 1]
    ^

During: resolving callee type: type(CPUDispatcher(<function _cov_nb at 0x13709edd0>))
During: typing of call at /Users/xxx/.conda/envs/futudata/lib/python3.10/site-packages/ta_cn/nb.py (239)

During: resolving callee type: type(CPUDispatcher(<function _cov_nb at 0x13709edd0>))
During: typing of call at /Users/xxx/.conda/envs/futudata/lib/python3.10/site-packages/ta_cn/nb.py (239)


File "../../.conda/envs/futudata/lib/python3.10/site-packages/ta_cn/nb.py", line 239:
def _rolling_func_2_nb(arr0, arr1, out, timeperiod, func, *args):
    <source elided>
        for i, (a, b) in enumerate(zip(arr0, arr1)):
            out[i + timeperiod - 1] = func(a, b, *args)
            ^

python3 跑 alpha075 报错

Traceback (most recent call last):
  File "/Users/xxx/code/futudata/main.py", line 57, in <module>
    ret = l.alpha_075(**kwargs_l)
  File "/Users/xxx/.conda/envs/futudata/lib/python3.10/site-packages/ta_cn/alphas/test191.py", line 505, in alpha_075
    return COUNT((CLOSE > OPEN) & (BANCHMARKINDEXCLOSE < BANCHMARKINDEXOPEN), 50) / COUNT(
  File "/Users/xxx/.conda/envs/futudata/lib/python3.10/site-packages/pandas/core/ops/common.py", line 70, in new_method
    return method(self, other)
  File "/Users/xxx/.conda/envs/futudata/lib/python3.10/site-packages/pandas/core/arraylike.py", line 124, in __truediv__
    return self._arith_method(other, operator.truediv)
  File "/Users/xxx/.conda/envs/futudata/lib/python3.10/site-packages/pandas/core/series.py", line 5639, in _arith_method
    return base.IndexOpsMixin._arith_method(self, other, op)
  File "/Users/xxx/.conda/envs/futudata/lib/python3.10/site-packages/pandas/core/base.py", line 1295, in _arith_method
    result = ops.arithmetic_op(lvalues, rvalues, op)
  File "/Users/xxx/.conda/envs/futudata/lib/python3.10/site-packages/pandas/core/ops/array_ops.py", line 220, in arithmetic_op
    _bool_arith_check(op, left, right)
  File "/Users/xxx/.conda/envs/futudata/lib/python3.10/site-packages/pandas/core/ops/array_ops.py", line 520, in _bool_arith_check
    raise NotImplementedError(
NotImplementedError: operator 'truediv' not implemented for bool dtypes

单只股票的alpha191没办法求

image
image

报一下错误
File "D:\06_projects\python\stock_trade\alphas191.py", line 62, in <module> alpha_001 = l.alpha_001(OPEN=OPEN, CLOSE=CLOSE, VOLUME=VOLUME) File "D:\ProgramData\Anaconda3\envs\py38\lib\site-packages\ta_cn\alphas\alpha191.py", line 14, in alpha_001 return (-1 * CORR(RANK(DELTA(LOG(VOLUME), 1)), RANK(((CLOSE - OPEN) / OPEN)), 6)) File "D:\ProgramData\Anaconda3\envs\py38\lib\site-packages\ta_cn\utils_long.py", line 112, in decorated return pd.Series(s3, index=s1.index) File "D:\ProgramData\Anaconda3\envs\py38\lib\site-packages\pandas\core\series.py", line 386, in __init__ if is_empty_data(data) and dtype is None: File "D:\ProgramData\Anaconda3\envs\py38\lib\site-packages\pandas\core\construction.py", line 877, in is_empty_data is_simple_empty = is_list_like_without_dtype and not data File "D:\ProgramData\Anaconda3\envs\py38\lib\site-packages\pandas\core\generic.py", line 1527, in __nonzero__ raise ValueError( ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
image

而且,dataframe的索引还必须设置asset,不然报错,这是什么原因?难道不能单独求值?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.