Skip to content

Instantly share code, notes, and snippets.

@ericjang
ericjang / globalValues.py
Created August 19, 2014 00:06
Python script that retrieves a pandas dataframe containing fundamental stock market valuation ratios
import requests
from bs4 import BeautifulSoup
import pandas as pd
import re
import sys
def globalValues:
url = 'http://www.starcapital.de/research/stockmarketvaluation?SortBy=Shiller_PE'
r = requests.get(url)
if r.status_code != 200:
@timelyportfolio
timelyportfolio / MAImp.r
Created November 29, 2011 15:31
Improved Moving Average R Function
# Function to implement a version of the improved moving average functionality
# introduced and tested in:
#
# Papailias, Fotis and Thomakos, Dimitrios D.,
# "An Improved Moving Average Technical Trading Rule,
# (September 11, 2011). Available at SSRN: http://ssrn.com/abstract=1926376
#
# Original code written by Kent Russell @ timelyportfolio.com
#
# Cross-checked by Dimitrios Thomakos on 11/29/2011, @ quantf.com
require(quantmod)
require(PerformanceAnalytics)
require(xtsExtra)
require(RColorBrewer)
#unfortunately don't feel like fighting IP lawyers so I cannot share this index data
portfolio <- read.csv("C:\\Users\\Kent.TLEAVELL_NT\\Documents\\old\\R\\lbustruu with tbill.csv",stringsAsFactors=FALSE)
portfolio <- portfolio[2:NROW(portfolio),2:NCOL(portfolio)]
portfolio <- portfolio[,c(1,3,5)]
@timelyportfolio
timelyportfolio / graph.js
Created December 5, 2012 17:30
shiny json
<style>
.node {
stroke: #fff;
stroke-width: 1.5px;
}
.link {
stroke: #999;
stroke-opacity: .6;
doInstall <- TRUE
toInstall <- c("twitteR", "dismo", "maps", "ggplot2")
if(doInstall){install.packages(toInstall, repos = "http://cran.us.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
searchTerm <- "#rstats"
searchResults <- searchTwitter(searchTerm, n = 1000) # Gather Tweets
tweetFrame <- twListToDF(searchResults) # Convert to a nice dF
userInfo <- lookupUsers(tweetFrame$screenName) # Batch lookup of user info
# Requirements
#sudo apt-get install libcurl4-gnutls-dev # for RCurl on linux
#install.packages('RCurl')
#install.packages('RJSONIO')
library('RCurl')
library('RJSONIO')
query <- function(querystring) {
h = basicTextGatherer()
@catherinedevlin
catherinedevlin / gist:6588378
Last active December 23, 2015 05:39
IPython Notebook: your new SQL Client (lightning talk from PostgresOpen 2013)
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
@timelyportfolio
timelyportfolio / code.R
Last active June 23, 2016 01:22
rCharts Implements d3.js Sankey Plugin
require(rCharts)
require(rjson)
#get source from original example
#this is a JSON, so will need to translate
#this is complicated and unnecessary but feel I need to replicate
#for completeness
#expect most data to come straight from R
#in form of source, target, value
@alexbbrown
alexbbrown / d3widget.js
Last active October 18, 2016 20:58 — forked from anonymous/d3widget.js
Simple Shiny Example of Javascript Input and Output
<script src="http://d3js.org/d3.v3.js"></script>
<script type="text/javascript">
(function(){
// Probably not idiomatic javascript.
this.countValue=0;
updateView = function(message) {
var svg = d3.select(".d3io").select("svg")
@dsparks
dsparks / update R.R
Created April 12, 2014 12:02
Updating to a new version of R
# installing/loading the latest installr package:
install.packages("installr"); require(installr) #load / install+load installr
updateR()
# Then just follow the prompts...