Re: [R-SIG-Finance] quantstrat with intraday data

2012-05-03 Thread G See
Jim,

So, on any day that there is a dividend or a split, you want to back
adjust your data that you're using to calculate the next signal.
Every time you back-adjust, you have to recreate your signals.  If
that's how you want to do it, then I think that in quantstrat world,
you're better off running multiple backtests (e.g. 1 for each quarter
for a stock that pays quarterly dividends) and gluing them together
instead of adjusting on the fly.  i.e. try to let the quantstrat part
of it be as vectorized as possible.

If there were an addSplit function, it would adjust the quantity of
shares that you own, but last I looked, the order-sizing functionality
of quantstrat was still broken which means that you wouldn't be able
to adjust how many shares you trade going forward.

So, assuming you're using a fixed quantity of shares for your
transactions (which you are unless you patch quantstrat ;-)),
AddCumDiv is like a walk-forward adjustment of price (for dividends,
but you could pre-adjust your data, in a walk-forward manner, for
splits as well).  At the very least, it's pretty good proxy.

HTH,
Garrett

On Wed, May 2, 2012 at 11:19 PM, Jim Green
student.northwest...@gmail.com wrote:
 On 3 May 2012 00:07, G See gsee...@gmail.com wrote:
 If a stock splits in half, don't you think you should adjust for that
 before performing technical analysis?  You'd treat that big jump in
 price the same as a real price jump even though if you had a position
 in the stock, your PnL would be unaffected by the split?

 sorry I was unclear... that would generate wrong signals..  I think
 the correct way to use split/dividend adjusted daily data for
 technical analysis is:
 1, for each day, generate signals using adjusted data till before that
 day, in a walking forward fashion.
 2, for pnl logistics, use trade based adjustments or position adjustments.

 the above are not currently supported by quantstrat and underlying
 blotter but is really a nice to have. is qmao addressing the them in
 some way?

 Jim.

___
R-SIG-Finance@r-project.org 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.


Re: [R-SIG-Finance] quantstrat with intraday data

2012-05-02 Thread Brian G. Peterson
On Wed, 2012-05-02 at 00:00 -0400, Jim Green wrote:
 Greetings!
 Pls forgive me if this is an old topic. I have searched through list
 archives extensively but I am just not sure if I am using quantstrat
 correctly with intraday data.
...
 Currently I use something similar to attached test.R to do intraday
 work. in the code I liquidate everything before close so that I don't
 need to worry about splits and dividends. Is what I am doing the
 correct way of using quantstrat with intraday data?

That's certainly the easiest answer.

blotter contains some support for dividends, but it is only lightly
tested, since I personally don't need that functionality.  Additional
testing, direct feedback, and patches are always welcome.  Participation
by users is one of the ways these packages grow over time.  (and feel
free to take those conversations off-list)

 Also if in future I will hold overnight positions, How would I make
 sure dividends and splits are correctly adjusted for pnl and summary
 statistics? would underlying blotter be smart enough to handle all the
 housekeeping?

No Guarantees (of course that's true of everything in R).

My recollection is that the addDiv function will add cash to your
account to cover dividends.  

I don't believe that there is a function for splits.  You'd likely need
to write that, we'd love the contribution.  It shouldn't be hard, as all
that needs to happen is that you add a transaction for the split with a
price of zero, adding more shares and lowering your average cost to
compensate for the split.

As xts gains support for differing column classes this summer as part of
the funded GSoC project, it will get easier to add additional
information to transactions that will definitely include transaction
type.

Regards,

   - Brian

-- 
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock

___
R-SIG-Finance@r-project.org 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.


Re: [R-SIG-Finance] quantstrat with intraday data

2012-05-02 Thread G See
As an alternative to adjusting for dividends in quantstrat or blotter,
my qmao package (https://r-forge.r-project.org/R/?group_id=1113) has
two functions that adjust intraday data for dividends.

`adjustIntraday.yahoo` will download dividend data from yahoo and
calculate daily ratios.  Those ratios will then be applied to intraday
data.

`AddCumDiv` simply adds back all dividends to the price series.

With adjustIntraday.yahoo, the most recent observations will be the
same as the unadjusted data, but the older observations will be lower
than those that are unadjusted.

With AddCumDiv, the oldest observations will be the same for the
adjusted and unadjusted data, but the most recent observations will be
higher for AddCumDiv.

Although I believe these functions work like they're supposed to, they
have not been rigorously tested, so YMMV.  bug reports encouraged.

Since I just committed the AddCumDiv function a few minutes ago, it is
not yet in the R-Forge build (although it is in the repo if you know
how to svn checkout).  Since it's not in the build yet, I attached it.

Regards,
Garrett

On Wed, May 2, 2012 at 8:02 AM, Brian G. Peterson br...@braverock.com wrote:
 On Wed, 2012-05-02 at 00:00 -0400, Jim Green wrote:
 Greetings!
 Pls forgive me if this is an old topic. I have searched through list
 archives extensively but I am just not sure if I am using quantstrat
 correctly with intraday data.
 ...
 Currently I use something similar to attached test.R to do intraday
 work. in the code I liquidate everything before close so that I don't
 need to worry about splits and dividends. Is what I am doing the
 correct way of using quantstrat with intraday data?

 That's certainly the easiest answer.

 blotter contains some support for dividends, but it is only lightly
 tested, since I personally don't need that functionality.  Additional
 testing, direct feedback, and patches are always welcome.  Participation
 by users is one of the ways these packages grow over time.  (and feel
 free to take those conversations off-list)

 Also if in future I will hold overnight positions, How would I make
 sure dividends and splits are correctly adjusted for pnl and summary
 statistics? would underlying blotter be smart enough to handle all the
 housekeeping?

 No Guarantees (of course that's true of everything in R).

 My recollection is that the addDiv function will add cash to your
 account to cover dividends.

 I don't believe that there is a function for splits.  You'd likely need
 to write that, we'd love the contribution.  It shouldn't be hard, as all
 that needs to happen is that you add a transaction for the split with a
 price of zero, adding more shares and lowering your average cost to
 compensate for the split.

 As xts gains support for differing column classes this summer as part of
 the funded GSoC project, it will get easier to add additional
 information to transactions that will definitely include transaction
 type.

 Regards,

   - Brian

 --
 Brian G. Peterson
 http://braverock.com/brian/
 Ph: 773-459-4973
 IM: bgpbraverock

 ___
 R-SIG-Finance@r-project.org 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.


AddCumDiv.R
Description: Binary data
___
R-SIG-Finance@r-project.org 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.

Re: [R-SIG-Finance] quantstrat with intraday data

2012-05-02 Thread G See
On Wed, May 2, 2012 at 10:57 PM, Jim Green
student.northwest...@gmail.com wrote:
 Thanks for the comment! personally I am hesitant to adjust intraday
 prices for splits or dividends, and I prefer adjust positions to
 account for the corp actions. Actually even for simplest technical
 analysis on daily data, I am still not sure if using dividend/split
 adjusted data is the right way to do.

 Jim.

If a stock splits in half, don't you think you should adjust for that
before performing technical analysis?  You'd treat that big jump in
price the same as a real price jump even though if you had a position
in the stock, your PnL would be unaffected by the split?

___
R-SIG-Finance@r-project.org 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.


Re: [R-SIG-Finance] quantstrat with intraday data

2012-05-02 Thread Jim Green
On 3 May 2012 00:07, G See gsee...@gmail.com wrote:
 If a stock splits in half, don't you think you should adjust for that
 before performing technical analysis?  You'd treat that big jump in
 price the same as a real price jump even though if you had a position
 in the stock, your PnL would be unaffected by the split?

sorry I was unclear... that would generate wrong signals..  I think
the correct way to use split/dividend adjusted daily data for
technical analysis is:
1, for each day, generate signals using adjusted data till before that
day, in a walking forward fashion.
2, for pnl logistics, use trade based adjustments or position adjustments.

the above are not currently supported by quantstrat and underlying
blotter but is really a nice to have. is qmao addressing the them in
some way?

Jim.

___
R-SIG-Finance@r-project.org 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.


[R-SIG-Finance] quantstrat with intraday data

2012-05-01 Thread Jim Green
Greetings!
Pls forgive me if this is an old topic. I have searched through list
archives extensively but I am just not sure if I am using quantstrat
correctly with intraday data.

I've attached sample minute ohlc data. after loading it, an xts object
spy.test would be populated as shown below:

 nrow(spy.test)
[1] 1074
 head(spy.test)
spy.Open spy.High spy.Low spy.Close spy.Volume
2012-03-29 07:32:00   140.14   140.15  140.14140.15800
2012-03-29 07:33:00   140.15   140.15  140.14140.14   2700
2012-03-29 07:36:00   140.16   140.16  140.12140.12   5105
2012-03-29 07:40:00   140.17   140.17  140.17140.17200
2012-03-29 07:41:00   140.15   140.16  140.15140.16   1798
2012-03-29 07:42:00   140.16   140.16  140.16140.16   2052
 tail(spy.test)
spy.Open spy.High spy.Low spy.Close spy.Volume
2012-03-30 16:26:00   140.86   140.87  140.85140.87  10900
2012-03-30 16:27:00   140.86   140.86  140.79140.79  27770
2012-03-30 16:28:00   140.84   140.86  140.84140.86  20400
2012-03-30 16:29:00   140.85   140.86  140.84140.86  18500
2012-03-30 16:30:00   140.86   140.86  140.85140.85  11035
2012-03-30 16:31:00   140.85   140.86  140.85140.85   1100


Currently I use something similar to attached test.R to do intraday
work. in the code I liquidate everything before close so that I don't
need to worry about splits and dividends. Is what I am doing the
correct way of using quantstrat with intraday data?

Also if in future I will hold overnight positions, How would I make
sure dividends and splits are correctly adjusted for pnl and summary
statistics? would underlying blotter be smart enough to handle all the
housekeeping?

Thanks!

Jim.


spy.test.Rdata
Description: Binary data


test.R
Description: Binary data
___
R-SIG-Finance@r-project.org 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.