
Using an automated day trader to generate income - fbbwsa
http://fattyfatfat.com/2008/10/automated-day-trader-double-moving-average-crossover-test-1/
======
matt1
I have no idea what that guy is talking about with double moving averages and
what not, but I'd bet that a few simple IF/THEN statements could have produced
similar results over the same period of time. Say it hand done well, would you
go an invest a few thousand dollars using the IF/THEN algorithm?

On a similar note, say this guy did lose his $3500. Do you think you'd be
reading this post on how to automate day trading? Randomness and the
survivorship bias play a huge, huge role here.

As far as the website ideas go, I'm pretty sure that some very smart people
have demonstrated that using past performance to estimate future performance
simply does not work; no amount of tweaking buy/sell algorithms will help you
predict where the market is going tomorrow.

~~~
mixmax
_using past performance to estimate future performance simply does not work_

This is not always true.

I had a theory a few years ago that went like this: _The price of a stock is a
direct function of the perceived price of the company multiplied by a risk
factor: The more risk the less the stock is worth. On the day the yearly
report is publicised for a company the risk is big just before the publication
because nobody knows for sure what the numbers are, and low just after the
publication because everybody now knows._ So according to my theory the stock
price of an arbitrary company should statistically go up on the day that the
yearly report is made public.

I, painstakingly, found some historical data on this (it wasn't easy) and
found that it was spot on. A bit of statistical analysis showed thet there was
a definite gap to be exploited.

A friend of mine showed in his Masters thesis that there were certain patterns
that would almost always be present in IPO's that could be exploited if you
knew them.

So there are definitely loopholes where past behaviour shows future
performance, but not a lot of them.

And professional investors aren't always as smart as they're made out to be. I
know a few, and hackers are a lot smarter in regard to numbers.

~~~
mattmaroon
The problem is that the market is dynamic and chaotic. Measuring past data
doesn't give you much indication of how much your algorithm would have made,
even in hindsight, because every buy and sell you would have executed would
have changed the market and the future. Even relatively small orders can have
big ripple effects, especially if they just happen to trigger standing limit
orders.

Genuinely measuring the market (by trading) changes it.

~~~
steveplace
Ideally, yes.

In practice, no. Trading a couple lots of /es futures will not do much to the
market. More like pissing in the ocean. In illiquid markets you can move
price, but not the stuff that you would want to blackbox anyways.

~~~
mattmaroon
It can. If someone has a large limit order and your small order hits their
trigger price, whereas the next person might have done the opposite and moved
away from it, you could have caused a huge change in the direction of the
market. Or the same is true of a cascading series of smaller limit orders,
etc.

And since making money is presumably based on volume, if you did small trades,
you'd end up doing a lot of them to make it worth your while. But in almost
all forms of betting, it's better to make fewer, better wagers.

~~~
bayes
The trouble with fewer better wagers is that wagers - even very good value
ones - can lose. So if you're only making a few of them there's a significant
probability of losing overall. Your expected value may be high, but your
standard deviation is even higher.

I'd much rather have 10,000 independent bets each with a 0.5% edge than 10
independent bets each with a 20% edge.

~~~
steveplace
_I'd much rather have 10,000 independent bets each with a 0.5% edge than 10
independent bets each with a 20% edge._

Not with trading, you want to cut losses quick and let winners run. The model
behind Long Term Capital Management, as well as a ton of quant firms that went
under this past Q, was the take-a-bunch-of-trades-for-small-profit... and it
works until you get a six sigma event (see 2008).

------
paddy_m
I'm the CTO of a startup named QuantRunner Software, where we write
backtesting software, (beta coming this month) <http://quantrunner.com> . I
found the article interesting, but it leaves out some important details such
as

1\. Why did he decide to enter into this strategy at 10:45 am on October 15th?
2\. What would the outcome of the same strategy have been if it was left
running for the next month, for the past year, for the past 10 years.

I'm curious.

Questions about how the backtest was run.

1.How do you get your data? 2.you seem to have written an excel spreadsheet to
run the backtest, what's going on with that? How did you design it?

For other people on HN, does anyone here use backtesting tools? What do you
think of the existing software you use?

------
iseff
I've been thinking recently about how it would be cool to have a service which
allowed you to try different trading algorithms.

For instance, it would have a few algorithms built in, you could choose which
you want and with what parameters and then it would monitor how it performs.
Also available would be the ability to see how this algorithm would have
performed in the past (to see how it worked in bad markets, etc).

It could also have a generic API to allow you to run your own algorithm on
your end and simply make calls to BUY and SELL certain things.

(In the future it could even allow _real_ trades, etc. One other cool way to
make money off this would be to actually invest in the best performing
strategies as they occur over time.)

I'm guessing this is all available to the big firms, but haven't ever heard of
anything geared to the hackers who want to try things out.

Does anyone know if this sort of thing exists? Would anyone else think this is
neat?

~~~
Hates_
<http://www.tradestation.com/platform/overview.shtm>

This should do the trick. I've never tried it myself but certainly looks
interesting. I know of a few people who use it to try out different systems.

~~~
iseff
Nice, thanks!

~~~
brent
\- or - You can try the free metatrader if you're less serious.

------
mattmaroon
If you thought something were profitable in a market, and it was easy enough
to implement that any hedge fund could, why would you publish it? They'd just
do it too until it was no longer profitable.

~~~
jcl
On the other hand, if you thought something was highly risky and likely to
succeed only for a short time before blowing up, why not publish it, then bet
against it? :)

But seriously -- the author's comments seem to indicate that he is not totally
comfortable with the technique and that he is aware it could lose, even though
it didn't in this case.

~~~
fattyfatfat
you're right. and i ran it until it started losing. I announced the day i quit
running the basic moving average crossover algo.

I still dabble with variations of it (made like 250 bucks last friday), but
I'm now doing way more research and backtesting before I drop things into the
market for real.

~~~
fattyfatfat
on that note, i lost over 1000 bucks a day for 3 days straight, which is when
i quit.

and on having the "secret sauce" to beat the market. Read about Edward Thorpe.
He's a badass. He wrote the book "beat the dealer" which was the bible on
counting cards and beating vegas at blackjack.

Then he figured out how to price options (convertibles, really) and made a
killing in his own hedge fund (Princeton Newport Associates, I believe).

He had the secret sauce, used it to make a killing instead of publishing it.
YEARS later, black and scholes published the essentially SAME formula for
price options and eventually won a nobel price for their work.

But Thorpe stuck to his guns and made his fortune. Merits to both sides, I
suppose.

~~~
mattmaroon
What's the merit to publishing a successful algorithm? Or using a previously
published algorithm that any hedge fund manager or resourceful individual can
find and implement trivially.

~~~
matt1
A better question is how do you know your algorithm is successful? If it
predicts correctly 10 days in a row, have you got a winner? It's like those
guys that advertise by saying "We outperformed the market by 6.2% on average
the last four years." Put enough monkeys in front of a trading terminal and
you're going to have some that outperform the market by 6.2%; doesn't mean you
should invest your money with them.

~~~
gaius
Have you ever wondered how every fund manager has a fund in the top 25%? It's
easy, they launch several funds in one sector, then after a few years merge
them all into the top one, and use its historical performance for the
marketing materials _not_ the average of them all.

------
SwellJoe
So, the obvious question for me is where can I buy stocks for $2.40 per trade?
Any day trading successes I might manage would be eaten up by transaction
costs at my current broker (where trades are $9.95, I think). I'd probably be
a far more active trader at $2.40 (which may not be a good thing, but cutting
costs is always good).

~~~
fattyfatfat
I use interactive brokers.

The cost of a ES mini (SP500 mini future) trade is $2.40.

Stocks trade for half a penny to a penny per share with a minimum of $1.00 per
transaction.

I think they require 20k to start a new account these days though.

IB has been by far my favorite brokerage

~~~
kmt
For those who use IB: How long have you been using them? Do you use their
client or their API? Is it alright to use both, in parallel? People complain
about their customer service; have you had any problems? Is it easy to
transfer money to/from your IB account?

------
Dilpil
People have been using computers to trade since the 80s. It is estimated that
in some markets (Forex, Commodities), more than 50% of the orders are put in
by machines.

------
ruby_roo
Heh, so this has piqued my interest. I have absolutely no experience in online
investing/day trading, although I'm pretty sure a lot of you are veterans.

Any books you'd recommend to a programmer with day trading aspirations?

~~~
mattmaroon
Yeah, don't daytrade. It's a sucker's game. The market is too close to
efficient for you to recoup what you lose in brokerage fees and excess taxes.

Fund your IRA to the max, and if you're 20+ years from retirement buy all ETFs
with low expense rations. If you're closer to retirement, buy fewer stocks and
more t-bills, etc.

~~~
Brushfire
Its hardly a suckers game if you know what you are doing. I know prop traders
that make huge bank essentially daytrading on the forex and others.

Sure, its highly controlled gambling, but you of all people should realize
that its not a losing game for everyone. If anything, its just a suckers game
for small timers -- like all other gambling.

~~~
mattmaroon
Any sufficiently volatile form of gambling has big winners. That doesn't mean
it's +EV. The markets (especially forex, from what I hear) are such that even
if it were impossible to outperform the broader indexes, you could very well
know multiple people who did so over a period of years or even decades.

See Fooled by Randomness for a more detailed explanation.

~~~
volida
if you open 1 lot in your life and sell it and outperform the market, yes
that's random. If you open more lots and your success rate is higher than 50%
then you can't really call it random. Playing random in forex kills you.

You can treat it as gambling yes, but it's not.

~~~
mattmaroon
You can win more than 50% of wagers even over fairly large numbers if you're
-EV, especially if you're only slightly so and the variance is large. And with
tens of millions of people attempting to do this between forex, stocks,
futures, etc., it's a virtual certainty that one could find a large number who
have.

Again, read Fooled by Randomness.

~~~
volida
I think it's a combination of factors luck, knowledge, practice, that
ultimately their result may be called random.

However my opinion is that Forex is not gambling. In wagers to win big you
must either combine different bets with odds that pay as someone predefined.
If you combine more, the need for luck increases. If you bet a large amount of
money on high paying odds then again you need luck.

In contrary, foreign exchange you just trade the currency according to your
prediction. The only way to automatically lose the negative lot is going off
your margin. To win big, your prediction doesn't need to go against the odds
like a soccer bet for example.

But, I will check out that book. Thanks

------
fattyfatfat
And lastly: I wrote a lot of that just as I was figuring things out, so I
don't know how much of that I still stand by. But this morning, I wrote the
one thing that I'd recommend to anyone who is interested in this sort of
thing.

[http://fattyfatfat.com/2008/12/moving-average-crossover-
theo...](http://fattyfatfat.com/2008/12/moving-average-crossover-theory/)

~~~
hedgehog
I read through your posts but I didn't see whose data you used for
backtesting, did you use Interactive Broker's?

------
martinflack
A year ago I embarked on a project to learn Common Lisp by building a trading
system, to execute with the Interactive Brokers API.

I modeled the woodiescciclub.com trading strategies, primarily because the
math is simple and the patterns are well defined. However since then I've seen
other parties on the web talk about how the Woodies patterns actually don't
make money consistently, although I didn't corroborate this.

I actually found CL to be a fantastic language for this. I was writing up the
Woodies patterns using a DSL I had created:

    
    
      (defpattern zlr "Zero Line Reject" :with-trend
        ((count 1)    (within  100  250) (trend :up :or-opposite-invert))
        ((count 1)    (within  100  200) (trend :up :or-opposite-invert))
        ((count 0 10) (within  -50   99) (trend :up :or-opposite-invert))
        ((count 1)    (within  -50   50) (trend :up :or-opposite-warn) (angle :down))
        ((count 1)    (within    0  115) (trend :up) (angle :up) (away 8)))
    
      (defpattern hfe "Hook From Extreme" :counter-trend
        ((count 1)    (within  200  300) (trend :up))
        ((count 1)    (within    0  199) (trend :up) (angle :down) (away 3)))
    
       ...etc
    

The defpattern macro was creating, for example, #'is-zlr, #'is-zlr-up, #'is-
zlr-down, which were then used by a trading engine that monitored 5-minute
bars on a given futures contract and launched trades.

Another CL feature, restarts in the condition system, helped too. When the
data feed broke or got corrupt, an exception thrown which could reload the
data feed and restart back in the listening loop without forgetting any
context was helpful.

Also just running in a Lisp image was great because I could swap functions
during a live feed without stopping the program.

In the end, the programming worked great, but the trading system lost money. I
had it working in backtesting over a few months and then papertrade mode for
weeks, and then when I took it live, the volatility rose and it started
hitting the stop all the time. I adjusted things like stops based on ATR, but
I really just ran out of my little budget to play with it.

It did however teach me CL. ;-)

Modern trading platforms have built-in tools and programming languages and
writing things from scratch in CL is really just an academic exercise.

I believe it's possible to do algorithmic daytrading, but quite a bit more
difficult than it seems. There are way more market behavior modes than you can
appreciate at first, and the keys to success lie more in counterintuitive
aspects of your system like position sizing rather than intuitive aspects like
entry strategy.

The best talk I heard from someone on the subject indicated that it takes
years and the end result is a fairly sophisticated algorithm-switching engine,
because the hard part is just to survive.

------
Tichy
Like many hackers, I often pondered the idea. The closest I got was automated
trading in a stock market game run by the company I was working for. I never
got round to programming a sophisticated strategy, so basically it was just
"sell and buy random new stock if price has risen or fallen more than x%",
where I think x was something like 15%. Even with that the algorithm was in
the middle of the field (with 10000 participants), but it still lost a little
money. As it was 2001, losing money was to be expected, I guess.

------
fattyfatfat
um well, hello. so thats my website. quite the site here. and quite the
surprise to see that i'm getting any attention at all. a lot of very
intelligent commentary.

~~~
Prrometheus
All successful day traders are lucky. People who give day trading advice are
frauds.

That's not the most polite thing to say. Some of the people who give day
trading advice might even be sincere and not know that they are frauds. But
it's the truth.

------
quellhorst
So this guy wants to automate trading with $3.5k? You need at least $25k with
a cushion otherwise you can't day trade.

------
pjharrin
I'm actually working on a startup in this space. Nice to see some HN people
share a similar interest

~~~
drwh0
there's an entire street dedicated to people developing trading
algorithms...WALL. see: quant funds...whats left of them anyway

------
known
<http://en.wikipedia.org/wiki/Fixed_income> seems lot simpler strategy

------
steveplace
1\. Not having a stop loss (other than the 3500 circuit breaker) is a terrible
idea in black box trading.

2\. Yes, it is that simple. Note that simple != easy.

------
apstuff
boolean TraderAnxiety(boolean mktStatus) {

    
    
      if (mktStatus == FALLING) {
        Sell();
        return true;
      }
    
      if (mktStatus == SURGING) {
        Buy();
        return true;
      }
    
      if (mktStatus == FEAR) {
        Loathing();
        return true;
      }
    
      if (mktStatus == OVERMYHEAD) {
        UseProfanity();
        return true;
      }
    
    
      return true;

~~~
olefoo
Your `boolean` has 4 values?

Most languages I am familiar with require booleans to be either TRUE or FALSE,
although I have met a few where undefined or NULL are possible values.

~~~
steveplace
It returns true in all 4 cases.

~~~
olefoo
mktStatus is always true and he defined 4 values for it?

:P

~~~
shabda
That is the wall street boolean, what do you expect?

