Re-learning Java a decade later

Java is the programming language that I have known and used the longest. I learned Java as part of the curriculum when I was in my first year of undergraduate study. Although reluctant at first, I can still recall the joy I felt switching over from C++. No more garbage collection! That was ten years ago. I haven't done any real programming in the last few years as my engineering work has become higher and higher level. Although I have maintained my hobby in developing automated trading strategies and quantitative analysis, much of that work are mere child's play compared to what I have done and much forgotten. Lately, words such as "code smell", "design pattern", and the likes are creeping back into my world as I am comitting myself to pursuit my esoteric fascination in financial engineering. The first step, research, was a few months of testing the possibilities to decide what I should use. Different markets, different brokers, different platforms, and different technology. I decided to study the foreign exchange market through Dukascopy's JForex platform using Java. Although ideally, I would be using Oanda and Python... But I'm not prepared to cough out \$600 per month for Oanda's API. Some of the other tools that I use are RapidMiner and Weka. Both of which offer a Java API. Having learned JForex and programmed a few strategies already, I have tested the water enough. For the past few weeks, I have been taking steps to move to the next level of my development. However, as I play with programming more and more, I realize that I am fundamentally outdated in my programming skills. There were no interface when I learned Java. Neither was there hashset and annotation. As such, before doing anything else, I am just going to pause for the next two weeks while I am travelling in Hong Kong and catch up on my Java knowledge (I just realized that they don't publish those Teach Yourself \<insert topic> in 24 Hours book anymore. The Head First series seem to be the craze nowadays). My goal is to devour a Java book in the 15-hour flight. Let's see if I still got it after ten years.

To gamble or not to gamble?

There is only two more trading days left in the April Dukascopy JForex Strategy Contest. I am currently ranked 6th. But there's a fierce fight for my spot. I've been moving between 6th and 8th all week even though I haven't made any trade. The other people are putting on big bets hoping to squeeze in a top 6. Why? According to the winning prize structure, the 4th to 6th winners will each receive \$1,000. Whereas the 7th to 10th will each receive \$500 only. With my current account standing at \$120,032 (20% gain) this month, it is quite viable for others to try to take my spot. See the table below for the top 10 standings as of this writing.

April standing 2 days before close

My options are to either fire up my strategy to make more trades or do nothing. The risk in running my strategy again is that I might lose money and make myself even less competitive. My strategy's working timeframe is in hours, so there isn't much room for error. As such, I feel that with only two days of trading left, time is not on my side.

On the other hand, I will probably lose out my 6th spot as I am not far away from others behind me. So if I do nothing, I will most likely end up 7th or 8th and lose half the prize money.

After pondering about this briefly, I've decided to do nothing. The odds are just too much against me. I have seen too many people in this month's contest risking to move up from a good rank only to expose themselves too much and lose out of the top 10 completely.

Clarification and relieve for Dukascopy JForex Strategy Contest

I found out that the competing strategy in the Dukascopy JForex Strategy Contest doesn't need to be 100% automatic! According to Contest Support in the official forum, I can set parameters like take profit target, stop loss, and long-only or short-only trades. That make this contest substantially easier to program as I can implement a semi-automatic strategy, which is what I prefer in my real trading. The problem with building an automated trading system is that market conditions change frequently and without notice. Thus, it takes more than a few lines to program a consistently profitable system to filter out undesirable conditions. As I discussed before, because all winners in this contest have to publish their source codes, I don't want to spend too much time on this contest. Now that I know I can trade semi-automatically in this contest. I can just do my analysis manually and then use the strategy to execute trades when I so desire. That is exactly like my real trading process as illustrated before. As you can imagine, I am very happy of this news. I don't need to scratch my head anymore to build a new strategy for next month's contest. I programmed and tested several new ideas in the past 2 weeks but haven't found anything better than my existing strategy, which has been doing well in April. This Dukascopy JForex Strategy Contest has been a great incentive for me to become familiar with JForex. As I intend to use it for my real trading at Dukascopy (open an account with this affiliate link to receive 35% rebate on commissions) later this year, this is a win-win situation for me as I learn the API and possibly win some prize money at the same time.

JForex StopManager 1.0

I am building my real JForex automated trading system one feature at a time. The idea is to automate some of my most fundamental trading techniques on JForex so that I can trade forex semi-automatically on Dukascopy. I am starting off here with a simple stop management strategy. In a nutshell, once the market price moves in your favour equidistant from your original stop loss, this strategy moves the stop to breakeven. For example, if I go long EURUSD at 1.3500 with a stop at 1.3400 (100 pips stop). Then if the price breaks above 1.3600 (100 pips profit), the strategy moves the stop to breakeven. This is a simplistic implementation of the saying that "never let profits turn into losses". You can download the source code here and the executable strategy here. Note that these files are made available through Dropbox. Update: This logic is now integrated into the JFUtil open source project. You can also see a list of my latest JForex articles here. [java] /* StopManager.java version 1.0 Copyright 2010 Quantisan.com Move stops to breakeven when equidistance to original stop loss */ package jforex; import com.dukascopy.api.*; public class StopManager implements IStrategy { private IEngine engine; private IConsole console; private IContext context; @Configurable("Lock-in Pips for Breakeven") public int lockPip = 3; @Configurable("Move stop to breakeven?") public boolean moveBE = true; public void onStart(IContext context) throws JFException { this.engine = context.getEngine(); this.console = context.getConsole(); this.context = context; } public void onAccount(IAccount account) throws JFException { } public void onMessage(IMessage message) throws JFException { } public void onStop() throws JFException { } public void onTick(Instrument instrument, ITick tick) throws JFException { for (IOrder order : engine.getOrders(instrument)) { if (order.getState() == IOrder.State.FILLED) { boolean isLong; double open, stop, diff, newStop; String label = order.getLabel(); IChart chart; isLong = order.isLong(); open = order.getOpenPrice(); stop = order.getStopLossPrice(); diff = open - stop; // stop loss distance if (isLong) { // long side order if (moveBE && diff > 0 && tick.getBid() > (open + diff)) { // make it breakeven trade + lock in a few pips newStop = open + instrument.getPipValue() * lockPip; order.setStopLossPrice(newStop); console.getOut().println(label + ": Moved stop to breakeven"); chart = this.context.getChart(instrument); chart.draw(label + "_BE", IChart.Type.SIGNAL_UP, tick.getTime(), newStop); } } else { // short side order // Move to breakeven if (moveBE && diff \< 0 && tick.getAsk() \< (open + diff)) { // diff is negative // make it breakeven trade + lock in a few pips newStop = open - (instrument.getPipValue() * lockPip); order.setStopLossPrice(newStop); console.getOut().println(label + ": Moved stop to breakeven"); chart = this.context.getChart(instrument); chart.draw(label + "_BE", IChart.Type.SIGNAL_DOWN, tick.getTime(), newStop); } } } } } public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException { } } [/java]

←   newer continue   →