|
6 | 6 | print('mpf.__version__ =',mpf.__version__) # for the record
|
7 | 7 | print("plt.rcParams['backend'] =",plt.rcParams['backend']) # for the record
|
8 | 8 |
|
9 |
| -import subprocess |
10 |
| -pwd = subprocess.run(['pwd'], stdout=subprocess.PIPE) |
11 |
| -print('pwd.stdout=',str(pwd.stdout).strip()) |
12 |
| - |
13 | 9 | prefix='addplot'
|
14 | 10 | tdir='tests/test_images/'
|
15 | 11 | refd='tests/reference_images/'
|
@@ -39,6 +35,78 @@ def test_addplot02(bolldata):
|
39 | 35 |
|
40 | 36 | os.system('ls -l '+tdir+fname)
|
41 | 37 |
|
| 38 | + result = compare_images(refd+fname,tdir+fname,tol=IMGCOMP_TOLERANCE) |
| 39 | + if result is not None: |
| 40 | + print('result=',result) |
| 41 | + |
| 42 | +def percentB_aboveone(percentB,price): |
| 43 | + import numpy as np |
| 44 | + signal = [] |
| 45 | + previous = 2 |
| 46 | + for date,value in percentB.iteritems(): |
| 47 | + if value > 1 and previous <= 1: |
| 48 | + signal.append(price[date]*1.01) |
| 49 | + else: |
| 50 | + signal.append(np.nan) |
| 51 | + previous = value |
| 52 | + return signal |
| 53 | + |
| 54 | +def percentB_belowzero(percentB,price): |
| 55 | + import numpy as np |
| 56 | + signal = [] |
| 57 | + previous = -1.0 |
| 58 | + for date,value in percentB.iteritems(): |
| 59 | + if value < 0 and previous >= 0: |
| 60 | + signal.append(price[date]*0.99) |
| 61 | + else: |
| 62 | + signal.append(np.nan) |
| 63 | + previous = value |
| 64 | + return signal |
| 65 | + |
| 66 | +def test_addplot03(bolldata): |
| 67 | + df = bolldata |
| 68 | + fname=prefix+'03.png' |
| 69 | + |
| 70 | + tcdf = df[['LowerB','UpperB']] # DataFrame with two columns |
| 71 | + |
| 72 | + low_signal = percentB_belowzero(df['PercentB'], df['Close']) |
| 73 | + high_signal = percentB_aboveone(df['PercentB'], df['Close']) |
| 74 | + |
| 75 | + apds = [ mpf.make_addplot(tcdf), |
| 76 | + mpf.make_addplot(low_signal,scatter=True,markersize=200,marker='^'), |
| 77 | + mpf.make_addplot(high_signal,scatter=True,markersize=200,marker='v'), |
| 78 | + mpf.make_addplot((df['PercentB']),panel='lower',color='g') |
| 79 | + ] |
| 80 | + |
| 81 | + mpf.plot(df,addplot=apds,figscale=1.3,volume=True,savefig=tdir+fname) |
| 82 | + |
| 83 | + os.system('ls -l '+tdir+fname) |
| 84 | + |
| 85 | + result = compare_images(refd+fname,tdir+fname,tol=IMGCOMP_TOLERANCE) |
| 86 | + if result is not None: |
| 87 | + print('result=',result) |
| 88 | + assert result is None |
| 89 | + |
| 90 | +def test_addplot04(bolldata): |
| 91 | + df = bolldata |
| 92 | + fname=prefix+'04.png' |
| 93 | + |
| 94 | + tcdf = df[['LowerB','UpperB']] # DataFrame with two columns |
| 95 | + |
| 96 | + low_signal = percentB_belowzero(df['PercentB'], df['Close']) |
| 97 | + high_signal = percentB_aboveone(df['PercentB'], df['Close']) |
| 98 | + |
| 99 | + apds = [ mpf.make_addplot(tcdf,linestyle='dashdot'), |
| 100 | + mpf.make_addplot(low_signal,scatter=True,markersize=200,marker='^'), |
| 101 | + mpf.make_addplot(high_signal,scatter=True,markersize=200,marker='v'), |
| 102 | + mpf.make_addplot((df['PercentB']),panel='lower',color='g',linestyle='dotted') |
| 103 | + ] |
| 104 | + |
| 105 | + mpf.plot(df,addplot=apds,figscale=1.5,volume=True, |
| 106 | + style='starsandstripes',savefig=tdir+fname) |
| 107 | + |
| 108 | + os.system('ls -l '+tdir+fname) |
| 109 | + |
42 | 110 | result = compare_images(refd+fname,tdir+fname,tol=IMGCOMP_TOLERANCE)
|
43 | 111 | if result is not None:
|
44 | 112 | print('result=',result)
|
|
0 commit comments