Learning Kdb+/q

never design a trading system without proper prior analysis. post your market statistics here

Moderator: moderators

frang0nve
rank: 150+ posts
rank: 150+ posts
Posts: 198
Joined: Thu Apr 09, 2009 7:57 pm
Reputation: 0
Gender: Male

Postby frang0nve » Wed Jun 13, 2012 5:23 am

Hello:

As we'll need using the Open value from Weekly table in Daily table we have to use a different name to avoid problems, so we'll use W_Open.


[font=Courier New]EU_W1:update W_Open:Open from EU_W1
EU_W1:delete Open from EU_W1[/font]

The table with the new column name:





Cheers

Please add www.kreslik.com to your ad blocker white list.
Thank you for your support.

frang0nve
rank: 150+ posts
rank: 150+ posts
Posts: 198
Joined: Thu Apr 09, 2009 7:57 pm
Reputation: 0
Gender: Male

Postby frang0nve » Thu Jun 14, 2012 5:35 am

Now we'll add the open data from the weekly table into the daily table using this command:

[font=Courier New]EU_D1:aj[`datetime;EU_D1;EU_W1][/font]

This is the daily table with weekly data:

Image



Cheers

Thanks to Charles Skelton and many others in Kdb+ Personal Developers Forum.
Last edited by frang0nve on Tue Jun 19, 2012 4:37 am, edited 3 times in total.

frang0nve
rank: 150+ posts
rank: 150+ posts
Posts: 198
Joined: Thu Apr 09, 2009 7:57 pm
Reputation: 0
Gender: Male

Postby frang0nve » Fri Jun 15, 2012 9:12 pm

Hello,

We'll add a column to the Daily Data Table containing the weekday (0:Sat, 1:Sun,..., 6:Fri) with this command:

[font=Courier New]EU_D1: update Weekday:datetime mod 7 from EU_D1[/font]


Now we need to find the entry points for green rats (buyers):

The first tick (and only the first tick) every day presenting these conditions:
NewRat=1 (Daily Data Table)
askprice>=EntryLevel (Tick Data Table, Daily Data Table)
EntryLevel > Weekly Open (Daily Data Table)
Weekday: Monday, Tuesday, Wednesday, Thursday, Friday (broker allowing trading 24/7)

We'll add a column to the daily table to find out when a buy order should be issued:


[font=Courier New]EU_D1: update NewGreenRat:1 from EU_D1 where NewRat=1,EntryLevel>W_Open,Weekday within (2;6)[/font]


Then Red Rats need these conditions to short:

The first tick (and only the first tick) every day presenting these conditions:
NewRat=-1 (Daily Data Table)
bidprice<=EntryLevel (Tick Data Table, Daily Data Table)
EntryLevel < Weekly Open (Daily Data Table)
Weekday: Monday, Tuesday, Wednesday, Thursday, Friday (broker allowing trading 24/7)

We'll add a column to the daily table to find out when a sell order should be issued:

[font=Courier New]EU_D1: update NewRedRat:1 from EU_D1 where NewRat=-1,EntryLevel<W_Open,Weekday within (2;6)[/font]

The resulting daily table:

Image

Cheers

Thanks to Rory O'Rorke, effbiae, Aaron Davies and many others from Kdb+ Personal Developers forum.
Last edited by frang0nve on Fri Jul 20, 2012 2:12 am, edited 2 times in total.

frang0nve
rank: 150+ posts
rank: 150+ posts
Posts: 198
Joined: Thu Apr 09, 2009 7:57 pm
Reputation: 0
Gender: Male

Postby frang0nve » Sun Jun 17, 2012 5:34 am

Now we'll add NewGreenRat, NewRedRat, EntryLevel, SLLevel columns to the tick table. To do so we build and auxiliary table (EU_D1_S) only with the required columns:

[font=Courier New]EU_D1_S: select datetime,NewGreenRat,NewRedRat,EntryLevel,SLLevel from EU_D1[/font]

This is the auxiliary table:

Image

Now we'll add those columns to the tick table:

[font=Courier New]EU:aj[`datetime;EU;EU_D1_S][/font]

Resulting this table:

Image

frang0nve
rank: 150+ posts
rank: 150+ posts
Posts: 198
Joined: Thu Apr 09, 2009 7:57 pm
Reputation: 0
Gender: Male

Postby frang0nve » Sun Jun 17, 2012 7:46 am

Hello,

This step could be done earlier, but I forgot...

We'll add a column in the tickdata table with the date:

[font=Courier New]EU:update Date:datetime.date from EU[/font]

Image

And in the daily table using date format instead of datetime format:

[font=Courier New]EU_D1:update Date:datetime.date from EU_D1[/font]

Image




Now we need to find the ticks when trades are triggered:

For green rats The first tick in a day complying:
NewGreenRat=1
askprice>=EntryLevel

We'll add the column GreenEntry to show the buying ticks


[font=Courier New]EU:update GreenEntry:1 from (update f:(first i where askprice>=EntryLevel) by Date from EU lj `Date xkey select Date,NewGreenRat,EntryLevel from EU_D1) where NewGreenRat=1,f=i[/font]

This is a sparsely populated column in a tick data table, so we can select only the rows holding entry conditions:

[font=Courier New]EU_Green:select from EU where GreenEntry=1[/font]

Image

For red rats The first tick in a day complying:
NewRedRat=1
bidprice<=EntryLevel

We'll add the column RedEntry to show the selling ticks

[font=Courier New]EU:update RedEntry:1 from (update g:(first i where bidprice<=EntryLevel) by Date from EU lj `Date xkey select Date,NewRedRat,EntryLevel from EU_D1) where NewRedRat=1,g=i[/font]


This is also a sparsely populated column in a tick data table, so we can select only the rows holding entry conditions:

[font=Courier New]EU_Red:select from EU where RedEntry=1[/font]

Image

Cheers

Thanks to Max_18 and many others in Kdb+ Personal Developers forum.
Last edited by frang0nve on Wed Jun 20, 2012 3:38 am, edited 2 times in total.

Please add www.kreslik.com to your ad blocker white list.
Thank you for your support.

frang0nve
rank: 150+ posts
rank: 150+ posts
Posts: 198
Joined: Thu Apr 09, 2009 7:57 pm
Reputation: 0
Gender: Male

Postby frang0nve » Tue Jun 19, 2012 5:05 am

Hello,

I've found some free GUI tools to help writing code in q:

Studio For Kdb+

Qclient

Eclipse + QKDT

I've just started to test Studio For Kdb+ and it's very useful with its charting feature!





Cheers

Please add www.kreslik.com to your ad blocker white list.
Thank you for your support.


Return to “statistics”