This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a=-1.24458046630025 | |
b=-1.25191834103316 | |
c=-1.81590817030519 | |
d=-1.90866735205054 | |
n <- 10000000 | |
x <- vector("numeric", n) | |
y <- vector("numeric", n) | |
x[1] <- 0 | |
y[1] <- 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` r | |
library(odbc) | |
#> Warning: package 'odbc' was built under R version 3.4.2 | |
library(DBI) | |
con <- DBI::dbConnect(odbc::odbc(), | |
Driver = "PostgreSQL ODBC Driver(ANSI)", | |
Server = "localhost", | |
Database = "postgres", | |
UID = 'postgres', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` r | |
library(tibbletime) | |
library(dplyr) | |
options(digits.secs = 6) | |
# 1000 values | |
ex <- create_series('2013' ~ '2013-01-01 00:00:00.999', period = "1 millisec") | |
# Random data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tibbletime) | |
library(dplyr) | |
library(zoo) | |
data(FB) | |
window <- 6 | |
rolling_mean <- rollify(mean, window = window) | |
FB_roll <- FB %>% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(DBI) | |
library(dplyr) | |
library(pool) | |
pool <- dbPool(drv = RPostgres::Postgres(), | |
dbname = "rstudioconftweets", | |
host = "rstudioconf-tweets.c0azx4micevq.us-east-1.rds.amazonaws.com", | |
user = "guest", | |
password = "guest", | |
port = 5432) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tibbletime) | |
#> | |
#> Attaching package: 'tibbletime' | |
#> The following object is masked from 'package:stats': | |
#> | |
#> filter | |
library(dplyr) | |
#> | |
#> Attaching package: 'dplyr' | |
#> The following objects are masked from 'package:stats': |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### Example with flights dataset | |
library(readr) | |
library(fst) | |
library(data.table) | |
data(flights, package = "nycflights13") | |
# Write | |
write.fst(flights, path = "flights.fst") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(magrittr) | |
time_horizon <- 5 | |
# Starts at 12/12 (1) goes to 60/12 (5) (notice how the numerators are 12->60) | |
seq(1, time_horizon, by = 1/12) %>% print() %>% length() | |
#> [1] 1.000000 1.083333 1.166667 1.250000 1.333333 1.416667 1.500000 | |
#> [8] 1.583333 1.666667 1.750000 1.833333 1.916667 2.000000 2.083333 | |
#> [15] 2.166667 2.250000 2.333333 2.416667 2.500000 2.583333 2.666667 | |
#> [22] 2.750000 2.833333 2.916667 3.000000 3.083333 3.166667 3.250000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(Rcpp) | |
library(microbenchmark) | |
cppFunction( | |
'int looped_sum(int x, const int num_loops) { | |
for(int i = 0; i < num_loops; i++) { | |
x = x + 1; | |
} | |
return x; | |
}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This example simulates a stock price 1 time and 10k times. | |
# It uses a functional approach and a loop approach. | |
# A speed test is done at the end. | |
# This example for GBM ignores the fact that | |
# 1) There is an explicit solution to GBM where simulation isn't needed | |
# 2) Along the same lines, there is a vectorized form where pure matrix mult can be used. | |
# These are ignored for the sake of the example, because there are often cases | |
# where this isn't the case and you HAVE to do the discrete loop. |