quantstrat

Quantstrat: Execute on the same bar

余生颓废 提交于 2021-02-07 10:24:29
问题 I know this has been asked before here, but Id like to extend the question further. Lets say my entry price is 50, so at the start of the day I place a limit order bid 50 for 1 lot. During the trading day, the market collapses and I get filled on my bid. In a real world live trading scenario, my execution is going to be on the same daily bar at the price of 50. Even if I'm using 1 minute bars and that fill happens at 14:00 in real time, the data and prices at 14:01 are completely irrelevant

Quantstrat: apply.paramset fails due to combine error for certain paramater distributions, but not others

社会主义新天地 提交于 2020-06-17 10:05:43
问题 For some reason when I adjust the paramater distributions for apply.paramaset to include more extreme values beyond about -250 I get a simpleError saying match.names(clabs,names(xi)) names do not match previous names Sometimes this error doesn't occur when I do a very low sample size with the problem distributions but that may just be because specific paramater combos causing the problem aren't tried. What I don't get is what arguments are being fed to match.names and where which could

No results from apply.paramset if one parameter combination returns nothing

匆匆过客 提交于 2020-06-17 09:38:46
问题 I've been encountering an issue when optimizing a strategy using the apply.paramset function in quantstrat. The issue I am having appears to be the same as the one here: Quantstrat: apply.paramset fails due to combine error for certain paramater distributions, but not others The optimization works well if all of the parameter combinations return at least one transaction, however, if one of the combinations doesn't return a transaction then the results for all of the combinations are lost/NULL

Quantstrat: Ordersize function

放肆的年华 提交于 2020-03-25 13:40:29
问题 I'm new to R and I'm trying to figure out how to get quantstrat to work with a custom ordersize function. The idea is to always invest all available equity in Bitcoin so that it will be comparable to a B&H strategy. I have provided reproducible code. At first it seems to be working fine but the problem arises when I look at my orderbook. Maybe their is some mismatch between Closing prices but quantstrat doesn't order the amount of Bitcoin in accordance with the available equity. E.g. (from=

R: Quantstrat how to make a transaction for complete equity in portfolio?

≯℡__Kan透↙ 提交于 2020-01-01 12:11:10
问题 I'm still playing around with Guy Yollins quantstrat example. In this example he buys 1000 shares of the SPY when it crosses its 10 day MA. Since we define an initial equity, is it possible to always buy for the whole portfolio amount and not just 900 shares? 'all' didn't work for the enter, just the exit.. if (!exists('.blotter')) .blotter <- new.env() if (!exists('.strategy')) .strategy <- new.env() if (!exists('.instrument')) .instrument <- new.env() currency("USD") stock("SPY",currency=

Convert from R to quantstrat setup for trading strategy backtesting

丶灬走出姿态 提交于 2019-12-30 05:34:05
问题 I am trying to backtest a trading strategy with "quantstrat" package. My strategy is composed by 4 indicators, 3 different EMAs and 1 lagged EMA. I want to go long when: EMA1 > EMA2 & EMA1 > EMA3 & EMA1_lag < EMA1 I want to exit and go flat when: EMA1 < EMA3 It's pretty simple but I am not able to write it into quantstrat environment. Here's a data integrity check function used in both examples: # Data integrity check checkBlotterUpdate <- function(port.st,account.st,verbose=TRUE) { ok <-

R quantstrat: no transactions done despite all the signals

大兔子大兔子 提交于 2019-12-25 01:32:14
问题 Below is the reproducible code: library(quantstrat) start_date <- as.Date("2017-02-02") end_date <- as.Date("2018-06-24") init_date <- as.Date("2017-01-01") init_equity <- "50000" adjustment <- TRUE symbol <- "PETR4.SA" getSymbols(symbol, src = "yahoo",from = start_date, to=end_date, adjust = adjustment) portfolio.st <- "basic_port" account.st <- "basic_account" strategy.st <- "basic_strategy" rm.strat(portfolio.st) rm.strat(account.st) stock(symbol, currency = currency("BRL"), multiplier = 1

Xts conversion fails on update from xts 0.9.7 to 0.10.0

感情迁移 提交于 2019-12-24 20:15:33
问题 Dataframe to xts conversion fails on update from xts 0.9.7 to 0.10.0. #THIS WORKS (uses xts 0.9.7): library(xts) DFX <- structure(list(DateTime = structure(list(sec = c(0, 0, 0), min = c(10L, 0L, 5L), hour = c(17L, 18L, 18L), mday = c(24L, 24L, 24L), mon = c(5L, 5L, 5L), year = c(114L, 114L, 114L), wday = c(2L, 2L, 2L), yday = c(174L, 174L, 174L), isdst = c(1L, 1L, 1L), zone = c("EDT", "EDT", "EDT"), gmtoff = c(NA_integer_, NA_integer_, NA_integer_)), .Names = c("sec", "min", "hour", "mday",

Error with applyStrategy

不打扰是莪最后的温柔 提交于 2019-12-24 04:31:12
问题 I am new to R and have recently encountered the following error after running applyStrategy function from quantstrat package: Error in eval(expr, envir, enclos) : object 'signal' not found Error in `colnames<-`(`*tmp*`, value = integer(0)) : attempt to set 'colnames' on an object with less than two dimensions Could anyone please explain to me how I can debug this error and advise if I had used sigFormula correctly to combine both MACD and RSI indicators? Thank you for your help and please

Error with applyStrategy

倖福魔咒の 提交于 2019-12-24 04:31:06
问题 I am new to R and have recently encountered the following error after running applyStrategy function from quantstrat package: Error in eval(expr, envir, enclos) : object 'signal' not found Error in `colnames<-`(`*tmp*`, value = integer(0)) : attempt to set 'colnames' on an object with less than two dimensions Could anyone please explain to me how I can debug this error and advise if I had used sigFormula correctly to combine both MACD and RSI indicators? Thank you for your help and please