3

I'm new to R and quantstrat, so I appreciate your patience.

I note that a lot of the demo / example files around the web for quantstrat give great examples using TA rules.

My Question / TL;DR

How can I construct a simple intraday threshold crossing rule in quantstrat without using any TA using an opening price and subsequent intraday data?

Data Structure

Assume the instrument is a stock with ticker XYZ

XYZ is stored as an xts object of intraday (1min) OHLC data. IE:

2014-05-30 15:55:00 148.6231 148.6239 148.6632 148.7173
2014-05-30 15:56:00 148.7574 148.7373 148.7976 148.7976
2014-05-30 15:57:00 148.7775 148.7844 148.7976 148.7775
2014-05-30 15:58:00 148.7574 148.7443 148.7706 148.8246
2014-05-30 15:59:00 148.7574 148.8115 148.9586 148.9051
2014-05-30 16:00:00 148.8649 148.8919 148.9586 148.8919

which, via, to.daily(), looks like this:

2014-05-23   145.5871   146.8550  145.5196    146.0925
2014-05-26   146.2252   146.3783  145.7475    145.7497
2014-05-27   145.8070   146.1233  145.4283    145.7542
2014-05-28   146.0079   146.2983  145.5477    145.7511
2014-05-29   147.3544   147.7388  147.1623    147.4640
2014-05-30   147.3642   148.8919  147.4933    148.8919

Trade I'm trying to construct

What I would like to test (as a simple starting point) is:

  1. the profitability of shorting XYZ when it has risen more than n bps away from the open on a given day, and exiting at closing price.
  2. the profitability of buying XYZ when it has fallen more than n bps on a given day - again, exiting on the close.

Example Problem

  1. On 2014-05-30 in the data above, the opening price was 147.36.
  2. I would like to short if XYZ is > 50 bps up from its opening print (ie 147.34*1.005 = 148.08. 148.08 is now my "up" threshold).
  3. Conversely, I would like to get long if XYZ is < -50 bps down from its opening print (ie 147.34*.995 = 146.60). 146.60 is now my "down" threshold).
  4. In both cases, the exit would be the closing price of that day.
  5. Ideally, my code would evaluate whether the Close of each minute bar is <> the signal threshold price (derived from the open price) and them enter transactions to blotter accordingly.
  6. Happy with any answers to get me started, but especially if you can show some toy examples of handling order size (ie, once threshold is crossed, it will probably extend that move for a while before the anticipated reversion happens - not sure how to get quantstrat to handle that)

Apologies if this is stupidly simple. I've tried playing around with different examples and demos, but can't quite seem to get it right and would appreciate any help on how to set up this query correctly

rStack
  • 31
  • 1
  • I don't currently have time to write a full answer, but you need a custom `sigChangeFromOpen` function. Look at `quantstrat::sigTimestamp` for guidance. You could use a trailing stop as an entry for #6 (i.e. after XYZ has risen 50bps, you enter a trailing sell order for X points below the highest price). – Joshua Ulrich Jul 17 '14 at 14:40

0 Answers0