Support security lookup #215

Closed
Kevin-Jin opened this Issue Feb 11, 2017 · 12 comments

Comments

Projects
None yet
5 participants
@Kevin-Jin
Contributor

Kevin-Jin commented Feb 11, 2017

Something equivalent to the MATLAB lookup() function would be nice. Basically I would like to automate the task of typing the TK or SECF command into Bloomberg Terminal. According to the Bloomberg API Developer Guide section 7.10.1, it looks like the C code would look like:

Service secfService = session.getService("//blp/instruments");
Request request = secfService.createRequest("instrumentListRequest");
request.asElement().setElement("query", "IBM");
request.asElement().setElement("yellowKeyFilter", "YK_FILTER_CORP");
request.asElement().setElement("languageOverride", "LANG_OVERRIDE_NONE");
request.asElement().setElement("maxResults", 10);
sendRequest(request, session);

@Kevin-Jin Kevin-Jin changed the title from Support to Support security lookup Feb 11, 2017

@Kevin-Jin Kevin-Jin referenced this issue Feb 11, 2017

Open

BSRCH #186

@armstrtw

This comment has been minimized.

Show comment
Hide comment
@armstrtw

armstrtw Feb 11, 2017

Contributor

Can you submit a patch for this. It seems pretty straightforward.

Contributor

armstrtw commented Feb 11, 2017

Can you submit a patch for this. It seems pretty straightforward.

@Kevin-Jin

This comment has been minimized.

Show comment
Hide comment
@Kevin-Jin

Kevin-Jin Feb 11, 2017

Contributor

I'm having issues with building from source on Windows that look related to #164 (comment). If I can resolve them, then I'll give this a shot.

Contributor

Kevin-Jin commented Feb 11, 2017

I'm having issues with building from source on Windows that look related to #164 (comment). If I can resolve them, then I'll give this a shot.

@eddelbuettel

This comment has been minimized.

Show comment
Hide comment
@eddelbuettel

eddelbuettel Feb 11, 2017

Member

If you are having long long issues one easy workaround is to make sure the project is building as a C++11 compilations -- as C++11 gives us the long long which C++98 did not have. We do have this is src/Makevars{,.win} : CXX_STD = CXX11 so it should all be peachy.

Member

eddelbuettel commented Feb 11, 2017

If you are having long long issues one easy workaround is to make sure the project is building as a C++11 compilations -- as C++11 gives us the long long which C++98 did not have. We do have this is src/Makevars{,.win} : CXX_STD = CXX11 so it should all be peachy.

@armstrtw

This comment has been minimized.

Show comment
Hide comment
@armstrtw

armstrtw Feb 11, 2017

Contributor

I suggest you build on Linux. Good luck.

Contributor

armstrtw commented Feb 11, 2017

I suggest you build on Linux. Good luck.

@eddelbuettel eddelbuettel closed this in #216 Feb 12, 2017

eddelbuettel added a commit that referenced this issue Feb 12, 2017

Merge pull request #216 from Kevin-Jin/master
Add support for security lookup (resolves #215)
@joel23888

This comment has been minimized.

Show comment
Hide comment
@joel23888

joel23888 Apr 25, 2017

Contributor

I implemented a similar function to do security lookup (sorry I could not share it as I cannot push to GH). One additional thing I found useful was to run regex on the security column returned to convert it to a proper BBG code, as opposed to what the BBG API returns. If you want to add it, try using base::sub with pattern="^(.+)<(.)(.+)>$", replacement="\\1 \\U\\2\\E\\3" and perl=TRUE.

Contributor

joel23888 commented Apr 25, 2017

I implemented a similar function to do security lookup (sorry I could not share it as I cannot push to GH). One additional thing I found useful was to run regex on the security column returned to convert it to a proper BBG code, as opposed to what the BBG API returns. If you want to add it, try using base::sub with pattern="^(.+)<(.)(.+)>$", replacement="\\1 \\U\\2\\E\\3" and perl=TRUE.

@eddelbuettel

This comment has been minimized.

Show comment
Hide comment
@eddelbuettel

eddelbuettel Apr 25, 2017

Member

As in

R> res <- lookupSecurity("IBM", "mtge")
R> base::sub(pattern="^(.+)<(.)(.+)>$", "\\1 \\U\\2\\E\\3", perl=TRUE, res$security)
[1] "IBM Mtge"   "IBMMT Mtge"
R> 

That's nice.

Now we have of course "a published API" so we ought be careful about changes. Maybe add as a new third column?

Member

eddelbuettel commented Apr 25, 2017

As in

R> res <- lookupSecurity("IBM", "mtge")
R> base::sub(pattern="^(.+)<(.)(.+)>$", "\\1 \\U\\2\\E\\3", perl=TRUE, res$security)
[1] "IBM Mtge"   "IBMMT Mtge"
R> 

That's nice.

Now we have of course "a published API" so we ought be careful about changes. Maybe add as a new third column?

@joel23888

This comment has been minimized.

Show comment
Hide comment
@joel23888

joel23888 Apr 25, 2017

Contributor

Yes, that's right (and I tidied up my initial comment on this to make the intent clearer). I would agree it is better to add a column in this case.

Contributor

joel23888 commented Apr 25, 2017

Yes, that's right (and I tidied up my initial comment on this to make the intent clearer). I would agree it is better to add a column in this case.

@eddelbuettel

This comment has been minimized.

Show comment
Hide comment
@eddelbuettel

eddelbuettel Apr 25, 2017

Member

Oh, and as for

sorry I could not share it as I cannot push to GH

that is normal -- only the three of us can. GitHub works by you "forking", making the change in what is now your version and then submitting a so-called "pull request" back to us in order to get the change merged. Works well, millions of tutorials out there. Try it next time.

Member

eddelbuettel commented Apr 25, 2017

Oh, and as for

sorry I could not share it as I cannot push to GH

that is normal -- only the three of us can. GitHub works by you "forking", making the change in what is now your version and then submitting a so-called "pull request" back to us in order to get the change merged. Works well, millions of tutorials out there. Try it next time.

@joel23888

This comment has been minimized.

Show comment
Hide comment
@joel23888

joel23888 Apr 25, 2017

Contributor
Contributor

joel23888 commented Apr 25, 2017

@eddelbuettel

This comment has been minimized.

Show comment
Hide comment
@eddelbuettel

eddelbuettel Apr 25, 2017

Member

In a fuller example now at work:

R> res <- lookupSecurity("SNAP")
R> res
                       security                           description
1               SNAP US<equity>                       Snap Inc (U.S.)
2               SNAP UN<equity>                   Snap Inc (New York)
3                SNA US<equity>                    Snap-on Inc (U.S.)
4  SNAP US 01/19/18 P15<equity>  January 18 Puts on SNAP US Strike 15
5  SNAP US 07/21/17 P20<equity>     July 17 Puts on SNAP US Strike 20
6  SNAP US 01/18/19 C30<equity> January 19 Calls on SNAP US Strike 30
7  SNAP US 05/19/17 P20<equity>      May 17 Puts on SNAP US Strike 20
8  SNAP US 05/19/17 C23<equity>     May 17 Calls on SNAP US Strike 23
9               SNAP SW<equity>                Snap Inc (Switzerland)
10 SNAP US 01/19/18 P13<equity>  January 18 Puts on SNAP US Strike 13
11 SNAP US 01/19/18 C25<equity> January 18 Calls on SNAP US Strike 25
12 SNAP US 01/18/19 P15<equity>  January 19 Puts on SNAP US Strike 15
13 SNAP US 07/21/17 P18<equity>     July 17 Puts on SNAP US Strike 18
14 SNAP US 01/19/18 P20<equity>  January 18 Puts on SNAP US Strike 20
15 SNAP US 07/21/17 P15<equity>     July 17 Puts on SNAP US Strike 15
16 SNAP US 01/19/18 P18<equity>  January 18 Puts on SNAP US Strike 18
17 SNAP US 10/20/17 P15<equity>  October 17 Puts on SNAP US Strike 15
18 SNAP US 04/28/17 P21<equity>    April 17 Puts on SNAP US Strike 21
19 SNAP US 05/19/17 C22<equity>     May 17 Calls on SNAP US Strike 22
20 SNAP US 05/19/17 P19<equity>      May 17 Puts on SNAP US Strike 19
R> res[, "symbol"] <- sub(pattern="^(.+)<(.)(.+)>$", "\\1 \\U\\2\\E\\3", perl=TRUE, res[, "security"])
R> res
                       security                           description                      symbol
1               SNAP US<equity>                       Snap Inc (U.S.)              SNAP US Equity
2               SNAP UN<equity>                   Snap Inc (New York)              SNAP UN Equity
3                SNA US<equity>                    Snap-on Inc (U.S.)               SNA US Equity
4  SNAP US 01/19/18 P15<equity>  January 18 Puts on SNAP US Strike 15 SNAP US 01/19/18 P15 Equity
5  SNAP US 07/21/17 P20<equity>     July 17 Puts on SNAP US Strike 20 SNAP US 07/21/17 P20 Equity
6  SNAP US 01/18/19 C30<equity> January 19 Calls on SNAP US Strike 30 SNAP US 01/18/19 C30 Equity
7  SNAP US 05/19/17 P20<equity>      May 17 Puts on SNAP US Strike 20 SNAP US 05/19/17 P20 Equity
8  SNAP US 05/19/17 C23<equity>     May 17 Calls on SNAP US Strike 23 SNAP US 05/19/17 C23 Equity
9               SNAP SW<equity>                Snap Inc (Switzerland)              SNAP SW Equity
10 SNAP US 01/19/18 P13<equity>  January 18 Puts on SNAP US Strike 13 SNAP US 01/19/18 P13 Equity
11 SNAP US 01/19/18 C25<equity> January 18 Calls on SNAP US Strike 25 SNAP US 01/19/18 C25 Equity
12 SNAP US 01/18/19 P15<equity>  January 19 Puts on SNAP US Strike 15 SNAP US 01/18/19 P15 Equity
13 SNAP US 07/21/17 P18<equity>     July 17 Puts on SNAP US Strike 18 SNAP US 07/21/17 P18 Equity
14 SNAP US 01/19/18 P20<equity>  January 18 Puts on SNAP US Strike 20 SNAP US 01/19/18 P20 Equity
15 SNAP US 07/21/17 P15<equity>     July 17 Puts on SNAP US Strike 15 SNAP US 07/21/17 P15 Equity
16 SNAP US 01/19/18 P18<equity>  January 18 Puts on SNAP US Strike 18 SNAP US 01/19/18 P18 Equity
17 SNAP US 10/20/17 P15<equity>  October 17 Puts on SNAP US Strike 15 SNAP US 10/20/17 P15 Equity
18 SNAP US 04/28/17 P21<equity>    April 17 Puts on SNAP US Strike 21 SNAP US 04/28/17 P21 Equity
19 SNAP US 05/19/17 C22<equity>     May 17 Calls on SNAP US Strike 22 SNAP US 05/19/17 C22 Equity
20 SNAP US 05/19/17 P19<equity>      May 17 Puts on SNAP US Strike 19 SNAP US 05/19/17 P19 Equity
R> 

So @armstrtw @johnlaing : how do we feel about this? Worth it? Or just tuck into the examples section of the help page?

Member

eddelbuettel commented Apr 25, 2017

In a fuller example now at work:

R> res <- lookupSecurity("SNAP")
R> res
                       security                           description
1               SNAP US<equity>                       Snap Inc (U.S.)
2               SNAP UN<equity>                   Snap Inc (New York)
3                SNA US<equity>                    Snap-on Inc (U.S.)
4  SNAP US 01/19/18 P15<equity>  January 18 Puts on SNAP US Strike 15
5  SNAP US 07/21/17 P20<equity>     July 17 Puts on SNAP US Strike 20
6  SNAP US 01/18/19 C30<equity> January 19 Calls on SNAP US Strike 30
7  SNAP US 05/19/17 P20<equity>      May 17 Puts on SNAP US Strike 20
8  SNAP US 05/19/17 C23<equity>     May 17 Calls on SNAP US Strike 23
9               SNAP SW<equity>                Snap Inc (Switzerland)
10 SNAP US 01/19/18 P13<equity>  January 18 Puts on SNAP US Strike 13
11 SNAP US 01/19/18 C25<equity> January 18 Calls on SNAP US Strike 25
12 SNAP US 01/18/19 P15<equity>  January 19 Puts on SNAP US Strike 15
13 SNAP US 07/21/17 P18<equity>     July 17 Puts on SNAP US Strike 18
14 SNAP US 01/19/18 P20<equity>  January 18 Puts on SNAP US Strike 20
15 SNAP US 07/21/17 P15<equity>     July 17 Puts on SNAP US Strike 15
16 SNAP US 01/19/18 P18<equity>  January 18 Puts on SNAP US Strike 18
17 SNAP US 10/20/17 P15<equity>  October 17 Puts on SNAP US Strike 15
18 SNAP US 04/28/17 P21<equity>    April 17 Puts on SNAP US Strike 21
19 SNAP US 05/19/17 C22<equity>     May 17 Calls on SNAP US Strike 22
20 SNAP US 05/19/17 P19<equity>      May 17 Puts on SNAP US Strike 19
R> res[, "symbol"] <- sub(pattern="^(.+)<(.)(.+)>$", "\\1 \\U\\2\\E\\3", perl=TRUE, res[, "security"])
R> res
                       security                           description                      symbol
1               SNAP US<equity>                       Snap Inc (U.S.)              SNAP US Equity
2               SNAP UN<equity>                   Snap Inc (New York)              SNAP UN Equity
3                SNA US<equity>                    Snap-on Inc (U.S.)               SNA US Equity
4  SNAP US 01/19/18 P15<equity>  January 18 Puts on SNAP US Strike 15 SNAP US 01/19/18 P15 Equity
5  SNAP US 07/21/17 P20<equity>     July 17 Puts on SNAP US Strike 20 SNAP US 07/21/17 P20 Equity
6  SNAP US 01/18/19 C30<equity> January 19 Calls on SNAP US Strike 30 SNAP US 01/18/19 C30 Equity
7  SNAP US 05/19/17 P20<equity>      May 17 Puts on SNAP US Strike 20 SNAP US 05/19/17 P20 Equity
8  SNAP US 05/19/17 C23<equity>     May 17 Calls on SNAP US Strike 23 SNAP US 05/19/17 C23 Equity
9               SNAP SW<equity>                Snap Inc (Switzerland)              SNAP SW Equity
10 SNAP US 01/19/18 P13<equity>  January 18 Puts on SNAP US Strike 13 SNAP US 01/19/18 P13 Equity
11 SNAP US 01/19/18 C25<equity> January 18 Calls on SNAP US Strike 25 SNAP US 01/19/18 C25 Equity
12 SNAP US 01/18/19 P15<equity>  January 19 Puts on SNAP US Strike 15 SNAP US 01/18/19 P15 Equity
13 SNAP US 07/21/17 P18<equity>     July 17 Puts on SNAP US Strike 18 SNAP US 07/21/17 P18 Equity
14 SNAP US 01/19/18 P20<equity>  January 18 Puts on SNAP US Strike 20 SNAP US 01/19/18 P20 Equity
15 SNAP US 07/21/17 P15<equity>     July 17 Puts on SNAP US Strike 15 SNAP US 07/21/17 P15 Equity
16 SNAP US 01/19/18 P18<equity>  January 18 Puts on SNAP US Strike 18 SNAP US 01/19/18 P18 Equity
17 SNAP US 10/20/17 P15<equity>  October 17 Puts on SNAP US Strike 15 SNAP US 10/20/17 P15 Equity
18 SNAP US 04/28/17 P21<equity>    April 17 Puts on SNAP US Strike 21 SNAP US 04/28/17 P21 Equity
19 SNAP US 05/19/17 C22<equity>     May 17 Calls on SNAP US Strike 22 SNAP US 05/19/17 C22 Equity
20 SNAP US 05/19/17 P19<equity>      May 17 Puts on SNAP US Strike 19 SNAP US 05/19/17 P19 Equity
R> 

So @armstrtw @johnlaing : how do we feel about this? Worth it? Or just tuck into the examples section of the help page?

@johnlaing

This comment has been minimized.

Show comment
Hide comment
@johnlaing

johnlaing Apr 26, 2017

Contributor

This is clearly useful. At a minimum we could provide a little utility function implementing this regex.

I'm less enthusiastic about tacking on unsolicited modifications/enhancements to returned data. I tend to like leaving the bbg output alone as much as possible, just on principle.

Contributor

johnlaing commented Apr 26, 2017

This is clearly useful. At a minimum we could provide a little utility function implementing this regex.

I'm less enthusiastic about tacking on unsolicited modifications/enhancements to returned data. I tend to like leaving the bbg output alone as much as possible, just on principle.

@eddelbuettel

This comment has been minimized.

Show comment
Hide comment
@eddelbuettel

eddelbuettel Apr 26, 2017

Member

I think I agree on both counts. May just stick it into the example section.

Member

eddelbuettel commented Apr 26, 2017

I think I agree on both counts. May just stick it into the example section.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment