[Rprotobuf-commits] r486 - in pkg: . inst inst/examples/HighFrequencyFinance
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Oct 4 02:36:22 CEST 2012
Author: edd
Date: 2012-10-04 02:36:22 +0200 (Thu, 04 Oct 2012)
New Revision: 486
Removed:
pkg/inst/examples/HighFrequencyFinance/Makefile
pkg/inst/examples/HighFrequencyFinance/README
pkg/inst/examples/HighFrequencyFinance/TradeData.proto
pkg/inst/examples/HighFrequencyFinance/loadInR.r
pkg/inst/examples/HighFrequencyFinance/protoCreate.cpp
pkg/inst/examples/HighFrequencyFinance/protoDump.cpp
pkg/inst/examples/HighFrequencyFinance/protoModule.cpp
pkg/inst/examples/HighFrequencyFinance/trades.pb
Modified:
pkg/DESCRIPTION
pkg/inst/NEWS.Rd
Log:
Release 0.2.6
Adding Murray to Authors
Removing the example we made up one afternoon before the useR! 2010 presentation
Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION 2012-10-03 19:43:56 UTC (rev 485)
+++ pkg/DESCRIPTION 2012-10-04 00:36:22 UTC (rev 486)
@@ -1,7 +1,7 @@
Package: RProtoBuf
-Version: 0.2.5.2
+Version: 0.2.6
Date: $Date$
-Author: Romain Francois <romain at r-enthusiasts.com> and Dirk Eddelbuettel <edd at debian.org>
+Author: Romain Francois, Dirk Eddelbuettel and Murray Stokely
Maintainer: Dirk Eddelbuettel <edd at debian.org>
Title: R Interface to the Protocol Buffers API
Description: Protocol Buffers are a way of encoding structured data in an
Modified: pkg/inst/NEWS.Rd
===================================================================
--- pkg/inst/NEWS.Rd 2012-10-03 19:43:56 UTC (rev 485)
+++ pkg/inst/NEWS.Rd 2012-10-04 00:36:22 UTC (rev 486)
@@ -2,7 +2,7 @@
\title{News for Package \pkg{RProtoBuf}}
\newcommand{\cpkg}{\href{http://CRAN.R-project.org/package=#1}{\pkg{#1}}}
-\section{Changes in version 0.2.6 (2012-xx-yy)}{
+\section{Changes in version 0.2.6 (2012-10-04)}{
\itemize{
\item Applied several more patches by Murray to
\itemize{
@@ -16,6 +16,9 @@
\item fix a bug that caused non-deterministic behavior when setting a repeated message field in a protobuf to a single Message.
\item add unit tests for all of the above.
}
+ \item Added Murray to Authors: field in DESCRIPTION
+ \item Removed old and unconvincing example on RProtoBuf for storage
+ and serialization in an imagined HighFrequencyFinance context
}
}
Deleted: pkg/inst/examples/HighFrequencyFinance/Makefile
===================================================================
--- pkg/inst/examples/HighFrequencyFinance/Makefile 2012-10-03 19:43:56 UTC (rev 485)
+++ pkg/inst/examples/HighFrequencyFinance/Makefile 2012-10-04 00:36:22 UTC (rev 486)
@@ -1,33 +0,0 @@
-
-# Rmath is in /usr/include on my system
-CXXFLAGS= -I/usr/include -I. -Wall -O3 -pipe
-
-# libRmath.so is in /usr/lib on my system, as are the proto library
-LDLIBS= -L/usr/lib -lprotobuf -lprotoc -lpthread
-
-RCPPINC= $(shell Rscript -e 'Rcpp:::CxxFlags()')
-RCPPLIB= $(shell Rscript -e 'Rcpp:::LdFlags()')
-
-TARGETS= protoCreate protoDump protoModule.so TradeData.pb.cc
-
-all: $(TARGETS)
-
-protoCreate: protoCreate.cpp TradeData.pb.cc
- $(CXX) $(CXXFLAGS) $^ -o $@ -lRmath $(LDLIBS)
-
-protoDump: protoDump.cpp TradeData.pb.cc
- $(CXX) $(CXXFLAGS) $^ -o $@ $(LDLIBS)
-
-#protoLoadForR.so: protoLoadForR.cpp TradeData.pb.cc
-# PKG_CXXFLAGS="$(CXXFLAGS) $(RCPPINC)" PKG_LIBS="$(LDLIBS) $(RCPPLIB)" \
-# R CMD SHLIB $^
-
-protoModule.so: protoModule.cpp TradeData.pb.cc
- PKG_CXXFLAGS="$(CXXFLAGS) $(RCPPINC)" PKG_LIBS="$(LDLIBS) $(RCPPLIB)" \
- R CMD SHLIB $^
-
-TradeData.pb.cc: TradeData.proto
- protoc --cpp_out=. $^
-
-clean:
- @$(RM) $(TARGETS) TradeData.pb.h *.o
Deleted: pkg/inst/examples/HighFrequencyFinance/README
===================================================================
--- pkg/inst/examples/HighFrequencyFinance/README 2012-10-03 19:43:56 UTC (rev 485)
+++ pkg/inst/examples/HighFrequencyFinance/README 2012-10-04 00:36:22 UTC (rev 486)
@@ -1,8 +0,0 @@
-
-This is an entirely cooked-up example resembling some of the data you might
-encounter looking at trades on a tick-by-tick basis.
-
-It provides a good example for why ProtoBuffers rocks: they are concise, they
-are fast, they are extensible --- and they can be hooked up to several
-languages with C++, Java and Python supported by Google, and others by
-third-party projects such as this providing R.
Deleted: pkg/inst/examples/HighFrequencyFinance/TradeData.proto
===================================================================
--- pkg/inst/examples/HighFrequencyFinance/TradeData.proto 2012-10-03 19:43:56 UTC (rev 485)
+++ pkg/inst/examples/HighFrequencyFinance/TradeData.proto 2012-10-04 00:36:22 UTC (rev 486)
@@ -1,16 +0,0 @@
-
-// Namespace
-package TradeData;
-
-// A simple Fill, ie a completed trade
-message Fill {
- required double timestamp = 1;
- required string symbol = 2;
- required double price = 3;
- required int32 size = 4;
-}
-
-// A sequence of Fills
-message Trades {
- repeated Fill fill = 1;
-}
Deleted: pkg/inst/examples/HighFrequencyFinance/loadInR.r
===================================================================
--- pkg/inst/examples/HighFrequencyFinance/loadInR.r 2012-10-03 19:43:56 UTC (rev 485)
+++ pkg/inst/examples/HighFrequencyFinance/loadInR.r 2012-10-04 00:36:22 UTC (rev 486)
@@ -1,112 +0,0 @@
-#!/usr/bin/r -t
-
-
-basicUse <- function(verbose=TRUE) {
- readProtoFiles("TradeData.proto")
- x <- read( TradeData.Trades, "trades.pb")
- xl <- as.list(x)
- df <- do.call(rbind, lapply(as.list(xl$fill), function(.) as.data.frame(as.list(.))))
- df[,1] <- as.POSIXct(df[,1], origin="1970-01-01")
- if (verbose) print(summary(df))
- invisible(df)
-}
-
-timedUse <- function() {
- a1 <- system.time(readProtoFiles("TradeData.proto"))
- a2 <- system.time(x <- read( TradeData.Trades, "trades.pb"))
- a3 <- system.time(xl <- as.list(x))
- a4 <- system.time(df <- do.call(rbind, lapply(as.list(xl$fill), function(.) as.data.frame(as.list(.)))))
- print(summary(df))
-
- print(rbind(a1, a2, a3, a4))
- invisible(df)
-}
-
-profiledUse <- function() {
- Rprof(filename = "loadIt-Rprof.out", interval = 0.01)
- readProtoFiles("TradeData.proto")
- x <- read( TradeData.Trades, "trades.pb")
- xl <- as.list(x)
- df <- do.call(rbind, lapply(as.list(xl$fill), function(.) as.data.frame(as.list(.))))
- print(summary(df))
- Rprof(NULL)
- invisible(df)
-}
-
-betterUse <- function(verbose=TRUE, file = "trades.pb") {
- readProtoFiles("TradeData.proto")
- x <- read( TradeData.Trades, "trades.pb")
- xl <- lapply( x$fill, as.list )
-
- df <- data.frame(timestamp = as.POSIXct( sapply( xl, "[[", "timestamp" ), origin="1970-01-01"),
- symbol = sapply( xl, "[[", "symbol" ),
- price = sapply( xl, "[[", "price" ),
- size = sapply( xl, "[[", "size" )
- )
- if (verbose) print(summary(df))
- invisible(df)
-}
-
-preAlloc <- function(verbose=TRUE) {
- readProtoFiles("TradeData.proto")
- x <- read( TradeData.Trades, "trades.pb")
- x1 <- as.list(x) # 36 sec
- xl <- as.list(x1$fill)
- n <- length(xl)
- df <- data.frame(ts = rep(NA, n),
- sym = rep("", n),
- price = rep(NA, n),
- size = rep(NA, n),
- stringsAsFactors=FALSE)
- for (i in 1:n) {
- df[i, ] <- as.list(xl[[i]])
- }
- df[,1] <- as.POSIXct(df[,1], origin="1970-01-01")
- if (verbose) print(summary(df))
- invisible(df)
-}
-
-compiled <- function(verbose=FALSE, file="trades.pb") {
-
- stopifnot(file.exists(file))
-
- df <- .Call("pbload", file);
-
- if (verbose) print(summary(df))
-
- invisible(df)
-}
-
-moduled <- function(verbose=FALSE, file="trades.pb", dll) {
-
- stopifnot(file.exists(file))
-
- trds <- Module("trades", dll)
- td <- new( trds$Trades )
- td$init(file)
- #print(n <- td$numberOfFills())
- df <- td$getData()
-
- if (verbose) print(summary(df))
-
- invisible(df)
-}
-
-suppressMessages(library(stats))
-suppressMessages(library(RProtoBuf))
-suppressMessages(library(utils))
-suppressMessages(library(Rcpp))
-suppressMessages(library(rbenchmark))
-
-dll <- dyn.load("protoModule.so")
-
-print(benchmark(compiled = compiled(FALSE),
- moduled = moduled(FALSE),
- basicUse = basicUse(FALSE),
- betterUs = betterUse(FALSE),
- preAlloc = preAlloc(FALSE),
- order = "elapsed",
- columns = c("test", "replications", "elapsed", "relative", "user.self", "sys.self"),
- replications = 5))
-
-
Deleted: pkg/inst/examples/HighFrequencyFinance/protoCreate.cpp
===================================================================
--- pkg/inst/examples/HighFrequencyFinance/protoCreate.cpp 2012-10-03 19:43:56 UTC (rev 485)
+++ pkg/inst/examples/HighFrequencyFinance/protoCreate.cpp 2012-10-04 00:36:22 UTC (rev 486)
@@ -1,46 +0,0 @@
-// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*-
-
-#include "TradeData.pb.h" // auto-generated ProtoBuffer data structure accessor
-#include <iostream>
-#include <fstream>
-
-#define MATHLIB_STANDALONE 1 // so that we get set_seed()
-#include <Rmath.h> // to use R's RNGs and random distribution functions
-
-int main(int argc, char **argv)
-{
- // Verify that the version of the library that we linked against is
- // compatible with the version of the headers we compiled against.
- GOOGLE_PROTOBUF_VERIFY_VERSION;
-
- const char* pbfile = "trades.pb";
- const int N = 1000;
-
- set_seed(123, 456);
-
- double tstamp = 1277973000; // 2010-07-01 08:30:00
- double tprice = 100.0; // gotta start somewhere
- char sym[] = "ABC";
-
- TradeData::Trades tr;
- for (int i=0; i<N; i++) {
- TradeData::Fill *fill = tr.add_fill();
- tstamp += runif(0.000, 0.100); // time steps anywhere between 0 and 100 msec
- tprice += round(rt(5) * 0.01 * 100)/100; // price move as dampened t(5), rounded to pennies
- int tsize = 100 + round(runif(0,9))*100; // size in 100 lots
-
- fill->set_timestamp(tstamp);
- fill->set_price(tprice);
- fill->set_symbol(sym);
- fill->set_size(tsize);
- }
-
- std::fstream output(pbfile, std::ios::out | std::ios::binary);
- if (!tr.SerializeToOstream(&output)) {
- std::cerr << "Failed to write data." << std::endl;
- return -1;
- }
- google::protobuf::ShutdownProtobufLibrary();
-
- return 0;
-}
Deleted: pkg/inst/examples/HighFrequencyFinance/protoDump.cpp
===================================================================
--- pkg/inst/examples/HighFrequencyFinance/protoDump.cpp 2012-10-03 19:43:56 UTC (rev 485)
+++ pkg/inst/examples/HighFrequencyFinance/protoDump.cpp 2012-10-04 00:36:22 UTC (rev 486)
@@ -1,49 +0,0 @@
-// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*-
-
-#include "TradeData.pb.h"
-#include <iostream>
-#include <fstream>
-#include <cmath>
-
-std::string formatTimestamp(const double ts) {
- // tt is the nb of seconds, ignores fractional microsec
- time_t tt = static_cast<time_t>(floor(ts));
- struct tm tm = *localtime(&tt); // parse time type into time structure
-
- // m_us is fractional (micro)secs is diff. between (fractional) m_d and m_tm
- unsigned int us = static_cast<int>( round( (ts - tt) * 1.0e6 ) );
-
- char buf[32], txt[32];
- strftime(buf, 31, "%Y-%m-%d %H:%M:%S", &tm);
- snprintf(txt, 31, "%s.%.06d", buf, us);
- return std::string(txt);
-}
-
-int main(int argc, char **argv)
-{
- // Verify that the version of the library that we linked against is
- // compatible with the version of the headers we compiled against.
- GOOGLE_PROTOBUF_VERIFY_VERSION;
-
- const char* pbfile = "trades.pb";
-
- TradeData::Trades tr;
-
- std::fstream fs(pbfile, std::ios::in | std::ios::binary);
- if (!tr.ParseFromIstream(&fs)) {
- std::cerr << "Trouble parsing...\n";
- return -1;
- }
-
- for (int i=0; i<tr.fill_size(); i++) {
- const TradeData::Fill &fill = tr.fill(i);
- std::cout << formatTimestamp(fill.timestamp()) << " "
- << fill.symbol() << " "
- << fill.price() << " "
- << fill.size() << std::endl;
- }
-
- google::protobuf::ShutdownProtobufLibrary();
-
- return 0;
-}
Deleted: pkg/inst/examples/HighFrequencyFinance/protoModule.cpp
===================================================================
--- pkg/inst/examples/HighFrequencyFinance/protoModule.cpp 2012-10-03 19:43:56 UTC (rev 485)
+++ pkg/inst/examples/HighFrequencyFinance/protoModule.cpp 2012-10-04 00:36:22 UTC (rev 486)
@@ -1,101 +0,0 @@
-// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*-
-
-#include "TradeData.pb.h"
-
-#include <Rcpp.h>
-#include <fstream>
-#include <iostream>
-
-
-extern "C" SEXP pbload(SEXP b) {
-
- std::string pbfile = Rcpp::as<std::string>(b);
-
- // Verify that the version of the library that we linked against is
- // compatible with the version of the headers we compiled against.
- GOOGLE_PROTOBUF_VERIFY_VERSION;
-
- TradeData::Trades tr;
-
- std::fstream fs(pbfile.c_str(), std::ios::in | std::ios::binary);
-
- if (!tr.ParseFromIstream(&fs)) {
- std::cerr << "Trouble parsing..." << std::cout;
- return R_NilValue;
- }
-
- int n = tr.fill_size();
- Rcpp::DatetimeVector timestamp(n);
- Rcpp::CharacterVector tsym(n);
- Rcpp::NumericVector tprice(n);
- Rcpp::IntegerVector tsize(n);
-
- for (int i=0; i<n; i++) {
- const TradeData::Fill &fill = tr.fill(i);
- timestamp[i] = fill.timestamp();
- tsym[i] = fill.symbol();
- tprice[i] = fill.price();
- tsize[i] = fill.size();
- }
-
- //google::protobuf::ShutdownProtobufLibrary();
- return Rcpp::DataFrame::create(Rcpp::Named("times") = timestamp,
- Rcpp::Named("symbol") = tsym,
- Rcpp::Named("price") = tprice,
- Rcpp::Named("size") = tsize);
-}
-
-
-class TradeModule
-{
-private:
- TradeData::Trades tr;
-public:
- int init(const char *pbfile) {
- std::fstream fs(pbfile, std::ios::in | std::ios::binary);
-
- if (!tr.ParseFromIstream(&fs)) {
- std::cerr << "Trouble parsing..." << std::cout;
- return -1;
- }
- return 0;
- }
-
- int numberOfFills(void) {
- return tr.fill_size();
- }
-
- Rcpp::DataFrame getData(void) {
- int n = tr.fill_size();
- Rcpp::DatetimeVector timestamp(n);
- Rcpp::CharacterVector tsym(n);
- Rcpp::NumericVector tprice(n);
- Rcpp::IntegerVector tsize(n);
-
- for (int i=0; i<n; i++) {
- const TradeData::Fill &fill = tr.fill(i);
- timestamp[i] = fill.timestamp();
- tsym[i] = fill.symbol();
- tprice[i] = fill.price();
- tsize[i] = fill.size();
- }
-
- return Rcpp::DataFrame::create(Rcpp::Named("times") = timestamp,
- Rcpp::Named("symbol") = tsym,
- Rcpp::Named("price") = tprice,
- Rcpp::Named("size") = tsize);
- }
-
-};
-
-RCPP_MODULE(trades){
- using namespace Rcpp ;
-
- class_<TradeModule>( "Trades" )
- .method( "init", &TradeModule::init )
- .method( "numberOfFills", &TradeModule::numberOfFills )
- .method( "getData", &TradeModule::getData )
- ;
-
-}
-
Deleted: pkg/inst/examples/HighFrequencyFinance/trades.pb
===================================================================
(Binary files differ)
More information about the Rprotobuf-commits
mailing list