#picks random stock tickerNumber = random.randint(0, len(stockArray) -1) ticker = stockArray[tickerNumber] print "decided to buy stock with ticker :", ticker startingPrice = robot.getPrice(ticker) print "price of stock: $", startingPrice, "per share" #determines how much money it's willing to wager at once money = robot.getFunds() maxMoney = money*riskFactor*riskFactorMultiplier print "bot is willing to risk $" , maxMoney shares = (int)(maxMoney/startingPrice) print "purchasing", shares, "shares at $" , startingPrice, "per share" #ourchases stock result = robot.bid(shares, startingPrice, ticker) if result == 'Accepted': print "trade accepted" elif result == 'Unsuccesful': print "trade declined" elif result == 'Pending': print "trade pending" else: print "not a recognizable order state" if not empty: #sell algorithm currentPrice = robot.getPrice(currentlyOwnedStock) priceDifference = (currentPrice - startingPrice)/startingPrice print "percentage difference between purchasing price and current price: ", priceDifference
#picks random stock tickerNumber = random.randint(0, len(stockArray) - 1) ticker = stockArray[tickerNumber] print "decided to buy stock with ticker :", ticker startingPrice = robot.getPrice(ticker) print "price of stock: $", startingPrice, "per share" #determines how much money it's willing to wager at once money = robot.getFunds() maxMoney = money * riskFactor * riskFactorMultiplier print "bot is willing to risk $", maxMoney shares = (int)(maxMoney / startingPrice) print "purchasing", shares, "shares at $", startingPrice, "per share" #ourchases stock result = robot.bid(shares, startingPrice, ticker) if result == 'Accepted': print "trade accepted" elif result == 'Unsuccesful': print "trade declined" elif result == 'Pending': print "trade pending" else: print "not a recognizable order state" if not empty: #sell algorithm currentPrice = robot.getPrice(currentlyOwnedStock) priceDifference = (currentPrice - startingPrice) / startingPrice print "percentage difference between purchasing price and current price: ", priceDifference
for ticker in stockArray: portfolio = robot.getPortfolio() if (portfolio[ticker] != 0): trueValue = robot.getTrueValue(ticker) price = robot.getPrice(ticker) increment = abs(trueValue - price) / 3 #bid for 10 percent of the total stock @ market value #bid for 4 percent of total stock @ below market value #bid for 3 percent of total stock @ above market value #bid for 2 percent of total stock @ significantly above market value #bid for 1 percent of total stock @ true value if trueValue / price > 1.05: stockToBuy = 0.2 * robot.getSellVolume(ticker) robot.bid((int)(stockToBuy / 2), price, ticker) stockToBuy /= 2 robot.bid((int)(stockToBuy * 0.4), price - increment, ticker) robot.bid((int)(stockToBuy * 0.3), price + increment, ticker) robot.bid((int)(stockToBuy * 0.2), price + 2 * increment, ticker) robot.bid((int)(stockToBuy * 0.1), price + 3 * increment, ticker) #ask for 10 percent of the total stock @ market value #ask for 4 percent of total stock @ above market value #ask for 3 percent of total stock @ below market value #ask for 2 percent of total stock @ significantly below market value #ask for 1 percent of total stock @ true value if trueValue / price < 0.95: stockToSell = 0.3 * portfolio[ticker]
for ticker in stockArray: portfolio = robot.getPortfolio() if portfolio[ticker] != 0: trueValue = robot.getTrueValue(ticker) price = robot.getPrice(ticker) increment = abs(trueValue - price) / 3 # bid for 10 percent of the total stock @ market value # bid for 4 percent of total stock @ below market value # bid for 3 percent of total stock @ above market value # bid for 2 percent of total stock @ significantly above market value # bid for 1 percent of total stock @ true value if trueValue / price > 1.05: stockToBuy = 0.2 * robot.getSellVolume(ticker) robot.bid((int)(stockToBuy / 2), price, ticker) stockToBuy /= 2 robot.bid((int)(stockToBuy * 0.4), price - increment, ticker) robot.bid((int)(stockToBuy * 0.3), price + increment, ticker) robot.bid((int)(stockToBuy * 0.2), price + 2 * increment, ticker) robot.bid((int)(stockToBuy * 0.1), price + 3 * increment, ticker) # ask for 10 percent of the total stock @ market value # ask for 4 percent of total stock @ above market value # ask for 3 percent of total stock @ below market value # ask for 2 percent of total stock @ significantly below market value # ask for 1 percent of total stock @ true value if trueValue / price < 0.95: stockToSell = 0.3 * portfolio[ticker] robot.ask((int)(stockToSell / 2), price, ticker) stockToSell /= 2
ticker = random.randint(0, len(portfolio) -1) print "decided to buy stock with ticker :", ticker startingPrice = robot.getPrice(ticker) print "price of stock: $", startingPrice, "per share" #determines how much money it's willing to wager at once money = robot.getFunds() maxMoney = money*riskFactor*riskFactorMultiplier if maxMoney > money: maxMoney = money print "bot is willing to risk $" , maxMoney shares = (int)(maxMoney/startingPrice) print "purchasing", shares, "shares at $" , startingPrice, "per share" #ourchases stock result = robot.bid(robot.accountID, shares, price, ticker) if result == 'Accepted': print "trade accepted" elif result == 'Unsuccesful': print "trade declined" elif result == 'Pending': print "trade pending" else: print "not a recognizable order state" if not empty: #sell algorithm currentPrice = robot.getPrice(currentlyOwnedStock) priceDifference = (currentPrice - startingPrice)/startingPrice print "percentage difference between purchasing price and current price: ", priceDifference