-
Notifications
You must be signed in to change notification settings - Fork 12
/
spy-dfa.R
executable file
·44 lines (31 loc) · 1.07 KB
/
spy-dfa.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
#!/usr/bin/env R
# --no-restore --no-save -f $0
library(quantmod)
library(fractal)
# getSymbols("SPY", from="1900-01-01", src="yahoo")
# write.zoo(SPY, file="data/yahoo/SPY.csv", sep=",")
setSymbolLookup(SPY=list(src="csv",format="%Y-%m-%d",dir="data"))
SPY <- getSymbols("SPY", auto.assign=FALSE, adjust=TRUE)
SPY_CLOSE = Cl(SPY)
fractalBlock = DFA(coredata(SPY_CLOSE))
#str(fractalBlock)
#summary(fractalBlock)
DFA.walk <- fractalBlock
print(DFA.walk)
#n <- length(SPY_CLOSE); log_returns_SPY_CLOSE <- log(SPY_CLOSE[-n]/SPY_CLOSE[-1])
log_returns_SPY_CLOSE = diff(log(SPY_CLOSE))
fractalBlock = DFA(coredata(log_returns_SPY_CLOSE), detrend="poly2")
DFA.walk <- fractalBlock
print(DFA.walk)
fractalBlock = DFA(coredata(log_returns_SPY_CLOSE), detrend="poly1")
DFA.walk <- fractalBlock
print(DFA.walk)
fractalBlock = DFA(log_returns_SPY_CLOSE, detrend="poly2")
DFA.walk <- fractalBlock
print(DFA.walk)
fractalBlock = DFA(log_returns_SPY_CLOSE, detrend="poly1")
DFA.walk <- fractalBlock
print(DFA.walk)
png(filename="DFA_%03d_med.png", width=480, height=480)
eda.plot(DFA.walk)
dev.off()