So I realized that some trades were failing to execute because they were below the minimum tradeable amount.
This was triggering a flaw in the ordering logic which was the source of some of the more interesting notes in my logs.
I've now added both min and max currency amounts.
High: Ticker [timestamp=2012-09-14T12:37:52.430Z, last=USD 11.52338, bid=USD 11.52338, ask=USD 11.52572, tradableIdentifier=BTC, volume=2949494761223]
Low: Ticker [timestamp=2012-09-14T12:42:37.605Z, last=USD 11.43251, bid=USD 11.43351, ask=USD 11.5233, tradableIdentifier=BTC, volume=2944701489592]
Current: Ticker [timestamp=2012-09-14T13:30:05.568Z, last=USD 11.51, bid=USD 11.451, ask=USD 11.51, tradableIdentifier=BTC, volume=2959960727343]
VWAP: 11.51947
The market is trending down.
Sep 14, 2012 7:30:47 AM org.open.payment.alliance.isis.atp.TradingAgent evalBid
INFO: Attempting to buy 0.00000000 USD
Sep 14, 2012 7:30:47 AM org.open.payment.alliance.isis.atp.TradingAgent evalBid
INFO: 0.00000000 was less than the configured minimum of 0.01
Increasing order size to 0.01
Sep 14, 2012 7:30:47 AM org.open.payment.alliance.isis.atp.TradingAgent marketOrder
INFO: You are in simulation mode, the transaction below did NOT actually occur.
Sep 14, 2012 7:30:47 AM org.open.payment.alliance.isis.atp.TradingAgent marketOrder
INFO: Successfully bought 0.01 at current market price.
So it looks like that part is resolved. Now for the interesting part.
In my code the algorithm is using max only as a ceiling constraint and it's calculating how much to trade using your balance as the starting point.
When I ran my simulations on the hadoop cluster max was used in the same place in the algorithm as we're using the balance now.
Both situations will always produce a trade between 0 and Max. The difference being, if you have a substantial balance you'll be trading Max much more often, where as the optimal algorithm identified by my simulations had Max being traded rarely if ever.
I'd like to test both and see which is more performant. I have a hunch that this "mistake" is primarily why I'm seeing such high profit/loss.
I'll add an option to the setup interview to let you pick one or the other but I need you to pick, understand the risks and roll with it for the entire month. Keep in mind that the difference is in how much is risked per trade, the decision on whether or not it's time to trade at all is a different step.
So let's walk through it a moment.
With the ATP, trading occurs in two steps.
First is to determine "are market conditions favoring, buy, sell or hold right now?"
Second is to determine "how much do I trade right now?"
Market Conditions means all trades that have actually occurred in the last hour.
These are summed at each tick and a VWAP (Volume Weighted Average Price) (Each trade on the ticker multiplied by each trade's quantity. Each is then summed and the sum is divided by the total volume)
3 indicators called arrows are generated as well, we have a trendArrow, bidArrow and askArrow.
Each arrow can be any one of positive, negative or 0.
If it's 0 that means the market is completely flat, so we have to wait.
If the trendArrow is positive it means that prices for bitcoins are going up relative to your local currency, thus we should look at selling some of ours off. If the trendArrow is down, then it means prices are going down relative to your local currency and we should look at buying.
Once the trendArrow has been evaluated and we know the market is trading, we want to time our entry and exit into the market to maximize our profit.
We do that by comparing the last trade with the vwap.
If the trendArrow is up, then we compare the last trade from the ticker with the vwap. If it's above the vwap then we sell (at market prices).
If the trendArrow is down, then we compare the last trade from the ticker with the vwap. If it's below the vwap then we buy (again at market prices).
The decision has now been set in stone, we are buying (or selling). The only question now is how many BTC do we buy or sell?
Here are the two Bid algorithms in question, the Ask is the same algo, but instead of askArrow we use the bidArrow and instead of local currency we use BTC
I'll let you do your own math.
Trading Algorithm 1
BigDecimal weight = new BigDecimal((askArrow / ticker.size()) * (trendArrow / ticker.size()));
BigDecimal balance = AccountManager.getInstance().getBalance("USD").getAmount();
BigDecimal amountToSpend = balance.multiply(weight).multiply(fee);
Algorithm 2
BigDecimal weight = new BigDecimal((askArrow / ticker.size()) * (trendArrow / ticker.size()));
BigDecimal amountToSpend = maxLocal.multiply(weight).multiply(fee);
The askArrow (or bidArrow if we're selling), is calculated the same way as the trendArrow but uses the "ask" value from the ticker.
It's purpose is to let us know if people(or bots) placing limit orders are raising or lowering their prices.
Both of these values are multiplied together to give us a weight.
That weight is multiplied against (max or balance) and determines how MUCH we are trading.
That's it for now. You now know enough (hopefully) to choose your trading algorithm. Let me know what you think!