Issues with using R's bizdays package to create weekdays calendar for daily stock prices data
I have data on daily stock prices from Brazil span over the period 2000-01-03/2018-11-15, the data contain working days only, therefore, I'm using bizdays package to create calendar counting working days and skips weekends, bizdays requires predefined calendar to adjust dates to working days. To this end, we can use RQunatLib or Rmetrics to load the calendar we want. Once we get the calendar of interest, we can adjust dates to working days only with following code:
dates <- bizdays(from='2000-01-03', to='2018-11-15', cal)
In my case which is Brazil, to get the calendar I used the following codes:
install.packages("bizdays")
require(bizdays)
install.packages("RQuantLib")
require(RQuantLib)
load_quantlib_calendars('Brazil', from='2000-01-03', to='2018-11-15')
The problem here is that function "load_quantlib_calendars" is not recognized
Error in load_quantlib_calendars("Brazil", from = "2000-01-03", to = "2018-11-15") :
could not find function "load_quantlib_calendars"
Why is the function not working?
r date time-series
add a comment |
I have data on daily stock prices from Brazil span over the period 2000-01-03/2018-11-15, the data contain working days only, therefore, I'm using bizdays package to create calendar counting working days and skips weekends, bizdays requires predefined calendar to adjust dates to working days. To this end, we can use RQunatLib or Rmetrics to load the calendar we want. Once we get the calendar of interest, we can adjust dates to working days only with following code:
dates <- bizdays(from='2000-01-03', to='2018-11-15', cal)
In my case which is Brazil, to get the calendar I used the following codes:
install.packages("bizdays")
require(bizdays)
install.packages("RQuantLib")
require(RQuantLib)
load_quantlib_calendars('Brazil', from='2000-01-03', to='2018-11-15')
The problem here is that function "load_quantlib_calendars" is not recognized
Error in load_quantlib_calendars("Brazil", from = "2000-01-03", to = "2018-11-15") :
could not find function "load_quantlib_calendars"
Why is the function not working?
r date time-series
lubridate wday function is very easier than this have a look lubridate::wday(date, label = TRUE) . Also your spelling is wrong for bizdays while loading the library. require(bizdays)
– Hunaidkhan
Nov 21 '18 at 9:40
@ Hunaidkhan Thanks, I'm already reading an article about "lubridate", I'll try it for sure. Btw the spelling mistake has bee corrected
– Ameer
Nov 21 '18 at 9:57
@Hunaidkhan zoo is also very useful in this case and fairly easy to use, I created date index "X" using the codeX <- seq( as.Date("2000/1/03"), as.Date("2018/11/15"),"days")
, then excluded the weekend days from the date index "X" by doing thisweekdays.X <- X[ ! weekdays(X) %in% c("Saturday", "Sunday")]
. I got new date index without weekends "weekdays.X". lastly I combined the new date index with my stock price time series "SPrices1":XPrices = zoo(x=SPrices1, order.by=weekdays.X)
– Ameer
Nov 22 '18 at 14:34
add a comment |
I have data on daily stock prices from Brazil span over the period 2000-01-03/2018-11-15, the data contain working days only, therefore, I'm using bizdays package to create calendar counting working days and skips weekends, bizdays requires predefined calendar to adjust dates to working days. To this end, we can use RQunatLib or Rmetrics to load the calendar we want. Once we get the calendar of interest, we can adjust dates to working days only with following code:
dates <- bizdays(from='2000-01-03', to='2018-11-15', cal)
In my case which is Brazil, to get the calendar I used the following codes:
install.packages("bizdays")
require(bizdays)
install.packages("RQuantLib")
require(RQuantLib)
load_quantlib_calendars('Brazil', from='2000-01-03', to='2018-11-15')
The problem here is that function "load_quantlib_calendars" is not recognized
Error in load_quantlib_calendars("Brazil", from = "2000-01-03", to = "2018-11-15") :
could not find function "load_quantlib_calendars"
Why is the function not working?
r date time-series
I have data on daily stock prices from Brazil span over the period 2000-01-03/2018-11-15, the data contain working days only, therefore, I'm using bizdays package to create calendar counting working days and skips weekends, bizdays requires predefined calendar to adjust dates to working days. To this end, we can use RQunatLib or Rmetrics to load the calendar we want. Once we get the calendar of interest, we can adjust dates to working days only with following code:
dates <- bizdays(from='2000-01-03', to='2018-11-15', cal)
In my case which is Brazil, to get the calendar I used the following codes:
install.packages("bizdays")
require(bizdays)
install.packages("RQuantLib")
require(RQuantLib)
load_quantlib_calendars('Brazil', from='2000-01-03', to='2018-11-15')
The problem here is that function "load_quantlib_calendars" is not recognized
Error in load_quantlib_calendars("Brazil", from = "2000-01-03", to = "2018-11-15") :
could not find function "load_quantlib_calendars"
Why is the function not working?
r date time-series
r date time-series
edited Nov 27 '18 at 11:28
Ameer
asked Nov 21 '18 at 9:23
AmeerAmeer
175
175
lubridate wday function is very easier than this have a look lubridate::wday(date, label = TRUE) . Also your spelling is wrong for bizdays while loading the library. require(bizdays)
– Hunaidkhan
Nov 21 '18 at 9:40
@ Hunaidkhan Thanks, I'm already reading an article about "lubridate", I'll try it for sure. Btw the spelling mistake has bee corrected
– Ameer
Nov 21 '18 at 9:57
@Hunaidkhan zoo is also very useful in this case and fairly easy to use, I created date index "X" using the codeX <- seq( as.Date("2000/1/03"), as.Date("2018/11/15"),"days")
, then excluded the weekend days from the date index "X" by doing thisweekdays.X <- X[ ! weekdays(X) %in% c("Saturday", "Sunday")]
. I got new date index without weekends "weekdays.X". lastly I combined the new date index with my stock price time series "SPrices1":XPrices = zoo(x=SPrices1, order.by=weekdays.X)
– Ameer
Nov 22 '18 at 14:34
add a comment |
lubridate wday function is very easier than this have a look lubridate::wday(date, label = TRUE) . Also your spelling is wrong for bizdays while loading the library. require(bizdays)
– Hunaidkhan
Nov 21 '18 at 9:40
@ Hunaidkhan Thanks, I'm already reading an article about "lubridate", I'll try it for sure. Btw the spelling mistake has bee corrected
– Ameer
Nov 21 '18 at 9:57
@Hunaidkhan zoo is also very useful in this case and fairly easy to use, I created date index "X" using the codeX <- seq( as.Date("2000/1/03"), as.Date("2018/11/15"),"days")
, then excluded the weekend days from the date index "X" by doing thisweekdays.X <- X[ ! weekdays(X) %in% c("Saturday", "Sunday")]
. I got new date index without weekends "weekdays.X". lastly I combined the new date index with my stock price time series "SPrices1":XPrices = zoo(x=SPrices1, order.by=weekdays.X)
– Ameer
Nov 22 '18 at 14:34
lubridate wday function is very easier than this have a look lubridate::wday(date, label = TRUE) . Also your spelling is wrong for bizdays while loading the library. require(bizdays)
– Hunaidkhan
Nov 21 '18 at 9:40
lubridate wday function is very easier than this have a look lubridate::wday(date, label = TRUE) . Also your spelling is wrong for bizdays while loading the library. require(bizdays)
– Hunaidkhan
Nov 21 '18 at 9:40
@ Hunaidkhan Thanks, I'm already reading an article about "lubridate", I'll try it for sure. Btw the spelling mistake has bee corrected
– Ameer
Nov 21 '18 at 9:57
@ Hunaidkhan Thanks, I'm already reading an article about "lubridate", I'll try it for sure. Btw the spelling mistake has bee corrected
– Ameer
Nov 21 '18 at 9:57
@Hunaidkhan zoo is also very useful in this case and fairly easy to use, I created date index "X" using the code
X <- seq( as.Date("2000/1/03"), as.Date("2018/11/15"),"days")
, then excluded the weekend days from the date index "X" by doing this weekdays.X <- X[ ! weekdays(X) %in% c("Saturday", "Sunday")]
. I got new date index without weekends "weekdays.X". lastly I combined the new date index with my stock price time series "SPrices1": XPrices = zoo(x=SPrices1, order.by=weekdays.X)
– Ameer
Nov 22 '18 at 14:34
@Hunaidkhan zoo is also very useful in this case and fairly easy to use, I created date index "X" using the code
X <- seq( as.Date("2000/1/03"), as.Date("2018/11/15"),"days")
, then excluded the weekend days from the date index "X" by doing this weekdays.X <- X[ ! weekdays(X) %in% c("Saturday", "Sunday")]
. I got new date index without weekends "weekdays.X". lastly I combined the new date index with my stock price time series "SPrices1": XPrices = zoo(x=SPrices1, order.by=weekdays.X)
– Ameer
Nov 22 '18 at 14:34
add a comment |
1 Answer
1
active
oldest
votes
This should do the work for you
days <- as.data.frame(as.Date(seq(as.Date("2000-01-03"), as.Date("2018-11-15"), by="days")))
colnames(days)<- c("Date")
days$condition <- lubridate::wday(days$Date, label = TRUE)
If you want to remove weekend from the data use the below code
days_new <- mutate(days, Date = wday(Date, label = T)) %>%
filter(Date != "Sat", Date != "Sun")
Thanks for helping, it works great, now how can I attach the new object "days_new" to my stock price time series
– Ameer
Nov 21 '18 at 11:19
you can do left join or you can directly use this data for time series analysis
– Hunaidkhan
Nov 21 '18 at 11:38
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53408825%2fissues-with-using-rs-bizdays-package-to-create-weekdays-calendar-for-daily-stoc%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
This should do the work for you
days <- as.data.frame(as.Date(seq(as.Date("2000-01-03"), as.Date("2018-11-15"), by="days")))
colnames(days)<- c("Date")
days$condition <- lubridate::wday(days$Date, label = TRUE)
If you want to remove weekend from the data use the below code
days_new <- mutate(days, Date = wday(Date, label = T)) %>%
filter(Date != "Sat", Date != "Sun")
Thanks for helping, it works great, now how can I attach the new object "days_new" to my stock price time series
– Ameer
Nov 21 '18 at 11:19
you can do left join or you can directly use this data for time series analysis
– Hunaidkhan
Nov 21 '18 at 11:38
add a comment |
This should do the work for you
days <- as.data.frame(as.Date(seq(as.Date("2000-01-03"), as.Date("2018-11-15"), by="days")))
colnames(days)<- c("Date")
days$condition <- lubridate::wday(days$Date, label = TRUE)
If you want to remove weekend from the data use the below code
days_new <- mutate(days, Date = wday(Date, label = T)) %>%
filter(Date != "Sat", Date != "Sun")
Thanks for helping, it works great, now how can I attach the new object "days_new" to my stock price time series
– Ameer
Nov 21 '18 at 11:19
you can do left join or you can directly use this data for time series analysis
– Hunaidkhan
Nov 21 '18 at 11:38
add a comment |
This should do the work for you
days <- as.data.frame(as.Date(seq(as.Date("2000-01-03"), as.Date("2018-11-15"), by="days")))
colnames(days)<- c("Date")
days$condition <- lubridate::wday(days$Date, label = TRUE)
If you want to remove weekend from the data use the below code
days_new <- mutate(days, Date = wday(Date, label = T)) %>%
filter(Date != "Sat", Date != "Sun")
This should do the work for you
days <- as.data.frame(as.Date(seq(as.Date("2000-01-03"), as.Date("2018-11-15"), by="days")))
colnames(days)<- c("Date")
days$condition <- lubridate::wday(days$Date, label = TRUE)
If you want to remove weekend from the data use the below code
days_new <- mutate(days, Date = wday(Date, label = T)) %>%
filter(Date != "Sat", Date != "Sun")
answered Nov 21 '18 at 10:02
HunaidkhanHunaidkhan
1,014516
1,014516
Thanks for helping, it works great, now how can I attach the new object "days_new" to my stock price time series
– Ameer
Nov 21 '18 at 11:19
you can do left join or you can directly use this data for time series analysis
– Hunaidkhan
Nov 21 '18 at 11:38
add a comment |
Thanks for helping, it works great, now how can I attach the new object "days_new" to my stock price time series
– Ameer
Nov 21 '18 at 11:19
you can do left join or you can directly use this data for time series analysis
– Hunaidkhan
Nov 21 '18 at 11:38
Thanks for helping, it works great, now how can I attach the new object "days_new" to my stock price time series
– Ameer
Nov 21 '18 at 11:19
Thanks for helping, it works great, now how can I attach the new object "days_new" to my stock price time series
– Ameer
Nov 21 '18 at 11:19
you can do left join or you can directly use this data for time series analysis
– Hunaidkhan
Nov 21 '18 at 11:38
you can do left join or you can directly use this data for time series analysis
– Hunaidkhan
Nov 21 '18 at 11:38
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53408825%2fissues-with-using-rs-bizdays-package-to-create-weekdays-calendar-for-daily-stoc%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
lubridate wday function is very easier than this have a look lubridate::wday(date, label = TRUE) . Also your spelling is wrong for bizdays while loading the library. require(bizdays)
– Hunaidkhan
Nov 21 '18 at 9:40
@ Hunaidkhan Thanks, I'm already reading an article about "lubridate", I'll try it for sure. Btw the spelling mistake has bee corrected
– Ameer
Nov 21 '18 at 9:57
@Hunaidkhan zoo is also very useful in this case and fairly easy to use, I created date index "X" using the code
X <- seq( as.Date("2000/1/03"), as.Date("2018/11/15"),"days")
, then excluded the weekend days from the date index "X" by doing thisweekdays.X <- X[ ! weekdays(X) %in% c("Saturday", "Sunday")]
. I got new date index without weekends "weekdays.X". lastly I combined the new date index with my stock price time series "SPrices1":XPrices = zoo(x=SPrices1, order.by=weekdays.X)
– Ameer
Nov 22 '18 at 14:34