コード例 #1
0
ファイル: bollinger.py プロジェクト: hughdbrown/QSTK-nohist
def create(adjclose, timestamps, lookback, spread, high, low, bet, duration):
    alloc = DataMatrix(index=[timestamps[0]], columns=adjclose.columns, data=[zeros(len(adjclose.columns))])
    bs = boil.calcbvals(adjclose, timestamps, adjclose.columns, lookback)
    hold = []
    time = []
    for i in bs.index[1:]:
        for stock in range(0, len(bs.columns)):
            if(bs.xs(i)[stock] < low and len(hold) < spread):
                hold.append(stock)
                time.append(duration)
            elif(bs.xs(i)[stock] > high):
                if stock in hold:
                    del time[hold.index(stock)]
                    hold.remove(stock)
        for j in range(0, len(time)):
            time[j] -= 1
            if(time[j] <= 0):
                del hold[j]
                del time[j]

        vals = zeros(len(adjclose.columns))
        for j in range(0, len(hold)):
            vals[hold[j]] = bet
        alloc = alloc.append(DataMatrix(index=[i], columns=adjclose.columns, data=[vals]))
    return alloc
コード例 #2
0
def create(adjclose, timestamps, lookback, spread, high, low, bet, duration):
    alloc = DataMatrix(index=[timestamps[0]],
                       columns=adjclose.columns,
                       data=[zeros(len(adjclose.columns))])
    bs = boil.calcbvals(adjclose, timestamps, adjclose.columns, lookback)
    hold = []
    time = []
    for i in bs.index[1:]:
        for stock in range(0, len(bs.columns)):
            if (bs.xs(i)[stock] < low and len(hold) < spread):
                hold.append(stock)
                time.append(duration)
            elif (bs.xs(i)[stock] > high):
                if stock in hold:
                    del time[hold.index(stock)]
                    hold.remove(stock)
        for j in range(0, len(time)):
            time[j] -= 1
            if (time[j] <= 0):
                del hold[j]
                del time[j]

        vals = zeros(len(adjclose.columns))
        for j in range(0, len(hold)):
            vals[hold[j]] = bet
        alloc = alloc.append(
            DataMatrix(index=[i], columns=adjclose.columns, data=[vals]))
    return alloc
コード例 #3
0
ファイル: bollinger.py プロジェクト: hughdbrown/QSTK-nohist
def createStatefulStrat(adjclose, timestamps, lookback, highthresh, lowthresh):
    alloc = DataMatrix(index=[timestamps[0]], columns=adjclose.columns, data=[zeros(len(adjclose.columns))])
    bs = boil.calcbvals(adjclose, timestamps, adjclose.columns, lookback)
    hold = []
    for i in bs.index[1:]:
        for stock in range(0, len(bs.columns)):
            if(bs.xs(i)[stock] < lowthresh and len(hold) < 10):
                hold.append(stock)
            elif(bs.xs(i)[stock] > highthresh):
                if stock in hold:
                    hold.remove(stock)
        vals = zeros(len(adjclose.columns))
        for j in range(0, len(hold)):
            vals[hold[j]] = .1
        alloc = alloc.append(DataMatrix(index=[i], columns=adjclose.columns, data=[vals]))
    return alloc
コード例 #4
0
def createStatefulStrat(adjclose, timestamps, lookback, highthresh, lowthresh):
	alloc=DataMatrix(index=[timestamps[0]],columns=adjclose.columns, data=[zeros(len(adjclose.columns))])
	bs=boil.calcbvals(adjclose, timestamps, adjclose.columns, lookback)
	hold=[]
 	for i in bs.index[1:]:
		for stock in range(0,len(bs.columns)):
			if(bs.xs(i)[stock]<lowthresh and len(hold)<10):
				hold.append(stock)
			elif(bs.xs(i)[stock]>highthresh):
				if stock in hold:
					hold.remove(stock)
		vals=zeros(len(adjclose.columns))
		for j in range(0,len(hold)):
			vals[hold[j]]=.1
		alloc=alloc.append(DataMatrix(index=[i],columns=adjclose.columns,data=[vals]))
	return alloc