[R-SIG-Finance] quantmod, determine if ADR

2012-05-10 Thread Ben quant
Hello,

Using R (quantmod), does anyone know how to determine if a ticker trades as
an ADR? Also, is there a way to determine what currency the financials will
be quoted in when using  getFinancials() and viewFinancials()?

For example, TLK is an ADR and the tickers financials are quoted in non-USD
units.

Thanks,

ben

[[alternative HTML version deleted]]

___
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] Guy's example osFixedDollar not working in latest quantstrat

2012-05-10 Thread Jim Green
current svn version of quantstrat already fixed the order sizing
problem. Many thanks to Brian and the patch author!

Jim.

On 12 April 2012 21:15, Jim Green  wrote:
> Good Evening!
>
> I was studying the Guy Yollin's presentation on quantstrat
> http://www.r-programming.org/files/quantstrat-II.pdf  and can't
> reproduce the result in latest quantstrat. Actually osFixedDollar was
> not even called per my basic logging. I've attached the pdf chart and
> the runnable code and the results on my machine. Hope someone could
> help..
>
> Thanks!
> Jim.
>
>
> ### code ###
>
> #!/usr/bin/env Rscript
> library(quantstrat)
> library(logging)
> basicConfig()
>
> # define stock list
> stock.str=c("SPY")
> # inz currency and stocks
> dummy <- currency('USD')
> for(symbol in stock.str){
>         stock(symbol, currency="USD",multiplier=1)
> }
> # download stocks
> start.date <- as.Date("2001-01-01")
> initDate <- start.date-1
> end.date <-as.Date("2011-08-06")
> getSymbols(stock.str,from=start.date,to=end.date,adjust=T)
>
> # inz portfolio, account, orders, strategy
> strat.name <- "MAX"
> initEq=100
> trade.percent <- 0.01
> tradeSize <- initEq * trade.percent
> dummy <- initPortf(name=strat.name,symbols=stock.str, initDate=initDate)
> dummy <- initAcct(name=strat.name,portfolios=strat.name,
> initDate=initDate, initEq=initEq)
> initOrders(portfolio=strat.name,initDate=initDate)
> strat <- strategy(strat.name)
>
> # indicators:
> strat <- add.indicator(strategy = strat, name = "SMA", arguments =
> list(x=quote(Cl(mktdata)), n=50),label= "ma50" )
> strat <- add.indicator(strategy = strat, name = "SMA", arguments =
> list(x=quote(Cl(mktdata)), n=200),label= "ma200")
> # signals:
> strat <- add.signal(strategy = strat,name="sigCrossover", arguments =
> list(columns=c("ma50","ma200"), relationship="gte"),
> label="ma50.gt.ma200")
> strat <- add.signal(strategy = strat,name="sigCrossover", arguments =
> list(column=c("ma50","ma200"),relationship="lt"),
> label="ma50.lt.ma200")
>
> osFixedDollar <- function(timestamp,orderqty, portfolio, symbol, ruletype, 
> ...)
> {
>   logwarn("started osFixedDollar")
>   ClosePrice <- as.numeric(Cl(mktdata[timestamp,]))
>   orderqty <- sign(orderqty)*round(tradeSize/ClosePrice)
>   return(orderqty)
> }
>
> # rules:
> strat <- add.rule(
>   strategy = strat,
>   name='ruleSignal',
>   arguments = list(sigcol="ma50.gt.ma200",sigval=TRUE, orderqty=100,
> ordertype='market', orderside='long', osFUN='osFixedDollar'),
>   type='enter'
> )
>
> strat <- add.rule(
>   strategy = strat,
>   name='ruleSignal',
>   arguments = list(sigcol="ma50.lt.ma200",sigval=TRUE,
> orderqty='all', ordertype='market', orderside='long'),
>   type='exit'
> )
>
> out <- try(applyStrategy(strategy=strat , portfolios=strat.name, 
> verbose=TRUE))
> getTxns(Portfolio=strat.name, Symbol=stock.str)
> getPortfolio(strat.name)$summary
> dummy <- updatePortf(Portfolio=strat.name,
>   Dates=paste('::',as.Date(Sys.time()),sep='')
> )
>
> pdf("quantstrat2_position_sizing_fixed.pdf")
> chart.Posn(Portfolio=strat.name,Symbol=stock.str)
> add_SMA(n=50 , on=1,col='blue',lwd=2)
> add_SMA(n=200, on=1,col='red',lwd=2)
>
> ### output ###
> [1] "SPY"
> [1] "2002-04-24 SPY 100 @ 91.9933301492183"
> [1] "2002-04-29 SPY -100 @ 89.8492574695683"
> [1] "2002-04-30 SPY 100 @ 90.6900702851173"
> [1] "2002-05-14 SPY -100 @ 92.674388529813"
> [1] "2003-05-12 SPY 100 @ 81.1354076349475"
> [1] "2004-08-25 SPY -100 @ 96.8566013672453"
> [1] "2004-10-27 SPY 100 @ 98.8180303441752"
> [1] "2006-07-25 SPY -100 @ 114.662711057191"
> [1] "2006-08-29 SPY 100 @ 118.211406993905"
> [1] "2007-12-28 SPY -100 @ 137.165700378348"
> [1] "2009-06-18 SPY 100 @ 88.5716570825431"
> [1] "2010-07-06 SPY -100 @ 100.84667390332"
> [1] "2010-10-15 SPY 100 @ 116.002709490181"
>                   Txn.Qty Txn.Price Txn.Fees  Txn.Value Txn.Avg.Cost
> 2000-12-30 19:00:00       0   0.0        0      0.000      0.0
> 2002-04-24 00:00:00     100  91.99333        0   9199.333     91.99333
> 2002-04-29 00:00:00    -100  89.84926        0  -8984.926     89.84926
> 2002-04-30 00:00:00     100  90.69007        0   9069.007     90.69007
> 2002-05-14 00:00:00    -100  92.67439        0  -9267.439     92.67439
> 2003-05-12 00:00:00     100  81.13541        0   8113.541     81.13541
> 2004-08-25 00:00:00    -100  96.85660        0  -9685.660     96.85660
> 2004-10-27 00:00:00     100  98.81803        0   9881.803     98.81803
> 2006-07-25 00:00:00    -100 114.66271        0 -11466.271    114.66271
> 2006-08-29 00:00:00     100 118.21141        0  11821.141    118.21141
> 2007-12-28 00:00:00    -100 137.16570        0 -13716.570    137.16570
> 2009-06-18 00:00:00     100  88.57166        0   8857.166     88.57166
> 2010-07-06 00:00:00    -100 100.84667        0 -10084.667    100.84667
> 2010-10-15 00:00:00     100 116.00271        0  11600.271    116.00271
>                   Net.Txn.Realized.PL
> 2000-12-30 19:00:00              0.
> 2002-04-24 00:00:00              0.000

Re: [R-SIG-Finance] Generating a front month only Time Series for Futures Prices

2012-05-10 Thread G See
repost for the archives:

I agree that when possible, you should avoid building continuous
series.  Nonetheless, that's what the OP asked for.

Sometimes, there is value in analyzing a long history of data (for
example when analyzing risk) and in such cases, a constant maturity
future makes sense.

Also, if your time-frame is short and you're careful about how you
adjust and how you use the adjusted data, I think it can be useful.

The OP wanted to combine and not adjust, which, IMO is more dangerous
than combining and adjusting.  If you're going to combine the price
series of 2 different expiration months, then you have to adjust for
the roll.  Otherwise, you may see a trend or mean-reversion where
there isn't one, or worse, the opposite is actually occurring.

Your point about this being a difficult thing to generalize (e.g.
different grades for different expirations, or first notice day being
different than expiration, etc.) is valid.

Regards,
Garrett

___
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] Generating a front month only Time Series for Futures Prices

2012-05-10 Thread BBands
I feel that reiterating my prior warning is worthwhile. The proper way
to do this is to analyze the actual contracts and roll just as you
would have to if you were actually trading; exit the current contact
when the crowd moves enter the new actively-traded front month and
account for each separately. I coded this in Python and it works well,
but I have yet to tackle futures in R. Some problems: In some
commodities not all months actually trade actively. Backwardation and
contango can impact the rolls dramatically. While analyzing months in
delivery may seem OK, traders avoid them. None of the shortcuts that I
know of comes even close to approximating the realities of the
marketplace. Most analysts (including most of the tblox crowd) simply
ignore these problems, analyze continuous contracts and are burned
when they enter the marketable.

Current example problem: Different crude contracts track different
delivery venues and are priced differently. Think WTI versus Brent,
spread truculently running tin the $10 range, which not too long ago
was thought 'impossible".

This is a very deep well.

Best,

John

___
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] Generating a front month only Time Series for Futures Prices

2012-05-10 Thread G See
John,

I think you probably meant to send this to the list instead of just
me; apologies if not.

I agree that when possible, you should avoid building continuous
series.  Nonetheless, that's what the OP asked for.

Sometimes, there is value in analyzing a long history of data (for
example when analyzing risk) and in such cases, a constant maturity
future makes sense.

Also, if your time-frame is short and you're careful about how you
adjust and how you use the adjusted data, I think it can be useful.

The OP wanted to combine and not adjust, which, IMO is more dangerous
than combining and adjusting.  If you're going to combine the price
series of 2 different expiration months, then you have to adjust for
the roll.  Otherwise, you may see a trend or mean-reversion where
there isn't one, or worse, the opposite is actually occurring.

Your point about this being a difficult thing to generalize (e.g.
different grades for different expirations, or first notice day being
different than expiration, etc.) is valid.

Regards,
Garrett

On Thu, May 10, 2012 at 12:48 PM, BBands  wrote:
> I feel that reiterating my prior warning is worthwhile. The proper way
> to do this is to analyze the actual contracts and roll just as you
> would have to if you were actually trading; exit the current contact
> when the crowd moves enter the new actively-traded front month and
> account for each separately. I coded this in Python and it works well,
> but I have yet to tackle futures in R. Some problems: In some
> commodities not all months actually trade actively. Backwardation and
> contango can impact the rolls dramatically. While analyzing months in
> delivery may seem OK, traders avoid them. None of the shortcuts that I
> know of comes even close to approximating the realities of the
> marketplace. Most analysts (including most of the tblox crowd) simply
> ignore these problems, analyze continuous contracts and are burned
> when they enter the marketable.
>
> Current example problem: Different crude contracts track different
> delivery venues and are priced differently. Think WTI versus Brent,
> spread truculently running tin the $10 range, which not too long ago
> was thought 'impossible".
>
> This is a very deep well.
>
> Best,
>
> John

___
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] R-SIG-Finance Digest, Vol 96, Issue 10

2012-05-10 Thread Dale W.R. Rosenthal
There are changed engendered by index occlusion, but it can be made to occur. 
Read up on the Russell index rebalance. I can force a stock into the Russell 
2000 and then those liquidity and information production benefits help keep 
that stock in the index.

If tugger size effect is a self-fulfilling prophesy, then we have an 
Ornstein-Uhlenbeck process embedded on every stock's returns -- which is 
unlikely.

To bring this back to R, we should think that a demeaned process which is a 
self-fulfilling prophesy should exhibit decreasing variance over time. So a 
simple test:

sfp <- lm(log.returns ~ the + posited + model)
resids <- residuals(sfp)
var.vs.time <- lm(resids^2 ~ time)

Then check the slope coefficient for significance.

Dale W.R. Rosenthal
Assistant Professor, Department of Finance
University of Illinois at Chicago
http://tigger.uic.edu/~daler
http://ssrn.com/author=906862

- Reply message -
From: r-sig-finance-requ...@r-project.org
To: 
Subject: R-SIG-Finance Digest, Vol 96, Issue 10
Date: Thu, May 10, 2012 05:00
Message: 14
Date: Wed, 9 May 2012 15:44:08 -0400
From: Richard Herron 
Subject: Re: [R-SIG-Finance] self-fulfilling prophecies in financial
study
Message-ID:


I don't want to argue semantics, but for your examples there is a
real, underlying change.

Inclusion in an index improves liquidity and information production
for the real reasons you discuss (e.g., increased trading by index
funds or an increase in capitalization that added the firm to the
index).

For the size effect the only thing that changed was that some
researchers said "I think that small stocks earn an abnormal return,"
and the effect diminished. I consider this a "prophecy" because there
is no real underlying change, just an idea planted by academic
research.

Richard Herron


On Wed, May 9, 2012 at 10:49 AM, Nitish Ranjan  wrote:
> Disappearance of size effect will not be an example of self fulfilling
> prophesy (it disappeared rather than become stronger).
>
> In the stock market, possible examples are:
>
> 1. Index inclusion effect in returns
> 2. The tendency of traders to put in trades early in the day or later in
> the day but not in the middle of the day.
> 3. Most dispersion in returns during the earnings month.
>
> The second part of the email asked about R code/test which will test these
> effects for self fulfilling prophecy. The null for such test is "Are there
> any economic reasons why we would see self fulfilling prophecies to work."
> A general test is hard (probably impossible, see the following discussion)
> since different economic(or psychological) factors shape each of these
> examples. But we can formulate hypotheses for each one of these examples
> and write tests.
>
> Let me take the example of index inclusion effect. It is well known that
> after included in an index such as S&P 500, a stock performs well. Why? For
> one, there are many funds which are pegged to S&P 500 and many more which
> simply follow the index. Both these kind of funds will have demand for the
> newly inducted stock. Both these kind of funds will begin to buy the stock
> and
> move the prices up for the newly inducted stock. Since neither of these
> demands have any informational origins, we would expect the permanent
> impact to be small (close to zero) and a large temporary impact. See the
> survey paper http://www4.ncsu.edu/~rswarr/fm2006.pdf for further discussion.
>
> Another channel via which the effect might play out is through new
> information production. It is very possible that index inclusion actually
> brings a stock to the forefront of investors and produces new research for
> the stock which in turn should make the stock less volatile. A
> Campbell-Schiller type decomposition might help with matters here. You
> could also examine the actual production of information (number of news
> articles, analyst following, analyst dispersion etc). This line of
> reasoning suggests that we would see this effect most for stocks which come
> from relative anonymity to being famous. We would observe less of this
> effect for stocks which were famous before inclusion in an index (such as
> netflix for SP500 and any stock in Dow 30). But including such
> informational channels involve careful examination of multitude of data
> sources and ruling out the alternates one by one. It also involves
> understanding the various forces at play (or institutional knowledge).
>
> Regards
>
> Nitish
>
> p.s.: I think it is borderline not appropriate discussion for this list,
> but since it asked for an R code it deserves some consideration.
>
>
> On Wed, May 9, 2012 at 9:04 AM, Richard Herron
> wrote:
>
>> Is this an R question?
>>
>> Are you taking about anomalies that disappear after we discover them? If we
>> discover an anomaly and it disappears, then we have to wonder if we priced
>> it right before or after. See the size effect.
>>
>> http://schwert.ssb.rochester.edu/hbfech15.pdf
>>
>> Richard Herron
>>
>