Skip to content

Instantly share code, notes, and snippets.

View kimiyuki's full-sized avatar
🏠
Working from home

kimiyuki shirai kimiyuki

🏠
Working from home
View GitHub Profile
@kimiyuki
kimiyuki / facets.ipynb
Created August 26, 2018 11:43
facets.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kimiyuki
kimiyuki / F1-simulation.ipynb
Last active November 29, 2017 14:20
F1-simulation.ipynb
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.
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, "");
@kimiyuki
kimiyuki / upload_row_to_google-spreadsheet.r
Created August 12, 2014 16:58
Rでgoogle spreadsheetにデータを上げる(一行づつ)
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
@kimiyuki
kimiyuki / 1552_gap
Created November 19, 2012 15:15
##1552の日中GAPとovernightGAPの調査
##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 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)
## 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)
### 財務省の海外投資家の流出入の変遷
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]))
# -*- 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']);