-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathquantstrat examples.R
More file actions
executable file
·37 lines (26 loc) · 1.12 KB
/
Copy pathquantstrat examples.R
File metadata and controls
executable file
·37 lines (26 loc) · 1.12 KB
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
# http://www.programmingr.com/content/installing-quantstrat-r-forge-and-source/
# install packages
install.packages("blotter", repos="http://R-Forge.R-project.org")
install.packages("quantstrat", repos="http://R-Forge.R-project.org")
library(quantstrat)
# xts objects are stored in the global environment
# portfolio and account objects are stored in .blotter environment
# currency and trading instrument objects are stored in the .instrument environment
# assign portfolio and account names
# create portfolio and account objects (blotter)
b.strategy <- "my.strategy"
initPortf(b.strategy, 'SPY', initDate='1997-12-31')
# initDate is before the start of data
initAcct(b.strategy, portfolios=b.strategy, initDate='1997-12-31', initEq=1e6)
first(SPY)
### explore objects and environments
# get all objects in the global environment
ls(all=T)
# get all objects in the .blotter environment
ls(envir=.blotter)
# get all objects in the .instrument environment
ls(envir=FinancialInstrument:::.instrument)
# show "SPY" object
get("SPY,envir=FinancialInstrument:::.instrument)
# Remove objects associated with a strategy
rm.strat(b.strategy)