Skip to content

Commit

Permalink
RELEASE 0.1.0
Browse files Browse the repository at this point in the history
- Cython implementation of some functions.
  • Loading branch information
nymath committed May 26, 2023
1 parent e368b47 commit 12af69a
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 1 deletion.
2 changes: 2 additions & 0 deletions quant/op/_func.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import numpy as np

22 changes: 22 additions & 0 deletions quant/op/_func.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# distutils: language = c

import numpy as np
cimport numpy as np
from libc.stdlib cimport malloc, free
from libc.string cimport memset

def SMA(np.ndarray[np.float64_t, ndim=1] input, int period):
cdef int input_size = input.shape[0]
cdef np.ndarray[np.float64_t, ndim=1] output = np.empty(input_size)
cdef double sum = 0.0
cdef int i

for i in range(input_size):
sum += input[i]
if i >= period:
sum -= input[i - period]
if i >= period - 1:
output[i - period + 1] = sum / period
return output


1 change: 0 additions & 1 deletion quant/op/algos.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
import pandas as pd
from pandas._libs.algos import rank_1d, rank_2d

1 change: 1 addition & 0 deletions quant/op/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from ..config import __OP_MODE__
from typing import overload
from .algos import rank_1d, rank_2d
import talib
# Arithmetic Operators


Expand Down
12 changes: 12 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
pandas~=2.0.0
numpy~=1.24.2
graphviz~=2.50.0
gplearn~=0.4.2
scikit-learn~=1.0.2
matplotlib~=3.5.2
python-dateutil~=2.8.2
tushare~=1.2.89
joblib~=1.1.0
scipy~=1.9.1
setuptools~=63.4.1
cython~=0.29.34
10 changes: 10 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from setuptools import setup
from Cython.Build import cythonize
import numpy

setup(
ext_modules=cythonize('quant/op/_func.pyx', build_dir='build'),
include_dirs=[numpy.get_include()]
)


4 changes: 4 additions & 0 deletions test/testfunc_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import quant.op._func as F
import numpy as np

print(F.SMA(np.array([1, 2, 3, 4, 5.]), 2))

0 comments on commit 12af69a

Please sign in to comment.