Esempio n. 1
0
  for stock in stockArray:
    if portfolio[stock] != 0:
        empty=False
        currentlyOwnedStock = stock
        stockQuantity=portfolio[stock]
    

  if empty:
    print "portfolio is empty, picking a stock to buy"
    #buy algorithm

    #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"
Esempio n. 2
0
    for stock in stockArray:
        if portfolio[stock] != 0:
            empty = False
            currentlyOwnedStock = stock
            stockQuantity = portfolio[stock]

    if empty:
        print "portfolio is empty, picking a stock to buy"
        #buy algorithm

        #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"
Esempio n. 3
0
    portfolio = robot.getPortfolio()

    if portfolio[ticker] != 0:

        # selling distribution:
        # 25 percent at market price
        # 10 percent at 10 percent above market price
        # 10 percent at 10 percent below market price
        # 5 percent at 5 percent below market price

        marketFraction = 0.25
        aboveMarket = 0.10
        tenBelowMarket = 0.10
        fiveBelowMarket = 0.05

        price = robot.getPrice(ticker)

        result = robot.ask((int)(portfolio[ticker] * marketFraction), 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"
        result = robot.ask((int)(portfolio[ticker] * aboveMarket), price * 1.10, ticker)
        if result == "Accepted":
            print "trade accepted"
        elif result == "Unsuccesful":
            print "trade declined"
Esempio n. 4
0
    portfolio = robot.getPortfolio()

    if (portfolio[ticker] != 0):

        #selling distribution:
        #25 percent at market price
        #10 percent at 10 percent above market price
        #10 percent at 10 percent below market price
        #5 percent at 5 percent below market price

        marketFraction = 0.25
        aboveMarket = 0.10
        tenBelowMarket = 0.10
        fiveBelowMarket = 0.05

        price = robot.getPrice(ticker)

        result = robot.ask((int)(portfolio[ticker] * marketFraction), 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"
        result = robot.ask((int)(portfolio[ticker] * aboveMarket),
                           price * 1.10, ticker)
        if result == 'Accepted':
            print "trade accepted"
Esempio n. 5
0
robot = TraderBot()

stockArray = robot.getSymbols()

print "Stock Array", stockArray

size = len(stockArray)

print "Array Size", size

randomStockIdx = random.randint(0, size - 1)
randomStock = stockArray[randomStockIdx]

print "random stock ticker:", randomStock

price = robot.getPrice(randomStock)

print "stock price:", price

money = robot.getFunds()

maxShares = 100

confirmation = robot.buy(randomStock, maxShares)

if (confirmation == 1):
    print "buy confirmed"
else:
    print "buy failed"
    
portfolio = robot.getPortfolio()
Esempio n. 6
0
robot = TraderBot()

stockArray = robot.getSymbols()

print "Stock Array", stockArray

size = len(stockArray)

print "Array Size", size

randomStockIdx = random.randint(0, size - 1)
randomStock = stockArray[randomStockIdx]

print "random stock ticker:", randomStock

price = robot.getPrice(randomStock)

print "stock price:", price

money = robot.getFunds()

maxShares = 100

confirmation = robot.buy(randomStock, maxShares)

if (confirmation == 1):
    print "buy confirmed"
else:
    print "buy failed"

portfolio = robot.getPortfolio()