
Algorithmic Trading: A Practical Tale for Engineers - bbeneschott
http://www.toptal.com/data-science/algorithmic-trading-a-practical-tale-for-engineers
======
OldSchool
Thanks for posting a very top level view of automated trading for engineers.

In case discussion goes cynical here, I can attest to the fact that this sort
of thing can be done consistently and successfully for thousands of trades
over months' time. These days though with HFT and "intelligent routing" your
broker is your opponent in the equities world at least. When conditions become
unfavorable to an algorithm things tend to fizzle out rather than wipe you out
as long as you're not leveraged to the hilt. The point about optimizing is
key: the best algorithm has the minimum number of parameters to tweak
otherwise you're just curve-fitting. Whether you add value to the world is
anyone's opinion.

Proceed at your own risk of time and money.

~~~
jscheel
Interesting, so, you are saying that the right approach (plus a religious
avoidance of leveraged positions) is generally a low risk investment? What
about trading fees, won't those progressively eat into you as your model
continues to fizzle out at thousands of trades per month?

~~~
OldSchool
Trading costs have to part of your model, but at Interactive Brokers for
example you only pay $0.005/share (with a $1 minimum) to trade. At that rate
you can try to trade for an average of pennies per share (including winners
and losers). When an algorithm fizzles, my experience is that it stops making
small amounts of money per trade on average and starts losing small amounts of
money per trade on average, with more volatility.

As you see then, you may automate trading itself, but then your discretion is
shifted from deciding what stock to buy or sell short to when to turn on or
off an algorithm. The advantage I suppose is that an algorithm isn't
necessarily directly tied to market direction.

~~~
jscheel
Ah, thanks for the explanation! I've stayed completely away from forex, so I
don't know much about it.

------
brianbarker
I'm just going to leave this here.

I worked at a FX broker as a software engineer. When nerds first read about
this stuff we all have the same knee-jerk reaction: "I write code. I'm smart.
I could build a robot trader and make a Walter White pile of cash."

In short, I would recommend you stay the hell away from FX. It's bullshit.
It's not like the any type of trading (algorithmic, quantative, manual, good
luck charm) you see in stockes. I do thank the blog author for mentioning that
his system never seemed to work long term. That's the key element most people
can't accept.

Here are a few notes from my time in FX:

FX is traded on margin, and it's easy to lose all your money. Nearly every
single person will lose all their money in FX, and those who claim success are
riding a temporary wave. Even "experts" in the field can't hold big gains much
more than a few weeks or months at best.

A few years back our company bought a trading system we'd been marketing like
crazy and had customers buy into. Senior management decided to invest a
6-figure sum in this system with the intent of using the profits for employee
bonuses. The day it crashed, not only did we have angry customers but our
employees were pretty depressed.

FX trading systems are hype. Always. You'll hear the term "holy grail" in
reference to trading strategies. That should be enough to keep you away. The
real money is made by selling systems to idiots and writing books about it. As
a matter of fact, you'll notice a lot of forums and blogs have referral links
to brokers ;).

A common sentiment I heard tossed around traders and employees goes something
like, "rather than trade FX, just go to Vegas and play roulette. At least you
get free beers."

The technology is god-awful. You'd be blown away if you saw how shit-tacular
the backend is that handles your money. I thought it was just the place I
worked, but nope.

The company I worked for is very open and compliant, which I found admirable.
This has continued to be their focus, so that's cool. Many brokers are
corrupt, particularly if they're not in the US. Brokers have been caught
increasing margins against traders, stop-gapping trades and worse. In the US
the NFA is insane so they do a decent job of regulating, but it seems every
year or so they nab a broker on something. Most NFA fines range in the
millions so we took this seriously.

I have more war stories, but that's enough. Best advice: do not trade FX. I
realize that may rile some of you, so be it. I wouldn't put my money near that
shit.

~~~
Choronzon
Amen, Forex has less fundamental information than other markets,incredible
leverage and is subject to (legal) political manipulation at the highest level
(see Sovereign wealth funds). In addition relationships I have found holding
for stocks/indices do not transfer to the forex market at all. Easily the most
difficult market. I think it is probably crackable quantitively but only for a
more limited set of strategies than the standard market.

------
dunster
Very neat story. Thanks for writing it up. The nuts and bolts of this kind of
operation are fascinating. I know a lot of people out there have trading
ideas, but don't really know how to implement them.

If you just finished the post and you want to try coding up a trading
algorithm for free, check out
[http://www.quantopian.com](http://www.quantopian.com). It uses Python, not
MQL, and provides free data and backtesting. (Yes, I work at Quantopian)

------
rismay
I posted this on topal too, but I want to get your opinions also:

I studied a bit of market theory in college and learned about channel trading.
The Efficient Market Hypothesis is just that - a "Hypothesis" \- not a law.
Plenty of academics have argued against it but they don't teach this in
undergrad courses so as not to confuse students (this is seriously the answer
I was given when I asked my teachers). Some people like Nassim Taleb are
calling for a BAN on teaching entry level finance courses to MBAs who go out
and gamble vast amounts of money based on incorrect theories.

I always thought that algo trading would be a good fit for channel strategies
since the strategy is recursive in nature.

Does anyone have any pointers on how to implement channel type of strategies
(as opposed to Moving Average strategies)? I'd be willing to chat about deeper
into this topic.

FYI: Some (old) research shows that Exponential MA strategies make more and
even out perform buy and hold strategies without taking into account tax
advantages. If you have ever read a "Random Walk Down Wall Street" and don't
believe in this "crap," it's actually in the footnotes of the sources the
author cites.

~~~
Choronzon
Channels are boundary conditions on an estimation of a price or a price
itself,effectively a form of error bar. Your statistically looking at central
tendencies and dispersion.

~~~
rismay
No. That's another trading method. I know what you are talking about there
too, but that's not how I see the strategy working.

What I found in my research is that the statistical analysis being done on
markets is an approximation of the underlying phenomena. Yes - central
tendencies and dispersion work 90% of the time, but they hugely under price
tail events. This is the basis of Nassim Taleb's trading strategy.

What I see really happening is a recursive channel pattern at different time
scales. As the recursion plays out it "zooms in" on the correct price of a
security and the central tendencies and dispersion can be analyzed through
traditional statistics. However, when a market correction takes place it
"zooms out" by stepping back through previous market cycles and then
statistical models break down. It's very weird to explain. Essentially, I see
the market being a predictable Fractal pattern. Check out Mandelbrot's work on
Finance to get some insight. I just disagree with his (and Nassim's)
conclusion that these can't be predicted.

I've always been interested in trying to back test my theory but I didn't have
the technical chops and didn't know where to start looking.

Thanks for your thoughts.

~~~
Choronzon
Diregard Taleb,the man cant trade (buying OTM puts and hoping for the world to
end is not a trading strategy.)You are looking at basically a three regime
model,(standard statistical events,macro breakdown,and "dont know").The
problem is "fractals" is not a decent way to distinguish the three states,so
now you have 3 problems. For what its worth I think Mandelbrot was onto to
something but its a long way away from a trading strategy.You could decompose
movements over different frequencies ("Fractal Self Similarity) and test for
some sort of state wise relationship between recent micro and macro
movements.Im largely sure this will exist but extracting a leading indicator
out of this may be difficult.

~~~
rismay
I know this is late: but you get what I'm talking about: You could decompose
movements over different frequencies ("Fractal Self Similarity) and test for
some sort of state wise relationship between recent micro and macro movements.
That's where the channel patterns come in - they are self similar at different
time scales. The rules are pretty well known, but getting them coded is a
different story. I always find MACD strategies which are only approximations.

------
ipfree
I have taken different approach. I decided that the best way is to train by
own brain how to trade. Basically my approach was to trade as much as possible
and have results, without waiting for the market to let me know how I was
doing. So I wrote my own program called turtrades (test your trades). It
basically presentments you with random stock in random past date and lets you
trade or pass. Doing this I am using real historical market data and train my
brain to spot winning patters and I get instant result. For those interested
you can find it here [http://www.turtrades.com](http://www.turtrades.com)

Yes it is as selfish plug but program is free and I have nothing to gain.

------
samspenc
I think there was a Bloomberg article at the front page of HN a few weeks ago
talking about how algorithmic trading was producing less and less profits -
can't find the source/link right now.

Is that still true? Or is algorithmic trading on a rebound?

~~~
dunster
High-frequency algorithms are producing less profits. Other forms of
algorithmic trading are growing.

~~~
kasey_junk
You have to be careful with terms in this space (and many of them aren't even
well defined).

There are algorithmic trading strategies that are high frequency, but not low
latency for instance. Or low latency strategies that are not high frequency.

In my experience what people are talking about when they say that high
frequency algorithms are producing less profits, what they really mean is that
low latency arbitrage algorithms are not making as much profit.

Lots of high frequency algorithms remain profitable.

------
drawnic
Thanks for the comments!, this is just the tip of a huge iceberg down the
water... As you'll see the logic is very basic, and the system is rather
blind; but the main idea was to post this simple example because I noticed how
unknown is this subject among programmers. From this point forward, the
imagination is the limit when talking about trading systems creation.

~~~
rismay
Any thoughts on how to implement a channel trading algorithm?

------
mguillech
Found it really interesting, I'm one of those that know nothing about FX, this
has been very enlightening to me.

