Skip to content

Commit

Permalink
Merge pull request #1351 from yutiansut/master
Browse files Browse the repository at this point in the history
add renko/  set QA_fetch_get_stock_day default to '00' 不复权
  • Loading branch information
yutiansut authored Nov 16, 2019
2 parents f5eacae + 8f57b5b commit cace4b8
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 3 deletions.
1 change: 0 additions & 1 deletion QUANTAXIS/QAData/QADataStruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
from QUANTAXIS.QAUtil.QADate import QA_util_to_datetime
from QUANTAXIS.QAUtil.QAParameter import FREQUENCE, MARKET_TYPE


class QA_DataStruct_Stock_day(_quotation_base):
'''
Expand Down
2 changes: 1 addition & 1 deletion QUANTAXIS/QAFetch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def use(package):
return QAWEB


def QA_fetch_get_stock_day(package, code, start, end, if_fq='01', level='day', type_='pd'):
def QA_fetch_get_stock_day(package, code, start, end, if_fq='00', level='day', type_='pd'):
Engine = use(package)
if package in ['ths', 'THS', 'wind']:
return Engine.QA_fetch_get_stock_day(code, start, end, if_fq)
Expand Down
42 changes: 42 additions & 0 deletions QUANTAXIS/QAIndicator/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,45 @@ def BARLAST(cond, yes=True):

def XARROUND(x, y): return np.round(
y*(round(x/y-math.floor(x/y)+0.00000000001) + math.floor(x/y)), 2)


def RENKO(Series, N, condensed=True):

last_price = Series[0]
chart = [last_price]
for price in Series:
bricks = math.floor(abs(price-last_price)/N)
if bricks == 0:
if condensed:
chart.append(chart[-1])
continue
sign = int(np.sign(price-last_price))
chart += [sign*(last_price+(sign*N*x)) for x in range(1, bricks+1)]
last_price = abs(chart[-1])

return pd.Series(chart)



def RENKOP(Series, N, condensed=True):
last_price = Series[0]
chart = [last_price]
for price in Series:
inc = (price-last_price)/last_price
#print(inc)
if abs(inc) < N:
# if condensed:
# chart.append(chart[-1])
continue

sign = int(np.sign(price-last_price))
bricks = math.floor(inc/N)
#print(bricks)
#print((N * (price-last_price)) / inc)
step = math.floor((N * (price-last_price)) / inc)
print(step)
#print(sign)
chart += [sign*(last_price+(sign*step*x))
for x in range(1, abs(bricks)+1)]
last_price = abs(chart[-1])
return pd.Series(chart)
2 changes: 1 addition & 1 deletion QUANTAXIS/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
2017/4/8
"""

__version__ = '1.6.9'
__version__ = '1.6.10'
__author__ = 'yutiansut'

import argparse
Expand Down
44 changes: 44 additions & 0 deletions QUANTAXIS_Test/test_plotRenko.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import datetime
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates

from matplotlib.patches import Rectangle

import QUANTAXIS as QA


def plot_renko(ax, bricks):

ymax = max(bricks)
ymin = min(np.absolute(bricks))
width = 1.0 / len(bricks)
prev_height = 0
for index, brick in enumerate(bricks):
facecolor = 'red' if brick > 0 else 'green'
ypos = (abs(brick) - ymin) / (ymax - ymin)
if index == len(bricks)-1:
pass
elif bricks[index] == bricks[index+1]:
height = prev_height
else:
aux1 = (abs(bricks[index+1]) - ymin) / (ymax - ymin)
height = abs(aux1 - ypos)
prev_height = height
rect = Rectangle((index * width, ypos), width, height,
facecolor=facecolor, alpha=0.5)
ax.add_patch(rect)
pass


if __name__ == "__main__":
data = QA.QA_fetch_stock_day_adv('000001', '2019-01-01', '2019-11-01')
bricks_fixed = QA.RENKOP(data.close, N=0.05).tolist()

print(bricks_fixed)
fig = plt.figure()
ax = fig.add_subplot(111)
plot_renko(ax, bricks_fixed)
plt.title('RENKO {}'.format('600010'))
plt.show()

0 comments on commit cace4b8

Please sign in to comment.