Blotter & Quantstrat - Buy only strategy without any exit

96 views Asked by At

I am trying to implement a buy and hold strategy without any exit. Simple example: using sigFormula to buy when both RSI is long and SMA(sigcomparison) is long. Till here, the strategy throws all the trades and it works perfectly fine.

However, I would now like to see from a list of 200 tickers that I have used what are the recent trades. I am buying only one stock in each trade. So, is there a way to get all transactions sorted by date to find out what the algorithm is telling me to buy in the recent past, say last one month, one week or day?

Basically i am looking for a report by quantity not by weights(calcPortfWgt) or by performance (instrPL). I want to see if there are any additions to existing quantities over a period of time.

1

There are 1 answers

0
Amrith On

I think, I have a workaround for now. I am new to R, so, the workaround may not be tidy. It would be great if anyone can share an easier way to do this.

order_book <- getOrderBook(portfolio = portfolio.st)
order_book <- unlist(order_book, recursive = FALSE)
order_book <- lapply(order_book, FUN = tk_tbl)
order_book <-
  lapply(order_book, function(x)
    x[(names(x) %in% c("index", "Order.Qty", "Order.Price"))])
order_book <-
  lapply(order_book, setNames, c("Date", "Order.Qty", "Order.Price"))
order_book <- imap(order_book, ~ mutate(.x, Symbol = .y))
order_book <- do.call("rbind", order_book)
order_book <- order_book[, c(1, 4, 2, 3)]
order_book <- order_book %>% arrange(Date, decreasing = TRUE)
View(order_book)
#write.csv(order_book,"orderbook.csv", row.names = FALSE)