-
Notifications
You must be signed in to change notification settings - Fork 0
/
BTC-USD.R
50 lines (38 loc) · 1.21 KB
/
BTC-USD.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# INGENIERÍA FINANCIERA
# Sergio Cabrales [email protected]
#################################################
install.packages('quantmod')
library("quantmod")
# BITCOIN
BITCOIN <- getSymbols("BTC-USD",from="2017-01-01", warnings = FALSE, auto.assign=FALSE)
# Omitir Missing Data
BITCOIN <- na.omit(BITCOIN)
# daily,weekly,monthly,quarterly, and yearly
dailyReturn(BITCOIN) # returns by day
weeklyReturn(BITCOIN) # returns by week
monthlyReturn(BITCOIN) # returns by month, indexed by yearmon
plot(dailyReturn(BITCOIN))
plot(monthlyReturn(BITCOIN))
allReturns(BITCOIN) # note the plural
#Charting
barChart(BITCOIN)
candleChart(BITCOIN,theme='white', type='candles')
addBBands()
addRSI()
addMACD()
addCMF()
# Return and Volatility I
ret_BITI <- dailyReturn(BITCOIN,type='log')
vol_BI <- sd(ret_BITI)*sqrt(252)
vol_BI
# Black-Scholes Option Value
blackscholes <- function(S, K, rf, T, sigma) {
values <- c(2)
d1 <- (log(S/K)+(rf+sigma^2/2)*T)/(sigma*sqrt(T))
d2 <- d1 - sigma * sqrt(T)
values[1] <- S*pnorm(d1) - K*exp(-rf*T)*pnorm(d2)
values[2] <- K*exp(-rf*T) * pnorm(-d2) - S*pnorm(-d1)
values
}
# Black-Scholes
blackscholes(16.36,16.50,0.0227,1,vol/100)