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
# -*- coding: utf-8 -*- | |
require "nkf" | |
fs = File.open("/home/shirai/tmp/a.csv").readlines() | |
fs = fs.map{|e| e.split(",")[1].gsub("//","/").chomp} | |
ga = <<"EOS" | |
<script type="text/javascript"> | |
var _gaq = _gaq || []; | |
_gaq.push(['_setAccount', 'UA-XXXXX-xx']); |
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(ggplot2) | |
library(reshape2) | |
url <- "http://www.mof.go.jp/international_policy/reference/itn_transactions_in_securities/week.csv" | |
dt <- read.csv(url, skip=16, header=F,fileEncoding="Shift-Jis",encoding="UTF-8") | |
dt <- dt[, c(1,2,3,5,6,9,10,13,14,16,17,20,21)] | |
dt$V1 <- as.Date(sapply(strsplit(dt$V1,"[.〜]"),function(x)paste(x[1:3],collapse="-")), "%Y-%m-%d") | |
for(i in 2:13)dt[,i] <- as.numeric(gsub(",","",dt[,i])) |
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
## vxxとvxzのロングショートの最適比率(シャープレシオ基準)を探す | |
library(quantmod) | |
library(PerformanceAnalytics) | |
getSymbols("VXZ") | |
getSymbols("VXX") | |
out <- na.omit(ROC(cbind(VXZ[,6], VXX[,6]))) | |
adj <- function(out, n1=1, n2=1){ | |
out$total <- n1*out[,1] - n2*out[,2] | |
ret <- apply(out$total, 2, sum) |
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 code is almost same as | |
## http://timelyportfolio.blogspot.jp/2012/08/horizon-on-ggplot2.html | |
## just I changed the tickers and the indicator(MACD) | |
require(quantmod) | |
require(reshape2) | |
require(PerformanceAnalytics) | |
require(xtsExtra) | |
require(RColorBrewer) |
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
##1552の日中GAPとovernightGAPの調査 | |
library(RFinanceYJ) | |
vxx <- quoteStockXtsData("1552", from="2010-12-20") | |
vxx.back <- vxx | |
vxx <- vxx.back | |
vxx$openGap <- (vxx[,1]-Lag(vxx[,4]))/Lag(vxx[,4]) | |
vxx <- merge(vxx, (Next(vxx[,1]) - vxx[,4])/Next(vxx[,1])) ### 代入だとうまくいかない。ops.zooというので | |
names(vxx)[8] <- "overNightGap" | |
vxx$dayGap <- (vxx[,4]-vxx[,1])/vxx[,1] | |
vxx <- na.omit(vxx) |
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(httr) | |
library(XML) | |
myapp <- oauth_app("google","CLIENT_ID","CLIENT_SECRETS") | |
google_token <- oauth2.0_token(oauth_endpoints("google"), | |
myapp, | |
scope = c( | |
"https://spreadsheets.google.com/feeds")) | |
##upload file | |
###get the spreadsheet info |
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
d3 = function() { | |
var d3 = { | |
version: "3.2.7" | |
}; | |
if (!Date.now) Date.now = function() { | |
return +new Date(); | |
}; | |
var d3_document = document, d3_documentElement = d3_document.documentElement, d3_window = window; | |
try { | |
d3_document.createElement("div").style.setProperty("opacity", 0, ""); |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
OlderNewer