Trading with opensource tools, two years later
Upcoming SlideShare
Loading in...5
×
 

Trading with opensource tools, two years later

on

  • 3,830 views

 

Statistics

Views

Total Views
3,830
Views on SlideShare
3,400
Embed Views
430

Actions

Likes
6
Downloads
77
Comments
0

12 Embeds 430

http://funningboy.blogspot.com 263
http://funningboy.blogspot.tw 149
http://funningboy.blogspot.in 4
http://funningboy.blogspot.hk 4
url_unknown 2
http://funningboy.blogspot.ca 2
http://twitter.com 1
http://funningboy.blogspot.jp 1
http://duckduckgo.com 1
http://cncc.bingj.com 1
http://webcache.googleusercontent.com 1
http://funningboy.blogspot.kr 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Trading with opensource tools, two years later Trading with opensource tools, two years later Presentation Transcript

    • Tradingwith open source tools two years later Chia-liang Kao clkao@clkao.org OSDC.TW 2011 Taipei
    • Trading SystemTrading system, also known as algorithmic trading, is the use ofcomputer programs for entering trading orders with the computeralgorithm deciding on certain aspects of the order such as thetiming, price, quantity of order Even with dice
    • The OSDC Trading System (in 2009 talk)
    • Risk = controlled by youProfit = probabilities
    • Automated Trading Components quote strategy order (via broker)
    • bayen2010 results 40.15% net, end of year (Not with dice!)
    • Architecture 2009
    • quotememcached strategy GeniusTrader jsonrpc order pos: +1, -1, 0 (via broker)
    • Architecture 2011
    • quote monitoring quote rabbitmq Runs on Amazon EC2 position sizing anymq strategy1 (ap-southeast-1) strategy2 TradeSpring order ensuring jsonrpc order (via broker)system monitoring emergency fallback
    • 40.15% net, end of year 95.71% gross -21.85% cost -33.71% slippage avg: -2.5 in 2010 avg: -0.5 in 2011 moved to EC2moved to AnyMQ
    • Quote• Source • Commercial Quote services • Win32::DDE• AnyMQ• AnyEvent::Monitor• Price AGgregation Manager: serve history and manages real time quotes
    • Source• was running on MicroXP in VirtualBox• now on EC2 win32 instances• Republish to rabbitmq with AnyMQ
    • AnyMQ• inspired by Tatsumaki::MessageQueue• Use Moose traits• Available on CPAN• can talk to amqp servers like rabbitmq
    • AnyMQmy $bus = AnyMQ->new;my $topic = $bus->topic("Foo");my $sub = $bus->new_listener($topic);$sub->poll(sub { my $msg = shift; })$topic->publish($msg)
    • AnyMQ with AMQPmy $bus = AnyMQ->new_with_traits ( traits => [ ‘AMQP’], # host => ..., port => ..);my $topic = $bus->topic("Foo");my $sub = $bus->new_listener($topic);$sub->poll(sub { my $msg = shift; })$topic->publish($msg)
    • AnyMQ with AMQPmy $bus = AnyMQ->new_with_traits my $bus = AnyMQ->new_with_traits ( traits => [ ‘AMQP’], ( traits => [ ‘AMQP’], # host => ..., port => ..); # host => ..., port => ..);my $topic = $bus->topic("Foo"); my $topic = $bus->topic("Foo");my $sub = $bus->new_listener($topic); my $sub = $bus->new_listener($topic);$sub->poll(sub { my $msg = shift; }) $sub->poll(sub { my $msg = shift; })$topic->publish($msg) $topic->publish($msg) AMQP Server my $bus = AnyMQ->new_with_traits my $bus = AnyMQ->new_with_traits ( traits => [ ‘AMQP’], ( traits => [ ‘AMQP’], # host => ..., port => ..); # host => ..., port => ..); my $topic = $bus->topic("Foo"); my $topic = $bus->topic("Foo"); my $sub = $bus->new_listener($topic); my $sub = $bus->new_listener($topic); $sub->poll(sub { my $msg = shift; }) $sub->poll(sub { my $msg = shift; }) $topic->publish($msg) $topic->publish($msg)
    • Service monitoring• Is it running?• Can we fix it when it fails?
    • AnyEvent::Monitormy $foo = AnyEvent::Monitor->new( name => foo, on_softfail => sub { warn "==> service fail: $_[1]"; }, on_hardfail => sub { my ($resume_check); warn "==> service fail, should attempt to do something to fix it: $_[1]"; $resume_check->(60); # resume checking after 60 secs }, on_resume => sub { my ($prev, $outage) = @_; if ($prev) { warn "service resumed from: $prev, total outage: $outage secs"; } });
    • PAGM• a daemon listening on rabbitmq topic• tells client where to look for aggregated price ticks• answers historical price request: { type: ‘pagm.history’, reply: ‘client-name’, code: ‘XTAF.TX’, timeframe: ‘5min’, count: 180 }
    • Strategy• the core that decides: • when to buy/sell? • how much to buy/sell? • when to stop loss, take profit?• Finance::GeniusTrader• TradeSpring
    • Finance::GeniusTrader • DSL for trade systemsSY:Generic {S:G:Above {I:Random 6} 2} {S:G:Below {I:Random 6} 3} |TF:Generic {S:G:CrossOverUp {I:Hour} 850} {S:G:CrossOverUp {I:Hour} 850} |TF:MaxOpenTrades 1 |CS:DayTrade • too verbose • designed for backtesting • didn’t support live trading by default
    • TradeSpring!
    • ++
    • (Second largest profit this year was on 3/15, went to Japan Red Cross Society)
    • TradeSpring• New strategy runner engine• backtest code = live code• supports complex order types • attached, OCA, trail stop, etc• Moose based• More abstracted• release this year?
    • TradeSpringmethod detect_direction { for (1,-1) { local $self->{direction} = $_; if ($self->bt($self->better, $self->better($self->i-1)) && $self->bt($self->better($self->i-1), $self->better($self->i-2)) && $self->bt($self->close, $self->close( $self->i-1)) && $self->bt($self->close($self->i-1), $self->close( $self->i-2))) { return $self->{direction}; } } dir = -1} better dir = 1
    • TradeSpring examplesmethod detect_direction { for (1,-1) { local $self->{direction} = $_; if ($->bt($->better, $->better($->i-1)) && $->bt($->better($->i-1), $->better($->i-2)) && $->bt($->close, $->close( $->i-1)) && $->bt($->close( $->i-1), $->close( $->i-2))) { return $self->{direction}; } }} invoker.pm on CPAN
    • TradeSpring Order$self->new_bracket_order( { dir => $direction, type => lmt, price => $self->better($self->i-1), entry qty => $self->position_qty }, { price => $self->worse($self->i-1) }, stop { type => mkt, price => 0, timed => $self->order_timed(13, 43, 00) }); exit
    • EC2• multiple az • ap-southeast-1 latency: 60ms • ap-northeast-1 latency: 40ms • (to broker endpoint)• multiple region
    • Net::Amazon::EC2• cloud-init, user-datatn1: persistent: 1 ami_name: tn-dev6 type: m1.small security_group: default key_name: clec availability_zone: ap-southeast-1a
    • Gangliaec2 costs: ~US$100 / month
    • Analysis•R• protovis• ask interesting questions and check your records!
    • Trade result breakdown by time and day of week
    • 2011 results YOD ? ?10% of profit will go to TPF
    • PROFIT!!
    • Questions? clkao@clkao.org