Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getBars - optionally adjust for corporate actions? #47

Closed
joel23888 opened this issue Jul 15, 2015 · 12 comments
Closed

getBars - optionally adjust for corporate actions? #47

joel23888 opened this issue Jul 15, 2015 · 12 comments

Comments

@joel23888
Copy link
Contributor

@joel23888 joel23888 commented Jul 15, 2015

It seems the getBars function never adjusts for corporate actions like stock splits. Eg. 4661 JT Equity had a 1:4 stock split on 3/27/2015. This means unadjusted prices should have a large gap between 3/26 and 3/27 where prices fall by a factor of 4, while adjusted prices should multiply pre-3/27 prices by 0.25 to remove this gap. I find it always returns unadjusted prices, even though my BBG settings in DPDF are set to adjust and IntradayBarRequest should follow this by default according to BBG.

@eddelbuettel
Copy link
Member

@eddelbuettel eddelbuettel commented Jul 15, 2015

If you could, something reproducible would be great.

Also, it is not quite clear which settings do, or do not, come 'down' from the Bbg terminal one connects to.

@joel23888
Copy link
Contributor Author

@joel23888 joel23888 commented Jul 15, 2015

Basic reproduction steps:
Step 1. In BBG terminal, enter DPDF GO and uncheck all boxes, be sure to save settings
Step 2. Run:

library(lubridate)
library(xts)
library(Rblpapi)
con <- blpConnect() 
tz <- "Asia/Tokyo"
Sys.setenv(TZ=tz)
t7 <- ymd_hms("2015-03-26 14:00:00", tz = tz)
t8 <- ymd_hms("2015-03-27 10:00:00", tz = tz)
d <- getBars("4661 JT Equity", eventType = "TRADE", barInterval = 60,
               startTime = t7, endTime = t8,
               returnAs = "xts", tz = "Asia/Tokyo")
d

Which returns for me:
open high low close numEvents volume
2015-03-26 14:00:00 36089.7 36129.6 35930 35930 1170 216100
2015-03-27 09:00:00 9137.0 9400.0 9050 9395 9002 2576700

This is expected as DPDF settings dictate no corporate actions adjustments should be made, and given the stock split I referred to before when I raised the issue, the price should divide in 4 from one day to the next (approximately).

Step 3. In BBG terminal, enter DPDF GO and check all boxes, be sure to save settings
Step 4. Rerun getBars in step 2 (under new DPDF setting), which for me returns the same result as in step 2. However, this is unexpected because DPDF dictate corporate actions adjustments should be made. The adjustment should be that price on 3/26 is multiplied by 0.25 and volume by 4, which is what I get when I view the same data on BBG terminal using the GIT function (unrelated to "git").

Let me know if you need more details.

If you see http://www.bloomberglabs.com/api/content/uploads/sites/2/2014/07/blpapi-developers-guide-2.54.pdf around p176 there is an option "adjustmentFollowDPDF", which if passed over to BBG should return adjusted data if DPDF is set to apply adjustments.

@joel23888
Copy link
Contributor Author

@joel23888 joel23888 commented Jul 15, 2015

eddelbuettel: Seemed easier to provide a potential solution for this than I had first thought (new to RCpp). Sent you a pull request.

@eddelbuettel
Copy link
Member

@eddelbuettel eddelbuettel commented Jul 15, 2015

Thanks, the PR looks fine.

But am wondering why we need the setting if the default (per page 176) is TRUE already?

@joel23888
Copy link
Contributor Author

@joel23888 joel23888 commented Jul 15, 2015

It does say that, but on my system it was never adjusting for corporate actions even when my DPDF setting were dictating it should. As soon as I made the change, it worked. If anyone has a different behavior I would be interested to know.

Also, under the heading of corporate actions I should point out my approach is incomplete. It does not support the elements adjustmentNormal, adjustmentAbnormal, and adjustmentSplit. These may be useful for per-request control of corporate action adjustments. Expected behavior would be to override DPDF settings.

@eddelbuettel
Copy link
Member

@eddelbuettel eddelbuettel commented Jul 15, 2015

I know. I am wondering whether we should have a list, say, blpOptions(...), as opposed to individual toggles. No strong feelings either way, but a shorter argument list may be better.

Opinions on this, @armstrtw @johnlaing ?

@johnlaing
Copy link
Contributor

@johnlaing johnlaing commented Jul 15, 2015

Very much in favor of a list or ... instead of a long string of potentially esoteric options.

@eddelbuettel
Copy link
Member

@eddelbuettel eddelbuettel commented Jul 15, 2015

👍

I'll deal with it: first taking in the PR, then rearranging sligthly.

@armstrtw
Copy link
Contributor

@armstrtw armstrtw commented Jul 15, 2015

yeah, list sounds good.

I don't know how to put the fancy thumbs up here, so I'll just do +1.

@eddelbuettel
Copy link
Member

@eddelbuettel eddelbuettel commented Jul 15, 2015

:)

If you edit in the browser, start with a single : and you'll see ... (oh and you always look at other people's post by opening them for edits ...)

@joel23888
Copy link
Contributor Author

@joel23888 joel23888 commented Jul 16, 2015

Many thanks!

@eddelbuettel
Copy link
Member

@eddelbuettel eddelbuettel commented Dec 5, 2015

Attempted to get closed by #48 which was not good and then #105 with was better (though not without issues itself 😃 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.