SlideShare una empresa de Scribd logo
1 de 38
Descargar para leer sin conexión
Trading
with open source tools
      two years later
         Chia-liang Kao
        clkao@clkao.org

      OSDC.TW 2011 Taipei
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
The OSDC Trading System
     (in 2009 talk)
Risk = controlled by you
Profit = probabilities
Automated Trading
  Components
        quote

       strategy

         order
     (via broker)
bayen
2010 results
                     40.15% net, end of year




  (Not with dice!)
Architecture 2009
quote
memcached
        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 EC2
moved 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
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)
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)
AnyMQ with AMQP
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)
                                         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::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";
        }
    });
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 systems
SY: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?
TradeSpring
method 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 examples
method 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-data
tn1:
  persistent: 1
  ami_name: tn-dev6
  type: m1.small
  security_group: default
  key_name: clec
  availability_zone: ap-southeast-1a
Ganglia



ec2 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
Trading with opensource tools, two years later

Más contenido relacionado

La actualidad más candente

PHP 7 – What changed internally? (Forum PHP 2015)
PHP 7 – What changed internally? (Forum PHP 2015)PHP 7 – What changed internally? (Forum PHP 2015)
PHP 7 – What changed internally? (Forum PHP 2015)Nikita Popov
 
How to stand on the shoulders of giants
How to stand on the shoulders of giantsHow to stand on the shoulders of giants
How to stand on the shoulders of giantsIan Barber
 
The promise of asynchronous php
The promise of asynchronous phpThe promise of asynchronous php
The promise of asynchronous phpWim Godden
 
How CPAN Testers helped me improve my module
How CPAN Testers helped me improve my moduleHow CPAN Testers helped me improve my module
How CPAN Testers helped me improve my moduleacme
 
ZeroMQ Is The Answer: DPC 11 Version
ZeroMQ Is The Answer: DPC 11 VersionZeroMQ Is The Answer: DPC 11 Version
ZeroMQ Is The Answer: DPC 11 VersionIan Barber
 
Diving into HHVM Extensions (php[tek] 2016)
Diving into HHVM Extensions (php[tek] 2016)Diving into HHVM Extensions (php[tek] 2016)
Diving into HHVM Extensions (php[tek] 2016)James Titcumb
 
ZeroMQ Is The Answer
ZeroMQ Is The AnswerZeroMQ Is The Answer
ZeroMQ Is The AnswerIan Barber
 
Generated Power: PHP 5.5 Generators
Generated Power: PHP 5.5 GeneratorsGenerated Power: PHP 5.5 Generators
Generated Power: PHP 5.5 GeneratorsMark Baker
 
Observability with Consul Connect
Observability with Consul ConnectObservability with Consul Connect
Observability with Consul ConnectBram Vogelaar
 
ZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made SimpleZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made SimpleIan Barber
 
Ten modules I haven't yet talked about
Ten modules I haven't yet talked aboutTen modules I haven't yet talked about
Ten modules I haven't yet talked aboutacme
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Kang-min Liu
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalabilityWim Godden
 
Puppet and the HashiStack
Puppet and the HashiStackPuppet and the HashiStack
Puppet and the HashiStackBram Vogelaar
 
Using ngx_lua in UPYUN
Using ngx_lua in UPYUNUsing ngx_lua in UPYUN
Using ngx_lua in UPYUNCong Zhang
 
Fewer cables
Fewer cablesFewer cables
Fewer cablesacme
 

La actualidad más candente (20)

PHP 7 – What changed internally? (Forum PHP 2015)
PHP 7 – What changed internally? (Forum PHP 2015)PHP 7 – What changed internally? (Forum PHP 2015)
PHP 7 – What changed internally? (Forum PHP 2015)
 
How to stand on the shoulders of giants
How to stand on the shoulders of giantsHow to stand on the shoulders of giants
How to stand on the shoulders of giants
 
Triple Blitz Strike
Triple Blitz StrikeTriple Blitz Strike
Triple Blitz Strike
 
The promise of asynchronous php
The promise of asynchronous phpThe promise of asynchronous php
The promise of asynchronous php
 
How CPAN Testers helped me improve my module
How CPAN Testers helped me improve my moduleHow CPAN Testers helped me improve my module
How CPAN Testers helped me improve my module
 
Gun make
Gun makeGun make
Gun make
 
ZeroMQ Is The Answer: DPC 11 Version
ZeroMQ Is The Answer: DPC 11 VersionZeroMQ Is The Answer: DPC 11 Version
ZeroMQ Is The Answer: DPC 11 Version
 
Diving into HHVM Extensions (php[tek] 2016)
Diving into HHVM Extensions (php[tek] 2016)Diving into HHVM Extensions (php[tek] 2016)
Diving into HHVM Extensions (php[tek] 2016)
 
ZeroMQ Is The Answer
ZeroMQ Is The AnswerZeroMQ Is The Answer
ZeroMQ Is The Answer
 
Generated Power: PHP 5.5 Generators
Generated Power: PHP 5.5 GeneratorsGenerated Power: PHP 5.5 Generators
Generated Power: PHP 5.5 Generators
 
Observability with Consul Connect
Observability with Consul ConnectObservability with Consul Connect
Observability with Consul Connect
 
ZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made SimpleZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made Simple
 
Ten modules I haven't yet talked about
Ten modules I haven't yet talked aboutTen modules I haven't yet talked about
Ten modules I haven't yet talked about
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
 
Puppet and the HashiStack
Puppet and the HashiStackPuppet and the HashiStack
Puppet and the HashiStack
 
Using ngx_lua in UPYUN
Using ngx_lua in UPYUNUsing ngx_lua in UPYUN
Using ngx_lua in UPYUN
 
Solr @ Etsy - Apache Lucene Eurocon
Solr @ Etsy - Apache Lucene EuroconSolr @ Etsy - Apache Lucene Eurocon
Solr @ Etsy - Apache Lucene Eurocon
 
High Performance tDiary
High Performance tDiaryHigh Performance tDiary
High Performance tDiary
 
Fewer cables
Fewer cablesFewer cables
Fewer cables
 

Similar a Trading with opensource tools, two years later

(DEV305) Building Apps with the AWS SDK for PHP | AWS re:Invent 2014
(DEV305) Building Apps with the AWS SDK for PHP | AWS re:Invent 2014(DEV305) Building Apps with the AWS SDK for PHP | AWS re:Invent 2014
(DEV305) Building Apps with the AWS SDK for PHP | AWS re:Invent 2014Amazon Web Services
 
Php my sql - functions - arrays - tutorial - programmerblog.net
Php my sql - functions - arrays - tutorial - programmerblog.netPhp my sql - functions - arrays - tutorial - programmerblog.net
Php my sql - functions - arrays - tutorial - programmerblog.netProgrammer Blog
 
Adding 1.21 Gigawatts to Applications with RabbitMQ (PHPNW Dec 2014 Meetup)
Adding 1.21 Gigawatts to Applications with RabbitMQ (PHPNW Dec 2014 Meetup)Adding 1.21 Gigawatts to Applications with RabbitMQ (PHPNW Dec 2014 Meetup)
Adding 1.21 Gigawatts to Applications with RabbitMQ (PHPNW Dec 2014 Meetup)James Titcumb
 
OSMC 2014: Monitoring VoIP Systems | Sebastian Damm
OSMC 2014: Monitoring VoIP Systems | Sebastian DammOSMC 2014: Monitoring VoIP Systems | Sebastian Damm
OSMC 2014: Monitoring VoIP Systems | Sebastian DammNETWAYS
 
Monitoring VoIP Systems
Monitoring VoIP SystemsMonitoring VoIP Systems
Monitoring VoIP Systemssipgate
 
Power shell voor developers
Power shell voor developersPower shell voor developers
Power shell voor developersDennis Vroegop
 
Writing Modular Command-line Apps with App::Cmd
Writing Modular Command-line Apps with App::CmdWriting Modular Command-line Apps with App::Cmd
Writing Modular Command-line Apps with App::CmdRicardo Signes
 
Stack kicker devopsdays-london-2013
Stack kicker devopsdays-london-2013Stack kicker devopsdays-london-2013
Stack kicker devopsdays-london-2013Simon McCartney
 
PHP Performance Trivia
PHP Performance TriviaPHP Performance Trivia
PHP Performance TriviaNikita Popov
 
Dirty Secrets of the PHP SOAP Extension
Dirty Secrets of the PHP SOAP ExtensionDirty Secrets of the PHP SOAP Extension
Dirty Secrets of the PHP SOAP ExtensionAdam Trachtenberg
 
Internationalizing CakePHP Applications
Internationalizing CakePHP ApplicationsInternationalizing CakePHP Applications
Internationalizing CakePHP ApplicationsPierre MARTIN
 
fog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the Cloudfog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the CloudWesley Beary
 
MongoDB Chicago - MapReduce, Geospatial, & Other Cool Features
MongoDB Chicago - MapReduce, Geospatial, & Other Cool FeaturesMongoDB Chicago - MapReduce, Geospatial, & Other Cool Features
MongoDB Chicago - MapReduce, Geospatial, & Other Cool Featuresajhannan
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryTatsuhiko Miyagawa
 
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)Wesley Beary
 
When symfony met promises
When symfony met promises When symfony met promises
When symfony met promises Marc Morera
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Masahiro Nagano
 

Similar a Trading with opensource tools, two years later (20)

(DEV305) Building Apps with the AWS SDK for PHP | AWS re:Invent 2014
(DEV305) Building Apps with the AWS SDK for PHP | AWS re:Invent 2014(DEV305) Building Apps with the AWS SDK for PHP | AWS re:Invent 2014
(DEV305) Building Apps with the AWS SDK for PHP | AWS re:Invent 2014
 
Php my sql - functions - arrays - tutorial - programmerblog.net
Php my sql - functions - arrays - tutorial - programmerblog.netPhp my sql - functions - arrays - tutorial - programmerblog.net
Php my sql - functions - arrays - tutorial - programmerblog.net
 
Adding 1.21 Gigawatts to Applications with RabbitMQ (PHPNW Dec 2014 Meetup)
Adding 1.21 Gigawatts to Applications with RabbitMQ (PHPNW Dec 2014 Meetup)Adding 1.21 Gigawatts to Applications with RabbitMQ (PHPNW Dec 2014 Meetup)
Adding 1.21 Gigawatts to Applications with RabbitMQ (PHPNW Dec 2014 Meetup)
 
OSMC 2014: Monitoring VoIP Systems | Sebastian Damm
OSMC 2014: Monitoring VoIP Systems | Sebastian DammOSMC 2014: Monitoring VoIP Systems | Sebastian Damm
OSMC 2014: Monitoring VoIP Systems | Sebastian Damm
 
Monitoring VoIP Systems
Monitoring VoIP SystemsMonitoring VoIP Systems
Monitoring VoIP Systems
 
Power shell voor developers
Power shell voor developersPower shell voor developers
Power shell voor developers
 
Writing Modular Command-line Apps with App::Cmd
Writing Modular Command-line Apps with App::CmdWriting Modular Command-line Apps with App::Cmd
Writing Modular Command-line Apps with App::Cmd
 
Stack kicker devopsdays-london-2013
Stack kicker devopsdays-london-2013Stack kicker devopsdays-london-2013
Stack kicker devopsdays-london-2013
 
PHP Performance Trivia
PHP Performance TriviaPHP Performance Trivia
PHP Performance Trivia
 
Dirty Secrets of the PHP SOAP Extension
Dirty Secrets of the PHP SOAP ExtensionDirty Secrets of the PHP SOAP Extension
Dirty Secrets of the PHP SOAP Extension
 
Nubilus Perl
Nubilus PerlNubilus Perl
Nubilus Perl
 
Internationalizing CakePHP Applications
Internationalizing CakePHP ApplicationsInternationalizing CakePHP Applications
Internationalizing CakePHP Applications
 
fog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the Cloudfog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the Cloud
 
DataMapper
DataMapperDataMapper
DataMapper
 
MongoDB Chicago - MapReduce, Geospatial, & Other Cool Features
MongoDB Chicago - MapReduce, Geospatial, & Other Cool FeaturesMongoDB Chicago - MapReduce, Geospatial, & Other Cool Features
MongoDB Chicago - MapReduce, Geospatial, & Other Cool Features
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
 
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
 
When symfony met promises
When symfony met promises When symfony met promises
When symfony met promises
 
Mojo as a_client
Mojo as a_clientMojo as a_client
Mojo as a_client
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
 

Más de clkao

Open Source, Open Data, Open Government
Open Source, Open Data, Open GovernmentOpen Source, Open Data, Open Government
Open Source, Open Data, Open Governmentclkao
 
Websockets at tossug
Websockets at tossugWebsockets at tossug
Websockets at tossugclkao
 
"Lego Programming" with Lorzy
"Lego Programming" with Lorzy"Lego Programming" with Lorzy
"Lego Programming" with Lorzyclkao
 
Devel::NYTProf
Devel::NYTProfDevel::NYTProf
Devel::NYTProfclkao
 
Trading With Open Source Tools
Trading With Open Source ToolsTrading With Open Source Tools
Trading With Open Source Toolsclkao
 
Twopenhack08 Fnord
Twopenhack08 FnordTwopenhack08 Fnord
Twopenhack08 Fnordclkao
 
Svk Br Yapceu2008
Svk Br Yapceu2008Svk Br Yapceu2008
Svk Br Yapceu2008clkao
 
prototype::signatures
prototype::signaturesprototype::signatures
prototype::signaturesclkao
 
Leon & Andrea
Leon & AndreaLeon & Andrea
Leon & Andreaclkao
 

Más de clkao (9)

Open Source, Open Data, Open Government
Open Source, Open Data, Open GovernmentOpen Source, Open Data, Open Government
Open Source, Open Data, Open Government
 
Websockets at tossug
Websockets at tossugWebsockets at tossug
Websockets at tossug
 
"Lego Programming" with Lorzy
"Lego Programming" with Lorzy"Lego Programming" with Lorzy
"Lego Programming" with Lorzy
 
Devel::NYTProf
Devel::NYTProfDevel::NYTProf
Devel::NYTProf
 
Trading With Open Source Tools
Trading With Open Source ToolsTrading With Open Source Tools
Trading With Open Source Tools
 
Twopenhack08 Fnord
Twopenhack08 FnordTwopenhack08 Fnord
Twopenhack08 Fnord
 
Svk Br Yapceu2008
Svk Br Yapceu2008Svk Br Yapceu2008
Svk Br Yapceu2008
 
prototype::signatures
prototype::signaturesprototype::signatures
prototype::signatures
 
Leon & Andrea
Leon & AndreaLeon & Andrea
Leon & Andrea
 

Último

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 

Último (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 

Trading with opensource tools, two years later

  • 1. Trading with open source tools two years later Chia-liang Kao clkao@clkao.org OSDC.TW 2011 Taipei
  • 2. 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
  • 3. The OSDC Trading System (in 2009 talk)
  • 4. Risk = controlled by you Profit = probabilities
  • 5. Automated Trading Components quote strategy order (via broker)
  • 6. bayen 2010 results 40.15% net, end of year (Not with dice!)
  • 8. quote memcached strategy GeniusTrader jsonrpc order pos: +1, -1, 0 (via broker)
  • 10. 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
  • 11. 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 EC2 moved to AnyMQ
  • 12. Quote • Source • Commercial Quote services • Win32::DDE • AnyMQ • AnyEvent::Monitor • Price AGgregation Manager: serve history and manages real time quotes
  • 13. Source • was running on MicroXP in VirtualBox • now on EC2 win32 instances • Republish to rabbitmq with AnyMQ
  • 14. AnyMQ • inspired by Tatsumaki::MessageQueue • Use Moose traits • Available on CPAN • can talk to amqp servers like rabbitmq
  • 15. 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)
  • 16. 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)
  • 17. AnyMQ with AMQP 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) 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)
  • 18. Service monitoring • Is it running? • Can we fix it when it fails?
  • 19. 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"; } });
  • 20. 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 }
  • 21. Strategy • the core that decides: • when to buy/sell? • how much to buy/sell? • when to stop loss, take profit? • Finance::GeniusTrader • TradeSpring
  • 22. Finance::GeniusTrader • DSL for trade systems SY: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
  • 24. ++
  • 25. (Second largest profit this year was on 3/15, went to Japan Red Cross Society)
  • 26. 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?
  • 27. TradeSpring method 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
  • 28. TradeSpring examples method 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
  • 29. 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
  • 30. EC2 • multiple az • ap-southeast-1 latency: 60ms • ap-northeast-1 latency: 40ms • (to broker endpoint) • multiple region
  • 31. 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
  • 33. Analysis •R • protovis • ask interesting questions and check your records!
  • 34. Trade result breakdown by time and day of week
  • 35. 2011 results YOD ? ? 10% of profit will go to TPF