Last active
August 29, 2015 14:18
-
-
Save egorvodkin/3882d881c0db0747731f to your computer and use it in GitHub Desktop.
Currencies data export from OANDA
This file contains hidden or 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
#Start | |
########################################################################################## | |
#Initializing library quantmod - Подключаем библиотеку для сбора данных | |
library(quantmod) | |
#Loading currenices data from OANDA - Загружаем данные | |
getSymbols("AED/USD",src="oanda",from="2013-01-01", to=Sys.Date()) | |
getSymbols("AUD/USD",src="oanda",from="2013-01-01", to=Sys.Date()) | |
getSymbols("BRL/USD",src="oanda",from="2013-01-01", to=Sys.Date()) | |
getSymbols("CAD/USD",src="oanda",from="2013-01-01", to=Sys.Date()) | |
getSymbols("CHF/USD",src="oanda",from="2013-01-01", to=Sys.Date()) | |
getSymbols("CNY/USD",src="oanda",from="2013-01-01", to=Sys.Date()) | |
getSymbols("CZK/USD",src="oanda",from="2013-01-01", to=Sys.Date()) | |
getSymbols("DKK/USD",src="oanda",from="2013-01-01", to=Sys.Date()) | |
getSymbols("EUR/USD",src="oanda",from="2013-01-01", to=Sys.Date()) | |
getSymbols("GBP/USD",src="oanda",from="2013-01-01", to=Sys.Date()) | |
getSymbols("HKD/USD",src="oanda",from="2013-01-01", to=Sys.Date()) | |
getSymbols("IDR/USD",src="oanda",from="2013-01-01", to=Sys.Date()) | |
getSymbols("ILS/USD",src="oanda",from="2013-01-01", to=Sys.Date()) | |
getSymbols("INR/USD",src="oanda",from="2013-01-01", to=Sys.Date()) | |
getSymbols("JPY/USD",src="oanda",from="2013-01-01", to=Sys.Date()) | |
getSymbols("KRW/USD",src="oanda",from="2013-01-01", to=Sys.Date()) | |
getSymbols("KZT/USD",src="oanda",from="2013-01-01", to=Sys.Date()) | |
getSymbols("MAD/USD",src="oanda",from="2013-01-01", to=Sys.Date()) | |
getSymbols("MXN/USD",src="oanda",from="2013-01-01", to=Sys.Date()) | |
getSymbols("MYR/USD",src="oanda",from="2013-01-01", to=Sys.Date()) | |
getSymbols("PHP/USD",src="oanda",from="2013-01-01", to=Sys.Date()) | |
getSymbols("PLN/USD",src="oanda",from="2013-01-01", to=Sys.Date()) | |
getSymbols("RON/USD",src="oanda",from="2013-01-01", to=Sys.Date()) | |
getSymbols("RUB/USD",src="oanda",from="2013-01-01", to=Sys.Date()) | |
getSymbols("SEK/USD",src="oanda",from="2013-01-01", to=Sys.Date()) | |
getSymbols("SGD/USD",src="oanda",from="2013-01-01", to=Sys.Date()) | |
getSymbols("THB/USD",src="oanda",from="2013-01-01", to=Sys.Date()) | |
getSymbols("TRY/USD",src="oanda",from="2013-01-01", to=Sys.Date()) | |
getSymbols("TWD/USD",src="oanda",from="2013-01-01", to=Sys.Date()) | |
getSymbols("UAH/USD",src="oanda",from="2013-01-01", to=Sys.Date()) | |
getSymbols("USD/USD",src="oanda",from="2013-01-01", to=Sys.Date()) | |
getSymbols("VND/USD",src="oanda",from="2013-01-01", to=Sys.Date()) | |
getSymbols("ZAR/USD",src="oanda",from="2013-01-01", to=Sys.Date()) | |
getSymbols("NZD/USD",src="oanda",from="2013-01-01", to=Sys.Date()) | |
getSymbols("HUF/USD",src="oanda",from="2013-01-01", to=Sys.Date()) | |
getSymbols("NOK/USD",src="oanda",from="2013-01-01", to=Sys.Date()) | |
#Merging data to one object - Собираем данные в одну xts-табличку | |
currencies<-merge(AEDUSD, | |
AUDUSD, | |
BRLUSD, | |
CADUSD, | |
CHFUSD, | |
CNYUSD, | |
CZKUSD, | |
DKKUSD, | |
EURUSD, | |
GBPUSD, | |
HKDUSD, | |
IDRUSD, | |
ILSUSD, | |
INRUSD, | |
JPYUSD, | |
KRWUSD, | |
KZTUSD, | |
MADUSD, | |
MXNUSD, | |
MYRUSD, | |
PHPUSD, | |
PLNUSD, | |
RONUSD, | |
RUBUSD, | |
SEKUSD, | |
SGDUSD, | |
THBUSD, | |
TRYUSD, | |
TWDUSD, | |
UAHUSD, | |
USDUSD, | |
VNDUSD, | |
ZARUSD, | |
NZDUSD, | |
HUFUSD, | |
NOKUSD) | |
#Deleting unneccesary sumbols - Убираем лишние символы | |
renamer <- function(x, pattern, replace) { | |
for (i in seq_along(pattern)) | |
x <- gsub(pattern[i], replace[i], x) | |
x | |
} | |
colnames(currencies) <- renamer( | |
colnames(currencies), | |
"....$", | |
"" | |
) | |
#Transforming to dataframe - Преобразуем в датафрейм с добавлением столбца даты | |
currencies<-data.frame(Date=index(currencies), coredata(currencies)) | |
#CSV export - Экспортируем в CSV | |
write.csv(currencies, "2013_Current.csv") | |
########################################################################################## | |
#End | |
#Transforming data to tidy format for further usage Преобразуем в правильный формат чистых данных | |
library(tidyr) | |
currencies1<-gather(currencies, "currency","n", 2:37) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment