HST-PF
mail:pf@hst.tw
投資
投機
投資
投機
時間
分析
風險
投資
投機
時間
分析
風險
降息啦!!
投資
投機
時間
分析
風險
投資
時間
分析
風險
投機
時間
分析
風險
投機
投資
時間
分析
風險
投機
投資
股票與期貨
政府
散戶
大戶
散戶
散戶
散戶
MA
=
P1 + P2 +...+ Pn
n
+ ....
Px :第x天的價格
n :n日
def getMA(ori, n):
MA = []
MA.append(sum([ori[i] for i in range(n)]))
for i in range(1, len(ori)-n):
MA.append(MA[-1] - ori[i-1] + ori[i+n])
for i in range(len(ori)):
MA[i] /= n
return MA
買進
賣出
不動
買進
賣出
不動
0
-1
1
def judge(ori, MA):
state = []
for i in range(len(ori)):
if ori[i] > MA[i]:
state.append(-1)
elif ori[i] < MA[i]:
state.append(1)
else:
state.append(0)
return state
def calculateEarning(ori, state):
earning = 0
price = 0
if state[0] != 0:
price = ori[0]
for i in range(1, len(ori)):
if state[i-1] != state[i]:
if state[i-1] == 1:
earning += ori[i] - price
elif state[i-1] == -1:
earning -= ori[i] - proce
price = ori[i]
return earning
RSV
=
Cn - Ln
Hn - Ln
:自定義參數
x
100%
Kn
=
⍺
.
RSVn
+
(1 -
⍺
)
.
Kn-1
Dn
=
⍺
.
Kn
+
(1 -
⍺
)
.
Dn-1
⍺
Cn:第n日收盤價
Hn:n日內最高價
Ln:n日內最低價
def RSV(ori, i, n):
ln = min(ori[i-n:i])
hn = max(ori[i-n:i])
return ( ori[i] - ln ) / ( hn - ln )
def K(i):
return alpha * rsv + (1-alpha) * K(i-1)
def D(i):
return alpha * K(i) + (1-alpha) * D(i-1)
def judge(K, D):
state = []
for i in range(len(K))
if K[i] > D[i]:
state.append(1)
elif K[i] < D[i]:
state.append(-1)
else:
state.append(0)
return state
代入參數
判斷多空
計算利潤
import itertools as it
it.cycle([1,2,3]) -> 1,2,3,1,2,3,1....
it.product([1,2,3], repeat=2)
-> (1, 1), (1, 2), (1, 3), (2, 1),
(2, 2), (2, 3), (3, 1), (3, 2), (3, 3)
it.permutations([1,2,3], 2)
-> (1, 2), (1, 3), (2, 1), (2, 3), (3, 1), (3, 2)
it.combinations([1,2,3], 2)
-> (1, 2), (1, 3), (2, 3)
it.combinations_with_replacement([1,2,3], 2)
-> (1, 1), (1, 2), (1, 3), (2, 2), (2, 3), (3, 3)
2-365日線 * 超過點數(0-200) * 3000隻股票
2-365日線 * 2-365日線 * 3000隻股票
3000隻股票 * 3000隻股票 * 3000隻股票
.........
不過天無絕人之路
import numpy as np
import random, time
future1 = []
future2 = []
for i in range(10000):
future1.append(random.randint(1,10000))
future2.append(random.randint(1,10000))
np_future1 = np.array(future1, dtype=int)
np_future2 = np.array(future2, dtype=int)
s1 = time.time()
for i in range(10000):
a = future1[i] - future2[i]
e1 = time.time()
print 'Python : %.10fs' % (e1 - s1)
s2 = time.time()
b = np_future1 - np_future2
e2 = time.time()
print 'Numpy : %.10fs' % (e2 - s2)
Python : 0.0021190643s
Numpy : 0.0000231266s
import numpy as np
a = np.array(list, dtype=[bool, int, float])
b = np.arange(num)
c = np.zeros(num)
d = np.ones(num)
a = np.array([1,2,3,4,5], dtype=int)
a + 2 = [3,4,5,6,7]
a - 2 = [-1,0,1,2,3]
a * 2 = [2,4,6,8,10]
a / 2 = [0,1,1,2,2]
a = np.array([1,2,3,4,5], dtype=int)
b = np.array([6,7,8,9,10], dtype=int)
a + b = [7,9,11,13,15]
a - b = [-5,-5,-5,-5,-5]
a * b = [6,14,24,36,50]
a / b = [0,0,0,0,0]
a = np.array([1,2,3,4,5], dtype=int)
a[1:3] = [2,3]
a[a>3] = [4,5]
b = np.where(a>3) = [3,4]
np.take(a, b) = [4,5]
np.piecewise(a, [a<=2, a>=3], [-1,1]) = [-1,-1,1,1,1]
np.max(a) = 5
np.min(a) = 1
futures = np.array(fututres_list, dtype=int)
weight = np.ones(num) / num
MA = np.convolve(weight, futures)[num-1:-num+1]
state = MA1 - MA2
state = np.piecewise(state, [state<0, state>0], [-1,1])
judge(ori, state)
Core
用
import multiprocess as mul
queue = mul.Queue()
pool = mul.Pool(process=cpu_num)
while not queue.empty():
args = queue.get()
results.append(pool.apply_async(testArgs, (args1, args2...)))
pool.close()
pool.join()
PyCuda!!
import pycuda.autoinit
import pycuda.driver as drv
import numpy
from pycuda.compiler import SourceModule
mod = SourceModule("""
__global__ void multiply_them(float *dest, float *a, float *b)
{
const int i = threadIdx.x;
dest[i] = a[i] * b[i];
}
""")
multiply_them = mod.get_function("multiply_them")
a = numpy.random.randn(400).astype(numpy.float32)
b = numpy.random.randn(400).astype(numpy.float32)
dest = numpy.zeros_like(a)
multiply_them(
drv.Out(dest), drv.In(a), drv.In(b),
block=(400,1,1), grid=(1,1))
print dest-a*b
七非特說過:沒有量的股票就是壁紙
Sqlite
Flask
Amcharts.js
jQuery
mail:pf@hst.tw
如果有問題請洽以下mail