> So if the strategy involves 1000 stocks quantstrat's object would get 1000 additional columns?
No. Each stock is passed in as its own object in initialization. And each stock would need its own separate additional column. > Does this mean, when there are multiple entry signals at the same day and time and I like to discard some of them (because of insufficient cash) that I can not do this on a random basis? The idea would be to add a Monte Carlo simulation at such points, but I'm not sure how long such a calculation would take. Quantstrat processes instruments one at a time. It is not aware of positions in other instruments. There are ways to get at the order book and extract signals/positions to potentially do further calculations later, but that would be outside of the scope of the quantstrat simulation. > What do you mean by this? If you have 1,000 instruments, each with 10 signals, quantstrat would need 10,000 steps in that loop to run the simulation. > I just referred to the time stop rule one paragraph above. The exit should be like a three-leg logical or-rule: > My trades start at EntryDate, EntryTime and exit (at the latest) with the close of the last bar of ExitDate. But a trade is closed out earlier, if a take profit or a stop loss is met. > So if at any day during the trade's lifetime a bar at 3:55 PM EST (or whenever) mets a take profit or a stop loss, the trade should be closed - even if the last bar of ExitDate is not yet reached. Order chaining (one cancels the other) can take care of that. See this post I made a long time ago: A Hammer Trading System — Demonstrating Custom Indicator-Based Limit Orders in Quantstrat | QuantStrat TradeR <https://quantstrattrader.com/2014/08/18/a-hammer-trading-system-demonstrating-custom-indicator-based-limit-orders-in-quantstrat/> While that basically uses a custom R package that I haven't updated in years, the idea is that you can add your basic entry and exit rules (though I'm not quite sure how a time-to-exit rule would work with intraday data--I suppose it could be something like the max time before 4:00 PM EST on the date of exit), and then you can create chain orders based off of your basic exit rule to override it with a take profit or stop loss. On Wed, Dec 18, 2024 at 7:10 PM Mike <[email protected]> wrote: > Ilya, > > > Yes, you definitely can. You can definitely inject pre-generated > > signals as additional columns on your data ahead of time, and then > > use add.signal to work with them later, skipping the add.indicator > > step entirely. > > So if the strategy involves 1000 stocks quantstrat's object would > get 1000 additional columns? > > > Quantstrat/R *can* handle such an amount of data, but understand that > > quantstrat will loop over each instrument individually, > > Does this mean, when there are multiple entry signals at the same > day and time and I like to discard some of them (because of > insufficient cash) that I can not do this on a random basis? The idea > would be to add a Monte Carlo simulation at such points, but I'm not > sure how long such a calculation would take. > > > and the loops > > occur by signal observations. > > What do you mean by this? > > > That said, the "handle these prior to close" is a bit *vague* as far > > as objective implementation goes. What does "prior to close" mean? > > 3:55 PM EST? > > I just referred to the time stop rule one paragraph above. The exit > should be like a three-leg logical or-rule: > > My trades start at EntryDate, EntryTime and exit (at the latest) > with the close of the last bar of ExitDate. But a trade is closed out > earlier, if a take profit or a stop loss is met. > > So if at any day during the trade's lifetime a bar at 3:55 PM EST > (or whenever) mets a take profit or a stop loss, the trade should be > closed - even if the last bar of ExitDate is not yet reached. > > Thanks > Mike > > > > On Wed, Dec 18, 2024 at 5:40 PM Mike <[email protected]> wrote: > > > > > My strategy involves a universe with more than 1000 stocks. Since > > > the entry rules are complex, I've generated the entry signals with > > > a separate program. The resulting table for entry signals includes > > > these columns: Symbol, EntryDate, EntryTime, ExitDate. > > > > > > The backtest has to run on intraday basis. I have intraday data > > > OHLCV for every stock involved. The period to be tested spans > > > several years. > > > > > > Each trade has to be closed market on close on ExitDate at the > > > latest (time stop). > > > > > > Stop loss and take profit have to be handled prior to close on > > > ExitDate. Stop loss has to be tightened up once if a profit target > > > is met. > > > > > > Can I backtest such a type of strategy using quantstrat? > > > Especially: > > > - Can I inject pre-generated signals to quantstrat? > > > - Can quantstrat/R handle such an amount of data? > > > > > > Mike > > _______________________________________________ > [email protected] mailing list > https://stat.ethz.ch/mailman/listinfo/r-sig-finance > -- Subscriber-posting only. If you want to post, subscribe first. > -- Also note that this is not the r-help list where general R questions > should go. > [[alternative HTML version deleted]] _______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.
