Skip to content

Instantly share code, notes, and snippets.

View capm's full-sized avatar

Christian Portocarrero capm

View GitHub Profile
@capm
capm / advent_XML.R
Created December 8, 2012 19:15 — forked from dsparks/advent_XML.R
XML package example
doInstall <- TRUE
toInstall <- c("XML")
if(doInstall){install.packages(toInstall, repos = "http://cran.us.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
myURL <- "http://en.wikipedia.org/wiki/United_States_presidential_election,_2012"
allTables <- readHTMLTable(myURL)
str(allTables) # Look at the allTables object to find the specific table we want
stateTable <- allTables[[14]] # We want the 14th table in the list (maybe 13th?)
@capm
capm / advent_zoo.R
Created December 8, 2012 19:16 — forked from dsparks/advent_zoo.R
Rolling means with zoo
doInstall <- TRUE
toInstall <- c("zoo")
if(doInstall){install.packages(toInstall, repos = "http://cran.us.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
ftseIndex <- EuStockMarkets[, 4]
plot(ftseIndex, col = "GRAY")
# Calculate 10-day rolling mean, quickly:
smoothIndex <- rollmean(x = ftseIndex, # original series
@capm
capm / PackagesToInstall.R
Last active October 18, 2016 17:43
R: Packages to install
# DEVTOOLS
library(devtools)
build_github_devtools()
install.packages("devtools.zip", repos = NULL)
unlink("devtools.zip")
# RMetrics
source('http://www.rmetrics.org/Rmetrics.R')
install.Rmetrics()
# Additional set of repositories
setRepositories(addURLs = c(CRANxtras = 'http://www.stats.ox.ac.uk/pub/RWin'))
@capm
capm / FX_Download.r
Last active August 29, 2015 14:10
Functions for R
FX.HistData <- function(pair = "EURUSD", period = "day") {
##### Arguments verification Valid pairs to download
pairs.valid <- c("AUDJPY", "AUDUSD", "CHFJPY", "EURCHF", "EURGBP", "EURJPY", "EURUSD", "GBPCHF", "GBPJPY", "GBPUSD", "NZDUSD", "USDCAD", "USDCHF", "USDJPY", "XAGUSD", "XAUUSD")
# Valid download periods
period.valid <- c("day", "hour")
# Create set of warnings
error.string <- c()
# Check if it is a valid pair, if not store a warning
if (pair %in% pairs.valid){valid.pair = TRUE} else {
valid.pair = FALSE
@capm
capm / 0_reuse_code.js
Last active August 29, 2015 14:15
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@capm
capm / Excel-DateMultiFunction.vbs
Last active January 21, 2016 22:11
Excel VBA Function: Date pattern recognition and replacement.
Function DateMultiFunction(InputDate As String, InputType As Integer) As String
' 0: True or False
' 1: Replace date
' 2: Extract string
' Declare variables
Dim regEx As New RegExp
Dim strPattern As String
'
@capm
capm / MutualFunds.R
Created June 15, 2016 22:23
Mutual fund main variables data manipulation.
#####
## Load packages
#library(gdata)
library(readxl)
library(data.table)
library(tidyr)
library(magrittr)
library(SIT)
#####
@capm
capm / FXSBS.vbs
Created April 4, 2017 14:58
Download USDPEN FX rate from SBS website
Sub FXSBS()
'
' FXSBS Macro
'
' Declare variables
Dim wbMain As Workbook
Dim wsMain As Worksheet
Dim urlFX As String
Dim dateStart As Date, dateEnd As Date
' Internet objects
@capm
capm / vbFunctions.vbs
Last active September 28, 2022 15:33
Common functions I use in VBA.
Private Sub Auto_Open()
Call FXSBS
End Sub
Attribute VB_Name = "capmFunctions"
'XXXXX
Public Function RightToLeftChar(InputData As String, InputChar As String) As String
'
RightToLeftChar = Right(InputData, Len(InputData) - WorksheetFunction.Find("|", WorksheetFunction.Substitute(InputData, InputChar, "|", Len(InputData) - Len(WorksheetFunction.Substitute(InputData, InputChar, "")))))
End Function

Principles of Adult Behavior

  1. Be patient. No matter what.
  2. Don’t badmouth: Assign responsibility, not blame. Say nothing of another you wouldn’t say to him.
  3. Never assume the motives of others are, to them, less noble than yours are to you.
  4. Expand your sense of the possible.
  5. Don’t trouble yourself with matters you truly cannot change.
  6. Expect no more of anyone than you can deliver yourself.
  7. Tolerate ambiguity.
  8. Laugh at yourself frequently.