ilyakipnis / iktrading Goto Github PK
View Code? Open in Web Editor NEWIlya Kipnis's miscellaneous quantstrat extensions, indicators, and order-sizing functions.
Ilya Kipnis's miscellaneous quantstrat extensions, indicators, and order-sizing functions.
Hi Ilya, thanks so much for offering your datacamp course. I'm just having an issue building the IKTrading and DSTrading package.
My computer runs R on Windows 7, 64bit version. I have loaded RTools40 and devtools. I've installed Quantstrat and Blotter but can't install IKTrading or DSTrading from your github. I'm wondering if you might know why? This is the output in my console when I attempt to install from Github. It appears to be hung up on compilation. Any help would be much appreciated:
` install_github("IlyaKipnis/IKTrading")
Downloading GitHub repo IlyaKipnis/IKTrading@HEAD
√ checking for file 'C:\Users\blhodder\AppData\Local\Temp\RtmpioKKbu\remotes4ec73d5414e\IlyaKipnis-IKTrading-0b4e0e5/DESCRIPTION' (806ms)
Installing package into ‘\file086/A14$/My Documents/R/win-library/4.0’
(as ‘lib’ is unspecified)
'\file086\A14$\My Documents'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory.
*** arch - i386
"C:/rtools40/mingw32/bin/"g++ -std=gnu++11 -I"C:/PROGRA1/R/R-401.2/include" -DNDEBUG -I'\file086/A14My Documents/R/win-library/4.0/xts/include' -I'\file086/A14My Documents/R/win-library/4.0/Rcpp/include' -I'\file086/A14My Documents/R/win-library/4.0/inline/include' -I'\file086/A14My Documents/R/win-library/4.0/TTR/include' -I'\file086/A14My Documents/R/win-library/4.0/quantmod/include' -I'C:/Program Files/R/R-4.0.2/library/stats/include' -I'\file086/A14My Documents/R/win-library/4.0/digest/include' -I'\file086/A14My Documents/R/win-library/4.0/roxygen2/include' -O2 -Wall -mfpmath=sse -msse2 -mstackrealign -c RcppExports.cpp -o RcppExports.o
RcppExports.cpp:4:10: fatal error: Rcpp.h: No such file or directory
#include <Rcpp.h>
^~~~~~~~
compilation terminated.
make: *** [C:/PROGRA1/R/R-401.2/etc/i386/Makeconf:229: RcppExports.o] Error 1
ERROR: compilation failed for package 'IKTrading'
`
Using the ichimoku indicator, I am attempting to plot Ichimoku Cloud, with the below implementation:
require(quantmod)
require(IKTrading)
getSymbols('IBM', src='google', from='2014-04-01')
ibm_ic = ichimoku(IBM)
ibm_icPlot <- ibm_ic[,1:5]
chart.TimeSeries(ibm_icPlot, legend.loc = "topleft")
After running the above code, all the five lines are rendered in the Chart (i.e. turning line, base line, Span A, Span B, plotSpan), here's the screenshot of my RStudio with the plot:
Well, the problem is with the 'Span A' & 'Span B' lines (i.e. future cloud), which are not projected ('nMed=26') into the future. This projection is very important aspect of visualizing an Ichimoku Cloud in its entirety. Any suggestion on how to make the ichimoku indicator to plot the future cloud? Or is there something wrong in the above implementation?
If you use the sigAND signal in sequential mode, there are no problems using doParallel, but in parallel mode, it results in this error. Apparently this is not compatible, but I'd think many users of this handy signal would want to run tests in parallel. Cod below reproduces the issue
error calling combine function:
<simpleError in results[[r$portfolio.st]] <- r: attempt to select less than one element>
`####################################################################
library(dplyr)
suppressMessages(require(quantstrat))
require(IKTrading)
rm(list = ls(all.names = T))
if(!exists(".instrument")) .instrument <<- new.env()
if(!exists(".blotter")) .blotter <<- new.env()
if(!exists(".strategy")) .strategy <- new.env()
initDate = "2000-01-01"
symbol.st = 'CYB_DAY'
portf.st = 'bug'
acct.st = 'colony'
strat.st = 'bee'
initEq = 100000
nFast = 10
nSlow = 30
nSd = 1
setwd("/Users/tyamada/Google Drive/CFRM551/supplemental/")
currency('USD') # initiate currency
stock(symbol.st ,currency='USD', multiplier=1) # initiate stock
getSymbols(Symbols = symbol.st, src = "csv")
initPortf(
portf.st,
symbol.st,
initDate=initDate) # initiate portfolio
initAcct(
acct.st,
portf.st,
initEq=initEq,
initDate=initDate) # initiate account
initOrders(
portf.st,
initDate=initDate ) # initiate order_book
bee = strategy(strat.st) # create strategy object
addPosLimit(
portfolio=portf.st,
symbol=symbol.st,
timestamp=initDate,
maxpos=300, longlevels = 3) # only trade in one direction once
bee <- add.indicator(
strategy = strat.st,
name = 'BBands', # TA name
arguments = list(HLC=quote(HLC(mktdata)),
n=nSlow,
sd=nSd),
label = 'BBand')
bee <- add.indicator(
strategy = strat.st,
name = 'SMA', # TA name
arguments = list(x=quote(Cl(mktdata)),
n=nFast),
label = 'MA' )
bee <- add.signal(
strategy = strat.st,
name = 'sigCrossover',
arguments = list(columns=c('MA','dn'),
relationship='lt'),
label = 'MA.lt.dn')
bee <- add.signal(
strategy = strat.st,
name = 'sigCrossover',
arguments = list(columns=c('MA','up'),
relationship='gt'),
label = 'MA.gt.up')
add.signal(strat.st, name="sigAND",arguments=list(columns=c("MA.lt.dn","MA.gt.up"),cross=TRUE),label="unlikleyCross")
bee <- add.rule(
strategy = strat.st,
name = 'ruleSignal',
arguments = list(sigcol = 'MA.gt.up',
sigval = TRUE,
replace = F,
orderqty = 100,
ordertype = 'market',
# one of "market","limit","stoplimit", "stoptrailing", or "iceberg"
orderside = 'long',
osFUN = 'osMaxPos'),
type = 'enter',
label = 'EnterLONG')
bee <- add.rule(
strategy = strat.st,
name = 'ruleSignal',
arguments = list(sigcol = 'unlikleyCross',
sigval = TRUE,
replace = F,
orderqty = 500,
ordertype = 'market',
# one of "market","limit","stoplimit", "stoptrailing", or "iceberg"
orderside = 'long',
osFUN = 'osMaxPos'),
type = 'enter',
label = 'EnterLONGBIG')
bee <- add.rule(
strategy = strat.st,
name = 'ruleSignal',
arguments = list(sigcol = 'MA.lt.dn',
sigval = TRUE,
replace = F,
orderqty = 'all',
ordertype = 'market',
orderside = 'long'),
type = 'exit',
label = 'ExitLONG')
bee <- add.rule(
strategy = strat.st,
name = 'ruleSignal',
arguments = list(sigcol = 'MA.lt.dn',
sigval = TRUE,
replace = F,
orderqty = -100,
ordertype = 'market',
orderside = 'short',
osFUN = 'osMaxPos'),
type = 'enter',
label = 'EnterSHORT')
bee <- add.rule(
strategy = strat.st,
name = 'ruleSignal',
arguments = list(sigcol = 'MA.gt.up',
sigval = TRUE,
replace = F,
orderqty = 'all',
ordertype = 'market',
orderside = 'short'),
type = 'exit',
label = 'ExitSHORT')
applyStrategy(
strat.st,
portf.st,
prefer='Open', # why prefer='Open'
verbose=T)
updatePortf(
portf.st) #,
updateAcct(
acct.st) # ,
updateEndEq(
Account = acct.st)#,
.nFastList = 5:13
.nSlowList = 10:40
.nSdList = 1:3
.nsamples = 10
add.distribution(strat.st,
paramset.label = 'SMA_BBparams',
component.type = 'indicator',
component.label = 'BBand', #this is the label given to the indicator in the strat
variable = list(n = .nSlowList),
label = 'BBandMA'
)
add.distribution(strat.st,
paramset.label = 'SMA_BBparams',
component.type = 'indicator',
component.label = 'BBand', #this is the label given to the indicator in the strat
variable = list(sd = .nSdList),
label = 'BBandSD'
)
add.distribution(strat.st,
paramset.label = 'SMA_BBparams',
component.type = 'indicator',
component.label = 'MA', #this is the label given to the indicator in the strat
variable = list(n = .nFastList),
label = 'MAn'
)
add.distribution.constraint(strat.st,
paramset.label = 'SMA_BBparams',
distribution.label.1 = 'BBandMA',
distribution.label.2 = 'MAn',
operator = '>',
label = 'BBandMA>MAn'
)
if( Sys.info()['sysname'] == "Windows" )
{
library(doParallel)
registerDoParallel(cores=detectCores())
registerDoSEQ()
} else {
library(doMC)
registerDoMC(cores=detectCores())
}
results <- apply.paramset(strat.st,
paramset.label='SMA_BBparams',
portfolio.st=portf.st,
account.st=acct.st,
samples= 0, # take all options
#.nsamples, only take 10 samples
verbose=TRUE)
results$tradeStats %>% View()
`
Needs to be updated to work with the new columns in the ICE futures contracts.
Error in colnames<-
(*tmp*
, value = c("O", "H", "L", "C", "V", "OI" :
length of 'dimnames' [2] not equal to array extent
Hi there,
sorry to bother - I can't install IKTrading and DSTrading for R3.3.0 because they're built under a previous version of R. I downloaded the zips from github.com (IKTrading-master.zip and DSTrading -master.zip), but after installation from local files they are still not recognised by R (GUI and also RStudio).
Is there a way to solve this (I'm actually trying to run the 'Nuts & Bolts I-IV examples - maybe there's a newer library instead of those to use)?
Best
Hi,
I'm trying to install this package from source. Unfortunately, no luck.
Can you please tell me how to fix this. Alternatively, if you have a precompiled version, that would be great.
Thanks.
Warning: running command 'make -f "C:/PROGRA1/R/R-311.1/etc/i386/Makeconf" -f "C:/PROGRA1/R/R-311.1/share/make/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="IKTrading.dll" OBJECTS="RcppExports.o RcppFuns.o"' had status 127
ERROR: compilation failed for package 'IKTrading'
I get the error in line 124.
Error in as.Date.numeric(dates) : 'origin' must be supplied
I cloned the repository and added some cats
cat(head(dates))
cat(str(dates))
cat(head(index(returnsData)))
originalOld <- FAAreturns(adPrices, riskFreeName="VFISX")
10165 10193 10226 10256 10284 10316
num [1:205] 10165 10193 10226 10256 10284 ...
16251 16252 16253 16254 16258 16259
Show Traceback
Rerun with Debug
Error in as.Date.numeric(dates) : 'origin' must be supplied
Hi,
I am using tidyquant which loads dplyr. Unfortunately, the lag function from dplyr is masking the lag from stats. Would you consider updating your lagATR function to explicitly call stats::lag(ATR,lag)?
I currently have the following hack prior to applyIndicators:
lag <- stats::lag
applyIndicators(strategy.st, mktdata=OHLC(MSFT))
Thank you for this great package!
I am on Windows 10. Following the R bloggers code recently published on Quantstrat.
install_github("IKTrading", username = "IlyaKipnis")
When I run this code I get this:
install_github("IKTrading", username = "IlyaKipnis")
Downloading GitHub repo IlyaKipnis/IKTrading@master
from URL https://api.github.com/repos/IlyaKipnis/IKTrading/zipball/master
Installing IKTrading
Installing 1 package: digest
Installing package into ‘C:/Users/Matt/Documents/R/win-library/3.3’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.3/digest_0.6.12.zip'
Content type 'application/zip' length 172732 bytes (168 KB)
downloaded 168 KB
package ‘digest’ successfully unpacked and MD5 sums checked
Warning: cannot remove prior installation of package ‘digest’
The downloaded binary packages are in
C:\Users\Matt\AppData\Local\Temp\RtmpOaRqoz\downloaded_packages
Installing 1 package: quantmod
Installing package into ‘C:/Users/Matt/Documents/R/win-library/3.3’
(as ‘lib’ is unspecified)
Warning: package ‘quantmod’ is in use and will not be installed
"C:/PROGRA1/R/R-331.3/bin/x64/R" --no-site-file --no-environ --no-save --no-restore --quiet CMD INSTALL
"C:/Users/Matt/AppData/Local/Temp/RtmpOaRqoz/devtools2b946dd67cef/IlyaKipnis-IKTrading-0b4e0e5"
--library="C:/Users/Matt/Documents/R/win-library/3.3" --install-tests
ERROR: dependency 'digest' is not available for package 'IKTrading'
When I try the username "IllyKipnis/IKTrading" I get this error:
nstall_github("IKTrading", username = "IlyaKipnis/IKTrading")
Downloading GitHub repo IlyaKipnis/IKTrading/IKTrading@master
from URL https://api.github.com/repos/IlyaKipnis/IKTrading/IKTrading/zipball/master
Error in stop(github_error(request)) : Not Found (404)
In addition: Warning message:
Username parameter is deprecated. Please use IlyaKipnis/IKTrading/IKTrading
Any ideas how to proceed?
Hi,
I tried installing IKTrading. I am getting the error below. Could you please help? You have an excellent blog. Thanks.
install_github("ilyakipnis/iktrading")
package ‘inline’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\sjs\AppData\Local\Temp\Rtmpaoujit\downloaded_packages
"C:/PROGRA1/R/R-311.2/bin/x64/R" --vanilla CMD INSTALL
"C:/Users/sjs/AppData/Local/Temp/Rtmpaoujit/devtools13cc3fe0360e/IlyaKipnis-IKTrading-0b4e0e5"
--library="C:/Users/sjs/Documents/R/win-library/3.1" --install-tests
*** arch - i386
Warning: running command 'make -f "C:/PROGRA1/R/R-311.2/etc/i386/Makeconf" -f "C:/PROGRA1/R/R-311.2/share/make/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="IKTrading.dll" OBJECTS="RcppExports.o RcppFuns.o"' had status 127
ERROR: compilation failed for package 'IKTrading'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.