|
1 | 1 | import random
|
2 | 2 | #I'll need to change this to incorporate
|
3 |
| -from traderbot import traderbot |
| 3 | +from traderbot import TraderBot |
4 | 4 |
|
5 | 5 | robot = TraderBot()
|
6 | 6 |
|
7 | 7 | stockArray = robot.getSymbols()
|
8 | 8 |
|
9 | 9 | #initial loop
|
10 |
| -for ticker in stockArray |
11 |
| - portfolio = robot.getPortfolio() |
| 10 | +for ticker in stockArray: |
| 11 | + portfolio = robot.getPortfolio() |
12 | 12 |
|
13 |
| - if (portfolio[ticker] != 0) |
| 13 | + if (portfolio[ticker] != 0): |
14 | 14 |
|
15 |
| - #selling distribution: |
16 |
| - #25 percent at market price |
17 |
| - #10 percent at 10 percent above market price |
18 |
| - #10 percent at 10 percent below market price |
19 |
| - #5 percent at 5 percent below market price |
| 15 | + #selling distribution: |
| 16 | + #25 percent at market price |
| 17 | + #10 percent at 10 percent above market price |
| 18 | + #10 percent at 10 percent below market price |
| 19 | + #5 percent at 5 percent below market price |
20 | 20 |
|
21 |
| - marketFraction = 0.25 |
22 |
| - aboveMarket = 0.10 |
23 |
| - tenBelowMarket = 0.10 |
24 |
| - fiveBelowMarket = 0.05 |
25 |
| - |
26 |
| - price = robot.getPrice(ticker) |
| 21 | + marketFraction = 0.25 |
| 22 | + aboveMarket = 0.10 |
| 23 | + tenBelowMarket = 0.10 |
| 24 | + fiveBelowMarket = 0.05 |
| 25 | + |
| 26 | + price = robot.getPrice(ticker) |
27 | 27 |
|
28 |
| - result = robot.ask((int)portfolio[ticker] *marketFraction , price, ticker) |
29 |
| - if result == 'Accepted': |
30 |
| - print "trade accepted" |
31 |
| - elif result == 'Unsuccesful': |
32 |
| - print "trade declined" |
33 |
| - elif result == 'Pending': |
34 |
| - print "trade pending" |
35 |
| - else: |
36 |
| - print "not a recognizable order state" |
37 |
| - result = robot.ask((int)portfolio[ticker]*aboveMarket, price*1.10, ticker) |
38 |
| - if result == 'Accepted': |
39 |
| - print "trade accepted" |
40 |
| - elif result == 'Unsuccesful': |
41 |
| - print "trade declined" |
42 |
| - elif result == 'Pending': |
43 |
| - print "trade pending" |
44 |
| - else: |
45 |
| - print "not a recognizable order state" |
46 |
| - result = robot.ask((int)portfolio[ticker]*tenBelowMarket, price*0.9, ticker) |
47 |
| - if result == 'Accepted': |
48 |
| - print "trade accepted" |
49 |
| - elif result == 'Unsuccesful': |
50 |
| - print "trade declined" |
51 |
| - elif result == 'Pending': |
52 |
| - print "trade pending" |
53 |
| - else: |
54 |
| - print "not a recognizable order state" |
55 |
| - result = robot.ask((int)portfolio[ticker]*fiveBelowMarket, price*0.95, ticker) |
56 |
| - if result == 'Accepted': |
57 |
| - print "trade accepted" |
58 |
| - elif result == 'Unsuccesful': |
59 |
| - print "trade declined" |
60 |
| - elif result == 'Pending': |
61 |
| - print "trade pending" |
62 |
| - else: |
63 |
| - print "not a recognizable order state" |
| 28 | + result = robot.ask((int)(portfolio[ticker] *marketFraction) , price, ticker) |
| 29 | + if result == 'Accepted': |
| 30 | + print "trade accepted" |
| 31 | + elif result == 'Unsuccesful': |
| 32 | + print "trade declined" |
| 33 | + elif result == 'Pending': |
| 34 | + print "trade pending" |
| 35 | + else: |
| 36 | + print "not a recognizable order state" |
| 37 | + result = robot.ask((int)(portfolio[ticker]*aboveMarket), price*1.10, ticker) |
| 38 | + if result == 'Accepted': |
| 39 | + print "trade accepted" |
| 40 | + elif result == 'Unsuccesful': |
| 41 | + print "trade declined" |
| 42 | + elif result == 'Pending': |
| 43 | + print "trade pending" |
| 44 | + else: |
| 45 | + print "not a recognizable order state" |
| 46 | + result = robot.ask((int)(portfolio[ticker]*tenBelowMarket), price*0.9, ticker) |
| 47 | + if result == 'Accepted': |
| 48 | + print "trade accepted" |
| 49 | + elif result == 'Unsuccesful': |
| 50 | + print "trade declined" |
| 51 | + elif result == 'Pending': |
| 52 | + print "trade pending" |
| 53 | + else: |
| 54 | + print "not a recognizable order state" |
| 55 | + result = robot.ask((int)(portfolio[ticker]*fiveBelowMarket), price*0.95, ticker) |
| 56 | + if result == 'Accepted': |
| 57 | + print "trade accepted" |
| 58 | + elif result == 'Unsuccesful': |
| 59 | + print "trade declined" |
| 60 | + elif result == 'Pending': |
| 61 | + print "trade pending" |
| 62 | + else: |
| 63 | + print "not a recognizable order state" |
64 | 64 |
|
65 | 65 |
|
66 | 66 | while True:
|
67 | 67 |
|
68 |
| - for ticker in stockArray: |
69 |
| - portfolio = robot.getPortfolio() |
70 |
| - if (portfolio[ticker] != 0): |
71 |
| - trueValue = robot.getTrueValue(ticker) |
72 |
| - price = robot.getPrice(ticker) |
73 |
| - increment = abs(trueValue - price)/3 |
| 68 | + for ticker in stockArray: |
| 69 | + portfolio = robot.getPortfolio() |
| 70 | + if (portfolio[ticker] != 0): |
| 71 | + trueValue = robot.getTrueValue(ticker) |
| 72 | + price = robot.getPrice(ticker) |
| 73 | + increment = abs(trueValue - price)/3 |
74 | 74 |
|
75 |
| - #bid for 10 percent of the total stock @ market value |
76 |
| - #bid for 4 percent of total stock @ below market value |
77 |
| - #bid for 3 percent of total stock @ above market value |
78 |
| - #bid for 2 percent of total stock @ significantly above market value |
79 |
| - #bid for 1 percent of total stock @ true value |
80 |
| - if trueValue/price >1.05: |
81 |
| - stockToBuy = 0.2 * robot.getVolume(ticker) |
82 |
| - robot.bid((int)stockToBuy/2, price, ticker) |
83 |
| - stockToBuy/= 2 |
84 |
| - robot.bid((int)stockToBuy*0.4, price - increment, ticker) |
85 |
| - robot.bid((int)stockToBuy*0.3, price + increment, ticker) |
86 |
| - robot.bid((int)stockToBuy*0.2, price + 2 * increment, ticker) |
87 |
| - robot.bid((int)stockToBuy*0.1, price + 3 * increment, ticker) |
| 75 | + #bid for 10 percent of the total stock @ market value |
| 76 | + #bid for 4 percent of total stock @ below market value |
| 77 | + #bid for 3 percent of total stock @ above market value |
| 78 | + #bid for 2 percent of total stock @ significantly above market value |
| 79 | + #bid for 1 percent of total stock @ true value |
| 80 | + if trueValue/price >1.05: |
| 81 | + stockToBuy = 0.2 * robot.getVolume(ticker) |
| 82 | + robot.bid((int)(stockToBuy/2), price, ticker) |
| 83 | + stockToBuy/= 2 |
| 84 | + robot.bid((int)(stockToBuy*0.4), price - increment, ticker) |
| 85 | + robot.bid((int)(stockToBuy*0.3), price + increment, ticker) |
| 86 | + robot.bid((int)(stockToBuy*0.2), price + 2 * increment, ticker) |
| 87 | + robot.bid((int)(stockToBuy*0.1), price + 3 * increment, ticker) |
88 | 88 |
|
89 |
| - #ask for 10 percent of the total stock @ market value |
90 |
| - #ask for 4 percent of total stock @ above market value |
91 |
| - #ask for 3 percent of total stock @ below market value |
92 |
| - #ask for 2 percent of total stock @ significantly below market value |
93 |
| - #ask for 1 percent of total stock @ true value |
94 |
| - if trueValue/price < 0.95: |
95 |
| - stockToSell = 0.3 * portfolio[ticker] |
96 |
| - robot.ask((int)stockToSell/2, price, ticker) |
97 |
| - stockToBuy/= 2 |
98 |
| - robot.ask((int)stockToSell*0.4, price + increment, ticker) |
99 |
| - robot.ask((int)stockToSell*0.3, price - increment, ticker) |
100 |
| - robot.ask((int)stockToSell*0.2, price - 2 * increment, ticker) |
101 |
| - robot.ask((int)stockToSell*0.1, price - 3 * increment, ticker) |
| 89 | + #ask for 10 percent of the total stock @ market value |
| 90 | + #ask for 4 percent of total stock @ above market value |
| 91 | + #ask for 3 percent of total stock @ below market value |
| 92 | + #ask for 2 percent of total stock @ significantly below market value |
| 93 | + #ask for 1 percent of total stock @ true value |
| 94 | + if trueValue/price < 0.95: |
| 95 | + stockToSell = 0.3 * portfolio[ticker] |
| 96 | + robot.ask((int)(stockToSell/2), price, ticker) |
| 97 | + stockToBuy/= 2 |
| 98 | + robot.ask((int)(stockToSell*0.4), price + increment, ticker) |
| 99 | + robot.ask((int)(stockToSell*0.3), price - increment, ticker) |
| 100 | + robot.ask((int)(stockToSell*0.2), price - 2 * increment, ticker) |
| 101 | + robot.ask((int)(stockToSell*0.1), price - 3 * increment, ticker) |
102 | 102 |
|
103 |
| - |
| 103 | + |
0 commit comments