R Generating a 1 min spaced time sequence
Tag : r , By : Picoman Games
Date : March 29 2020, 07:55 AM
seems to work fine Out of interest does RTAQ offer anything not in another R package? Version 0.1 was released over two years ago, so it looks like a Dead Project. Anyway, you can still use XTS's to.minute() function, as it appears RTAQ use xts objects. Here is some sample code I use to take ticks and convert into bars, as well as adding other columns such as mean/sd: k=60
...
bars=to.period(x,k,period="secs")
colnames(bars)=c("Open","High","Low","Close")
ep=endpoints(x,"secs",k)
bars$Volume=period.apply(x,ep,length)
bars$mean=period.apply(x,ep,mean)
bars$sd=period.apply(x,ep, function(x){apply(x,2,sd)})
align.time(bars,k) #Do this last
align.time.down=function(x,n){index(x)=index(x)-n;align.time(x,n)}
full_index=do.call("c",mapply(
seq.exclude_final_period.POSIXt,period_from,period_to,by=k,SIMPLIFY=F
))
bars=merge(bars,xts(,full_index),all=TRUE)
#' Helper for process_one_day_of_ticks(); intended as a
#' replacement for seq.POSIXt (which will not exclude the final period).
#' @internal Use from=from+by instead of to=to-by to exclude the
# first period instead.
seq.exclude_final_period.POSIXt=function(from,to,by){
to=to-by #Make the final entry exclusive
seq(from,to,by)
}
|
Sequence of enumerators at compile time
Tag : cpp , By : Yohan Lee
Date : March 29 2020, 07:55 AM
this one helps. Given a C++11 enum class, is there some templating or other construct to iterate, at compile-time, over the set of all enumerators? Could one define a template to e.g. initialize an array with all possible values of that enum type? , One alternative technique is to resort to the pre-processor. #define ITERATE_MY_ENUM(_) \
_(A,) \
_(B, =3) \
_(C,) \
_(D, =10)
enum MyEnum {
#define DEFINE_ENUM_VALUE(key, value) key value,
ITERATE_MY_ENUM(DEFINE_ENUM_VALUE)
#undef DEFINE_ENUM_VALUE
};
void foo() {
MyEnum arr[] = {
#define IN_ARRAY_VALUE(key, value) key,
ITERATE_MY_ENUM(IN_ARRAY_VALUE)
#udnef IN_ARRAY_VALUE
};
}
|
Generating a random sequence of certain numbers in a deterministic time
Tag : cpp , By : Jonathan
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I have written the following piece of code to generate a random sequence of certain numbers {0,1,2,...,31}. It works fine, however, it cannot be guaranteed to complete within any finite amount of time; after any interval there is still only a certain (very high) probability that it will have completed. Any suggestion for removing this issue? , And an actual implementation: int a[] = { 0, 1, 2, ....., 31 };
std::random_shuffle(a, a + 32);
std::vector<int> v(a, a + 32); // from previous snippet
std::random_shuffle(v.begin(), v.end());
|
Generating BitCount LUT at compile time
Date : March 29 2020, 07:55 AM
it helps some times It would be fairly easy with macros using (recently re-discovered by me for my code) Boost.Preprocessor - I am not sure if it falls under "without using external code generators". PP_ENUM version #include <boost/preprocessor/repetition/enum.hpp>
// with ENUM we don't need a comma at the end
#define MACRO(z,n,text) CountBits<8>(n)
int CB_LUT[256] = {
BOOST_PP_ENUM(256, MACRO, _)
};
#undef MACRO
#include <boost/preprocessor/repetition/repeat.hpp>
#define MACRO(z,n,data) CountBits<8>(n),
int CB_LUT[256] = {
BOOST_PP_REPEAT(256, MACRO, _)
};
#undef MACRO
|
Generating a sequence of type T at compile time
Date : March 29 2020, 07:55 AM
like below fixes the issue I have the following problem: , Why not simply use: using callable_out_type = std::result_of_t< callable( decltype(N_i, std::declval<T>())...) >;
using callable_out_type = std::result_of_t< callable(std::tuple_element_t<(N_i, 0), std::tuple<T>>...) >;
using callable_out_type = std::result_of_t< callable(std::enable_if_t<(N_i, true), T>...) >;
|