+ All Categories
Home > Technology > Trading with opensource tools, two years later

Trading with opensource tools, two years later

Date post: 06-May-2015
Category:
Upload: clkao
View: 3,601 times
Download: 1 times
Share this document with a friend
Popular Tags:
38
Trading with open source tools Chia-liang Kao [email protected] OSDC.TW 2011 Taipei two years later
Transcript
Page 1: Trading with opensource tools, two years later

Tradingwith open source tools

Chia-liang [email protected]

OSDC.TW 2011 Taipei

two years later

Page 2: Trading with opensource tools, two years later

Trading System

Trading system, also known as algorithmic trading, is the use of computer programs for entering trading orders with the computer algorithm deciding on certain aspects of the order such as the timing, price, quantity of order

Even with dice

Page 3: Trading with opensource tools, two years later

The OSDC Trading System

(in 2009 talk)

Page 4: Trading with opensource tools, two years later

Risk = controlled by you

Profit = probabilities

Page 5: Trading with opensource tools, two years later

quote

strategy

order(via broker)

Automated TradingComponents

Page 6: Trading with opensource tools, two years later

bayen2010 results

40.15% net, end of year

(Not with dice!)

Page 7: Trading with opensource tools, two years later

Architecture 2009

Page 8: Trading with opensource tools, two years later

quote

strategy

order(via broker)

memcached

jsonrpc

GeniusTrader

pos: +1, -1, 0

Page 9: Trading with opensource tools, two years later

Architecture 2011

Page 10: Trading with opensource tools, two years later

Runs on Amazon EC2(ap-southeast-1)

quote

strategy2

order(via broker)

rabbitmqanymq

jsonrpc

TradeSpringstrategy1 order ensuring

position sizing

quote monitoring

system monitoring emergency fallback

Page 11: Trading with opensource tools, two years later

moved to AnyMQmoved to EC2

avg: -2.5 in 2010

avg: -0.5 in 2011

95.71% gross-21.85% cost-33.71% slippage

40.15% net, end of year

Page 12: Trading with opensource tools, two years later

Quote

• Source

• Commercial Quote services

• Win32::DDE

• AnyMQ

• AnyEvent::Monitor

• Price AGgregation Manager: serve history and manages real time quotes

Page 13: Trading with opensource tools, two years later

Source

• was running on MicroXP in VirtualBox

• now on EC2 win32 instances

• Republish to rabbitmq with AnyMQ

Page 14: Trading with opensource tools, two years later

AnyMQ

• inspired by Tatsumaki::MessageQueue

• Use Moose traits

• Available on CPAN

• can talk to amqp servers like rabbitmq

Page 15: Trading with opensource tools, two years later

AnyMQ

my $bus = AnyMQ->new;my $topic = $bus->topic("Foo");

my $sub = $bus->new_listener($topic);$sub->poll(sub { my $msg = shift; })

$topic->publish($msg)

Page 16: Trading with opensource tools, two years later

AnyMQ with AMQP

my $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)

Page 17: Trading with opensource tools, two years later

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)

my $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)

my $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)

my $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)AMQP Server

Page 18: Trading with opensource tools, two years later

Service monitoring

• Is it running?

• Can we fix it when it fails?

Page 19: Trading with opensource tools, two years later

AnyEvent::Monitor my $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"; } });

Page 20: Trading with opensource tools, two years later

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 }

Page 21: Trading with opensource tools, two years later

Strategy

• the core that decides:

• when to buy/sell?

• how much to buy/sell?

• when to stop loss, take profit?

• Finance::GeniusTrader

• TradeSpring

Page 22: Trading with opensource tools, two years later

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

Page 23: Trading with opensource tools, two years later

TradeSpring!

Page 24: Trading with opensource tools, two years later

♨++

Page 25: Trading with opensource tools, two years later

(Second largest profit this year was on 3/15,went to Japan Red Cross Society)

Page 26: Trading with opensource tools, two years later

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?

Page 27: Trading with opensource tools, two years later

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

Page 28: Trading with opensource tools, two years later

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

Page 29: Trading with opensource tools, two years later

TradeSpring Order

$self->new_bracket_order( { dir => $direction, type => 'lmt', price => $self->better($self->i-1), qty => $self->position_qty }, { price => $self->worse($self->i-1) }, { type => 'mkt', price => 0, timed => $self->order_timed(13, 43, 00) });

stop

exit

entry

Page 30: Trading with opensource tools, two years later

EC2

• multiple az

• ap-southeast-1 latency: 60ms

• ap-northeast-1 latency: 40ms

• (to broker endpoint)

• multiple region

Page 31: Trading with opensource tools, two years later

Net::Amazon::EC2

• cloud-init, user-data

tn1: persistent: 1 ami_name: tn-dev6 type: m1.small security_group: default key_name: clec availability_zone: ap-southeast-1a

Page 32: Trading with opensource tools, two years later

Ganglia

ec2 costs: ~US$100 / month

Page 33: Trading with opensource tools, two years later

Analysis

• R

• protovis

• ask interesting questions and check your records!

Page 34: Trading with opensource tools, two years later

Trade result breakdown by time and day of week

Page 35: Trading with opensource tools, two years later

?

?

2011 results YOD

10% of profit will go to TPF

Page 36: Trading with opensource tools, two years later

PROFIT!!

Page 38: Trading with opensource tools, two years later

謝謝!


Recommended