From listbox+trampoline+Q4+EFZ7+jDFcU-Kg4BG-g46ndgNjPQ+BqUXUH@jeeves.archives.listbox.com  Mon Jun 27 13:22:40 2011
Received: from mx2.cims.nyu.edu (mx2.cims.nyu.edu [128.122.49.96])
	by mail.cims.nyu.edu (8.14.4+Sun/8.14.4) with ESMTP id p5RHMdr2017980
	for <shasha@mail.cims.nyu.edu>; Mon, 27 Jun 2011 13:22:39 -0400 (EDT)
Received: from b-lb-ob-sd.listbox.com (b-lb-ob-sd.listbox.com [64.74.157.83])
	by mx2.cims.nyu.edu (8.14.4+Sun/8.14.4) with ESMTP id p5RHMVKW021813
	for <shasha@cs.nyu.edu>; Mon, 27 Jun 2011 13:22:31 -0400 (EDT)
Received: from b-lb-ob-sd.listbox.com (localhost [127.0.0.1])
	by b-lb-ob-sd.listbox.com (Postfix) with ESMTP id E3A12664
	for <shasha@cs.nyu.edu>; Mon, 27 Jun 2011 13:24:19 -0400 (EDT)
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=listbox.com; h=
	mime-version:in-reply-to:references:date:message-id:subject:from
	:to:content-type:reply-to:list-id:list-help:list-unsubscribe
	:list-subscribe; s=launch; bh=VIQQlqZXIL0nGs2PBcBZrbLPy6w=; b=QO
	5WB+rlupgTlRV9U1aCm4jZViPegqFeEq4kHVpKUz6Q7UW5WSFuy54GDZ5Ga5LGjc
	Ff4YUr3ztQFO7Bbf46Bw==
Received: from b-lb-ex-sd.listbox.com (b-lb-ex-sd.listbox.com [64.74.157.87])
	by b-lb-ob-sd.listbox.com (Postfix) with ESMTP id E0ABA663
	for <shasha@cs.nyu.edu>; Mon, 27 Jun 2011 13:24:19 -0400 (EDT)
Received: from localhost.localdomain (localhost [127.0.0.1])
	by b-lb-ex-sd.listbox.com (Postfix) with ESMTP id D49D66BE
	for <shasha@cs.nyu.edu>; Mon, 27 Jun 2011 13:24:19 -0400 (EDT)
Received: from a-lb-mx-sd.listbox.com (a-lb-mx-sd.listbox.com [64.74.157.95])
 by a-lb-arc-quonix.listbox.com (Postfix) with ESMTP id 2871821623 for
 <k4@listbox.com.email.enqueue.archive.listbox.com>; Mon, 27 Jun 2011 13:22:23
 -0400 (EDT)
Received: from localhost.localdomain (localhost [127.0.0.1]) by
 a-lb-mx-sd.listbox.com (Postfix) with ESMTP id BDD764516 for
 <k4@listbox.com.email.enqueue.archive.listbox.com>; Mon, 27 Jun 2011 13:24:34
 -0400 (EDT)
Received: from mail-ww0-f49.google.com (mail-ww0-f49.google.com
 [74.125.82.49]) by a-lb-mx-sd.listbox.com (Postfix) with ESMTP id 5E3DC4514
 for <k4@listbox.com>; Mon, 27 Jun 2011 13:24:32 -0400 (EDT)
Received: by wwf22 with SMTP id 22so3953535wwf.30 for <k4@listbox.com>; Mon,
 27 Jun 2011 10:22:19 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.216.53.203 with SMTP id g53mr2763317wec.13.1309195339444;
 Mon, 27 Jun 2011 10:22:19 -0700 (PDT)
Received: by 10.216.17.15 with HTTP; Mon, 27 Jun 2011 10:22:19 -0700 (PDT)
In-Reply-To: <EC2DEEB45E29704598803D850ED325660E185AA7@hkgex01.mwam.local>
References:
 <9A358A2339B7254BA234E70D74C073BD7180F9EE6B@MSGRTPCCRE2WIN.DMN1.FMR.COM>
 <30983968.13610.1308752255204.JavaMail.root@mail1.suntradingllc.com>
 <BANLkTinBGp=fdJnbm_jif5CTsJJTN168Pw@mail.gmail.com>
 <BANLkTi=23DD0K1tXeDCpeQYx1e0A0F=yGw@mail.gmail.com>
 <EC2DEEB45E29704598803D850ED325660E185AA7@hkgex01.mwam.local>
Date: Mon, 27 Jun 2011 10:22:19 -0700
Message-ID: <BANLkTik5F=Hi4gptmamvKgjO1sJVu1Xz8w@mail.gmail.com>
Subject: Re: [k4] Crossing Thresholds Problem
From: Arthur Whitney <arthur@kx.com>
To: "k4" <k4@listbox.com>
Content-Type: multipart/alternative; boundary=0016e6de04642632c404a6b4cbed
Reply-To: k4@listbox.com
List-ID: <k4@listbox.com>
X-Listbox-List-ID: 1080 <k4@listbox.com>
List-Software: listbox.com v2.0
List-Help: <http://www.listbox.com/subscription-help.html>
List-Unsubscribe: <mailto:unsubscribe-k4@listbox.com>,
 <https://www.listbox.com/unsubscribe/?member_id=901033&id_secret=901033-6a517507&post_id=20110627132225:535C318C-A0E2-11E0-BE83-8EA77603633D>
List-Subscribe: <mailto:subscribe-k4@listbox.com>,
 <http://www.listbox.com/subscribe/?list_id=1080>
X-Listbox-Post-Id: 20110627132225:535C318C-A0E2-11E0-BE83-8EA77603633D
X-Listbox-Original-Sender: Arthur Whitney <arthur@kx.com>
Errors-To:  listbox+trampoline+Q4+EFZ7+jDFcU-Kg4BG-g46ndgNjPQ+BqUXUH@jeeves.archives.listbox.com
X-Scanned-By: MIMEDefang 2.71 on 128.122.49.96
X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.2.6 (mx2.cims.nyu.edu [128.122.49.96]); Mon, 27 Jun 2011 13:22:39 -0400 (EDT)
Status: RO
Content-Length: 4015


--0016e6de04642632c404a6b4cbed
Content-Type: text/plain; charset=ISO-8859-1

>p:10 11 12 12 13 14 13 11 9 5 5 5 4 3 5 6 7 8 9 10
>entry 12. exit 6.

this can be solved 12 times faster with a state transition matrix
(or 60 times faster if inputs are already dense integer), e.g.

http://kx.com/q/state.q

/ input p. entry 12. exit 6.
p:10 11 12 12 13 14 13 11 9 5 5 5 4 3 5 6 7 8 9 10 12
0+0b{$[x;y>6;y>11]}\p

/ state transition matrix for all possible inputs
m:0+11 6<\:til 20
0 m\p

/ or translate to inputs 0(exit) 1(no op) 2(entry)
0(0 0 1;0 1 1)\1+(p>11)-p<7

p:1000000#p
\t 0b{$[x;y>6;y>11]}\p
\t 0 m\p
\t 0(0 0 1;0 1 1)\1+(p>11)-p<7



On Fri, Jun 24, 2011 at 1:22 AM, Hui Li <H.Li@mwam.com> wrote:

> An different version of Attila's solution by moving the comparison
> inside the function:
>
> {$[x;y>5;y>=12]}\[0b;a]
>
>
> There s a bit of speed up as well:
> a:10000000?100
>
> q)\t av:{$[x;z;y]<>x}\[0b;a>=12;a<=5]
> 6710
>
> q)\t hl:{x:$[x;y>5;y>=12]}\[0b;a]
> 3819
>
> q)av~hl
> 1b
>
>
>
> Kind regards,
> Hui
>
>
>
> ---------- Forwarded message ----------
> From: Attila Vrabecz <attila.vrabecz@gmail.com>
> Date: Wed, Jun 22, 2011 at 3:41 PM
> Subject: Re: [k4] Crossing Thresholds Problem
> To: k4 <k4@listbox.com>
>
>
>
> {$[x;z;y]<>x}\[0b;p>=12;p<=5]   /position, enter, exit
>  Attila
>
>
>
> On Wed, Jun 22, 2011 at 3:17 PM, Andrius Paulius
> <apaulius@suntradingllc.com> wrote:
>
>
>        I actually have my prices in a table.. along with other fields..
> how would that change this implementation?
>        i Do not want to lose tha tother information
>
>
>
>        ----- Original Message -----
>        From: Jan Roczniak <Jan.Roczniak@fmr.com>
>        To: k4 <k4@listbox.com>
>
>        Sent: Wed, 22 Jun 2011 09:07:36 -0500 (CDT)
>        Subject: RE: [k4] Crossing Thresholds Problem
>
>
>
>        // data:
>
>        p:10 11 12 12 13 14 13 11 9 5 5 5 4 3 5 6 7 8 9 10
>        12
>
>        pp:6 // stop
>
>        ps:12 // start
>
>        // find where prices are in a bracket
>
>        q)w1:((),pp,ps) bin p
>
>        q)w1
>
>        0 0 1 1 1 1 1 0 0 -1 -1 -1 -1 -1 -1 0 0 0 0 0
>        1
>
>        // compute each bracket indexes
>
>        q)ws:where (((),pp,ps) bin p) = 1
>
>        q)wp:where (((),pp,ps) bin p) =-1
>
>        q)ws
>
>        2 3 4 5 6 20
>
>        q)wp
>
>        9 10 11 12 13 14
>
>        // discover action points
>
>        q)ws[where (deltas ws)>1]
>
>        2 20
>
>        q)wp[where (deltas wp)>1]
>
>        ,9
>
>
>
>
>
> ________________________________
>
>                From: Andrius Paulius
>                  [mailto:apaulius@suntradingllc.com]
>                Sent: Wednesday, June 22, 2011
>                  9:09 AM
>                To: k4
>                Subject: [k4] Crossing Thresholds
>                  Problem
>
>
>                I have come up with a non-elegant solution to simulating
> trades in
>                  the market when a price point goes over a certain
> threshold and exiting when
>                  it goes below another threshold but am wondeirng if
> there is some easier way
>                  to do this.
>
>                for example
>
>                prices in sequence are:
>
>                p:10 11
>                  12 12 13 14 13 11 9 5 5 5 4 3 5 6 7 8 9 10
>                  12
>                pEntry:12
>                pExit:6;
>
>                My entry price is 12, so i get in on the
>                  third tick, i want to only treat this as my lone entry
> for this trade until i
>                  get to my closing point
>
>                My closing price is say 6, so when the 10th
>                  tick is reached (5) i would close the trade, i would
> reopen on the last tick
>                  and etc..
>
>                My current solution uses some complex boolean logic but
> i
>                  have to imagine there is a simpler way or something
> build it to help with this
>                  problem.
>
>                Any help is appreciated thanks..
>

