def exitPos(myExitPrice, myExitDate, tempName, myCurShares):
    global mp, commission
    global tradeName, entryPrice, entryQuant, exitPrice, numShares, myBPV, cumuProfit
    if mp < 0:
        trades = tradeInfo('liqShort', myExitDate, tempName, myExitPrice,
                           myCurShares, 0)
        profit = trades.calcTradeProfit('liqShort', mp, entryPrice,
                                        myExitPrice, entryQuant,
                                        myCurShares) * myBPV
        profit = profit - myCurShares * commission
        trades.tradeProfit = profit
        cumuProfit += profit
        trades.cumuProfit = cumuProfit
    if mp > 0:
        trades = tradeInfo('liqLong', myExitDate, tempName, myExitPrice,
                           myCurShares, 0)
        profit = trades.calcTradeProfit('liqLong', mp, entryPrice, myExitPrice,
                                        entryQuant, myCurShares) * myBPV
        profit = profit - myCurShares * commission
        trades.tradeProfit = profit
        cumuProfit += profit
        trades.cumuProfit = cumuProfit
    curShares = 0
    for remShares in range(0, len(entryQuant)):
        curShares += entryQuant[remShares]
    return (profit, trades, curShares)
Exemple #2
0
 def exitTrade(self):
     if self.mp < 0:
         trades = tradeInfo('liqShort', self.myExitDate, self.tempName,
                            self.myExitPrice, self.myCurShares, 0)
         profit = trades.calcTradeProfit(
             'liqShort', self.mp, self.entryPrice, self.myExitPrice,
             self.entryQuant, self.myCurShares) * self.myBPV
         profit = profit - myCurShares * commission
         trades.tradeProfit = profit
         cumuProfit += profit
         trades.cumuProfit = cumuProfit
     if self.mp > 0:
         trades = tradeInfo('liqLong', myExitDate, tempName, myExitPrice,
                            myCurShares, 0)
         profit = trades.calcTradeProfit('liqLong', mp, entryPrice,
                                         myExitPrice, entryQuant,
                                         myCurShares) * myBPV
         profit = profit - myCurShares * commission
         trades.tradeProfit = profit
         cumuProfit += profit
         trades.cumuProfit = cumuProfit
     curShares = 0
     for remShares in range(0, len(entryQuant)):
         curShares += entryQuant[remShares]
     return (profit, trades, curShares)
Exemple #3
0
def bookTrade(entryOrExit, lOrS, price, date, tradeName, shares):
    global mp, commission, totProfit, curShares, barsSinceEntry, listOfTrades
    global entryPrice, entryQuant, exitPrice, numShares, myBPV, cumuProfit
    if entryOrExit == -1:
        profit, trades, curShares = exitPos(price, date, tradeName, shares)
        listOfTrades.append(trades)
        mp = 0
    else:
        profit = 0
        curShares = curShares + shares
        barsSinceEntry = 1
        entryPrice.append(price)
        entryQuant.append(shares)
        if lOrS == 1:
            mp += 1
            marketPosition[i] = mp
            trades = tradeInfo('buy', date, tradeName, entryPrice[-1], shares,
                               1)
        if lOrS == -1:
            mp -= 1
            marketPosition[i] = mp
            trades = tradeInfo('sell', date, tradeName, entryPrice[-1], shares,
                               1)
        listOfTrades.append(trades)
    return (profit, curShares)
 def exitTrade(self):
     if self.mp < 0:
         trades = tradeInfo('liqShort',self.myExitDate,self.tempName,self.myExitPrice,self.myCurShares,0)
         profit = trades.calcTradeProfit('liqShort',self.mp,self.entryPrice,self.myExitPrice,self.entryQuant,self.myCurShares) * self.myBPV
         profit = profit - myCurShares *commission
         trades.tradeProfit = profit
         cumuProfit += profit
         trades.cumuProfit = cumuProfit
     if self.mp > 0:
         trades = tradeInfo('liqLong',myExitDate,tempName,myExitPrice,myCurShares,0)
         profit = trades.calcTradeProfit('liqLong',mp,entryPrice,myExitPrice,entryQuant,myCurShares) * myBPV
         profit = profit - myCurShares * commission 
         trades.tradeProfit = profit
         cumuProfit += profit
         trades.cumuProfit = cumuProfit
     curShares = 0
     for remShares in range(0,len(entryQuant)):
         curShares += entryQuant[remShares]
     return (profit,trades,curShares)
Exemple #5
0
def exitPos(myExitPrice,myExitDate,tempName,myCurShares):
    global mp,commission
    global tradeName,entryPrice,entryQuant,exitPrice,numShares,myBPV,cumuProfit
    if mp < 0:
        trades = tradeInfo('liqShort',myExitDate,tempName,myExitPrice,myCurShares,0)
        profit = trades.calcTradeProfit('liqShort',mp,entryPrice,myExitPrice,entryQuant,myCurShares) * myBPV
        profit = profit - myCurShares *commission
        trades.tradeProfit = profit
        cumuProfit += profit
        trades.cumuProfit = cumuProfit
    if mp > 0:
        trades = tradeInfo('liqLong',myExitDate,tempName,myExitPrice,myCurShares,0)
        profit = trades.calcTradeProfit('liqLong',mp,entryPrice,myExitPrice,entryQuant,myCurShares) * myBPV
        profit = profit - myCurShares * commission
        trades.tradeProfit = profit 
        cumuProfit += profit
        trades.cumuProfit = cumuProfit
    curShares = 0
    for remShares in range(0,len(entryQuant)):
       curShares += entryQuant[remShares]
    return (profit,trades,curShares)
            profit = 0
            price = myClose[i]
            if mp <= -1:
                profit, trades, curShares = exitPos(price, myDate[i],
                                                    "RevShrtLiq", curShares)
                listOfTrades.append(trades)
                mp = 0
                todaysCTE = profit
            tradeName = "TMA Buy"
            mp += 1
            marketPosition[i] = mp
            numShares = 1
            entryPrice.append(price)
            entryQuant.append(numShares)
            curShares = curShares + numShares
            trades = tradeInfo('buy', myDate[i], tradeName, entryPrice[-1],
                               numShares, 1)
            barsSinceEntry = 1
            totProfit += profit
            listOfTrades.append(trades)
#Long Exit - 1 Fixed Dollar Stop Loss
        if mp >= 1 and myClose[
                i] < entryPrice[-1] - stopAmt and barsSinceEntry > 1:
            price = myClose[i]
            tradeName = "L-MMLoss"
            exitDate = myDate[i]
            numShares = curShares
            exitQuant.append(numShares)
            profit, trades, curShares = exitPos(price, myDate[i], tradeName,
                                                numShares)
            if curShares == 0: mp = marketPosition[i] = 0
            totProfit += profit
Exemple #7
0
        if (mp != 1) and avg1 > avg2 and avg2 > avg3:
            profit = 0
            price = myClose[i]
            if mp <= -1:
                profit,trades,curShares = exitPos(price,myDate[i],"RevShrtLiq",curShares)
                listOfTrades.append(trades)
                mp = 0
                todaysCTE = profit
            tradeName = "TMA Buy"
            mp += 1
            marketPosition[i] = mp
            numShares = 1
            entryPrice.append(price)
            entryQuant.append(numShares)
            curShares = curShares + numShares
            trades = tradeInfo('buy',myDate[i],tradeName,entryPrice[-1],numShares,1)
            barsSinceEntry = 1
            totProfit += profit
            listOfTrades.append(trades)
 #Long Exit - 1 Fixed Dollar Stop Loss
        if mp >= 1 and myClose[i] < entryPrice[-1] - stopAmt and barsSinceEntry > 1:
            price = myClose[i]
            tradeName = "L-MMLoss"
            exitDate =myDate[i]
            numShares = curShares
            exitQuant.append(numShares)
            profit,trades,curShares = exitPos(price,myDate[i],tradeName,numShares)
            if curShares == 0 : mp = marketPosition[i] = 0
            totProfit += profit
            todaysCTE = profit
            listOfTrades.append(trades)
Exemple #8
0
             curShares)
         smtl[j].tradesList.append(trades)
         mp = 0
         todaysCTE = profit
         totProfit += profit
     tradeName = "Test B"
     mp += 1
     numShares = 1
     curShares = curShares + numShares
     barsSinceEntry = 1
     smtl[j].setSysMarkTrackingInfo(price, numShares,
                                    tradeName, totProfit,
                                    mp, barsSinceEntry,
                                    curShares)
     trades = tradeInfo('buy', marketList[j].date[k],
                        tradeName, smtl[j].entryPrice[-1],
                        numShares, 1)
     smtl[j].tradesList.append(trades)
 if marketList[j].low[k] <= lowest(
         marketList[j].low, 40, k,
         1) and barsSinceEntry > 1 and mp != -1:
     price = min(marketList[j].open[k],
                 marketList[j].low[k - 1])
     if mp >= 1:
         profit, trades, curShares = exitPos(
             price, marketList[j].date[k], "RevLongLiq",
             curShares)
         smtl[j].tradesList.append(trades)
         mp = 0
         todaysCTE = profit
         totProfit += profit