Skip to content

Instantly share code, notes, and snippets.

View timelyportfolio's full-sized avatar

timelyportfolio timelyportfolio

View GitHub Profile
\documentclass[nohyper,justified]{tufte-handout}
%\documentclass{article}
%great guides at epslatex.pdf
%check miniplot for potential use
%\usepackage{graphics}
%\usepackage{caption}
%\usepackage{sidecap}
%\usepackage{textpos}
%\usepackage[section]{placeins}
require(fGarch)
require(ttrTests)
require(quantmod)
require(PerformanceAnalytics)
getSymbols("^GSPC",from="1900-01-01")
#get monthly close prices from daily
price.monthly<-to.monthly(GSPC)[,4]
#get dates in yyyy-mm-01 format
index(price.monthly) <- as.Date(index(price.monthly))
#do a pretty correlation on heat map on all Pimco Funds (institutional share class) that have existed longer 5 years
#symbol list obtained from
#http://investments.pimco.com/Products/pages/PlOEF.aspx?Level1=ulProducts&Center=ulProducts&Level2=liulProductsMutualFunds
#pasted into Excel and sorted by 5 yr return
#then copied and pasted transpose
#saved to csv
#and pasted in this ticker list eliminating the money fund and adding Vanguard S&P 500 for reference
tckrs <- c("PISIX","PSKIX","PSDIX","PSTKX","PCRIX","PFIIX","PHMIX","PFCIX","PCDIX","PTSHX","PFMIX","PLMIX","PSPTX","PCIMX","PSTIX","PNYIX","PLDTX","PLDIX","PTLDX","PAAIX","PXTIX","PHIYX","PSCSX","PAUIX","PTRIX","PGBIX","PFORX","PELBX","PDMIX","PMDRX","PEBIX","PDIIX","PRRSX","PMBIX","PTSAX","PTTRX","PIGLX","PRRIX","PFUIX","PIMIX","PIGIX","PRAIX","PLRIX","PGOVX","PEDIX","VFINX")
for (i in 1:length(tckrs)) {
@timelyportfolio
timelyportfolio / horizon plot.r
Created June 15, 2012 20:18
R Horizon Chart
require(lattice)
require(latticeExtra)
require(reshape2)
require(quantmod)
#set up horizon plots as a function
horizonplot <- function(prices,horizon.type="offset",scale=0.05,title=NA,alpha=0.4){
#get change in prices since beginning or 1st row
prices.change <- prices[,4]/as.numeric(prices[1,4])-1
#get as a data.frame so it will work well with melt and lattice
@timelyportfolio
timelyportfolio / rut where are fat tails.r
Created June 19, 2012 17:47
Where are RUT fat tails
require(lattice)
require(latticeExtra)
require(directlabels)
require(reshape2)
require(quantmod)
require(PerformanceAnalytics)
#I will use a csv file of weekly returns to get more history
#but if you do not have access to that then use getSymbols for data to 1987
#getSymbols("^RUT",from="1900-01-01")
#do preliminary exploration of paper Why Trend is Not Your Friend
#http://www.frankfurt-school.de/clicnetclm/fileDownload.do?goid=000000311260AB4
#by Peter Scholz and Ursula Walther
#load table 2:Descriptive statistics of 35 leading equity indices
table2 <- read.csv("https://raw.github.com/gist/2996948/31d22bf58aad9f8421f419d659da90c4b3e0bcf0/table2.csv")
#load table 21: Average excess return from timing in the 35 selected leading equity indices
table21 <- read.csv("https://raw.github.com/gist/2996948/8ee5c1d6680fc592c99a68027d2381701c66bb22/table21.csv")
#I included the source at the end of attribution, so let's get rid of that
table2 <- table2[1:(NROW(table2)-2),]
@timelyportfolio
timelyportfolio / csv-to-json.php
Created June 27, 2012 20:58 — forked from robflaherty/csv-to-json.php
Convert Yahoo Finance CSV to JSON for use with d3.js
<?php
/*
* Converts CSV to JSON
* Example uses Google Spreadsheet CSV feed
* csvToArray function I think I found on php.net
*/
header('Content-type: application/json');
// Set your CSV feed
@timelyportfolio
timelyportfolio / index.html
Created June 27, 2012 21:37
ripoff d3.js dji-area example but use direct yahoo finance feed
<!DOCTYPE html>
<html>
<head>
<title>d3.js with Direct Yahoo Finance</title>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js?2.3.0"></script>
<style type="text/css">
body {
font: 10px sans-serif;
#should have known R already has horizon plot functionality
#latticeExtra (already a favorite package of mine) has it sitting right there
#http://rgm2.lab.nig.ac.jp/RGM2/func.php?rd_id=latticeExtra:horizonplot
require(lattice)
require(latticeExtra)
require(reshape2)
require(quantmod)
@timelyportfolio
timelyportfolio / index.html
Created July 13, 2012 18:19
d3 Axys Integration
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>d3.js Axys Chart</title>
<!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
Remove this if you use the .htaccess -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<script src="http://d3js.org/d3.v2.min.js?2.9.1"></script> <style>