Re: [R-SIG-Finance] Rbbg(Bloomberg) time zone problem and xts constructor
Thanks John. That was really helpful. On 5/21/2013 8:54 AM, John Laing wrote: Nikos, There is limited date/time functionality built into Rbbg, but the conversion you're seeking can be easily achieved using standard R tools. You're already converting the data to xts, which has a particularly convenient way of dealing with timezones. I would do something like this, ignoring the milliseconds you added (which I assume were just for formatting): require(xts) require(Rbbg) conn - blpConnect() local.times - as.POSIXct(c(2013-05-13 10:00:00, 2013-05-13 10:15:00), format=%Y-%m-%d %H:%M:%S) bbg.times - strftime(local.times, %Y-%m-%d %H:%M:%S.000, tz=UTC) bid - tick(conn, AAPL US Equity, BID_BEST, bbg.times[1], bbg.times[2]) x - xts(bid[, 3:4], strptime(bid$time, %Y-%m-%dT%H:%M:%OS, UTC)) tzone(x) - NULL Hope that helps, John On Tue, May 21, 2013 at 1:33 AM, Nikos Rachmanis nikos.rachma...@gmail.com mailto:nikos.rachma...@gmail.com wrote: Hi all, I have come across the following time zone problem and I would appreciate your input. I am trying to download tick data using the Rbloomberg and I have found out that the query should be done in UTC time zone. My current zone is EST so i have written the code below to transform it from EST to UTC and works fine however the output i get is indicated in UTC as listed below for my query (instead of 10:00:00.000). timetypevalue size 1 2013-05-13T14:00:00.000 ASK_BEST 454.87 1 2 2013-05-13T14:00:00.000 TRADE 454.58 100 3 2013-05-13T14:00:00.000 ASK_BEST 454.78 10 4 2013-05-13T14:00:00.000 ASK_BEST 454.7 1 5 2013-05-13T14:00:00.000 TRADE 454.58 100 6 2013-05-13T14:00:00.000 ASK_BEST 454.7 1 7 2013-05-13T14:00:01.000 ASK_BEST 454.69 1 My questions are the the following: 1) Is there a way I could write the timezone transformation and get the correct timing or would I have to change after I download? 2) I have tried to use the xts constructor with the following command but was not successful. Any idea how to separate the T in the time? new-xts(bid[,3:4],order.by http://order.by=strptime(x=as.character(bid$time),format=%Y-%m-%d %H:%M:%OS,tz=EST)) Thank you all, Nikos #Rbloomberg Code # Special options options(warn=-1) options(digits.secs = 3) options(java.parameters = -Xmx1000m) # Import libraries library(RODBC) library(Rbbg) #set time interval (transforms from 10:00:00.001 to 14:00:00.001) start_time-toString(format(as.POSIXct(2013-05-13 10:00:00.001, tz=EST5EDT), tz=UTC)) end_time-toString(format(as.POSIXct(2013-05-13 10:15:00.001, tz=EST5EDT), tz=UTC)) # Connect to Bloomberg API conn - blpConnect(log.level = finest) #Download command data - tick(conn, AAPL US Equity, c(TRADE,BID_BEST,ASK_BEST), start_date_time=start_time, end_date_time=end_time) [[alternative HTML version deleted]] ___ R-SIG-Finance@r-project.org mailto: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. [[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.
[R-SIG-Finance] Rbbg(Bloomberg) time zone problem and xts constructor
Hi all, I have come across the following time zone problem and I would appreciate your input. I am trying to download tick data using the Rbloomberg and I have found out that the query should be done in UTC time zone. My current zone is EST so i have written the code below to transform it from EST to UTC and works fine however the output i get is indicated in UTC as listed below for my query (instead of 10:00:00.000). timetypevalue size 1 2013-05-13T14:00:00.000 ASK_BEST454.87 1 2 2013-05-13T14:00:00.000 TRADE 454.58 100 3 2013-05-13T14:00:00.000 ASK_BEST454.78 10 4 2013-05-13T14:00:00.000 ASK_BEST454.7 1 5 2013-05-13T14:00:00.000 TRADE 454.58 100 6 2013-05-13T14:00:00.000 ASK_BEST454.7 1 7 2013-05-13T14:00:01.000 ASK_BEST454.69 1 My questions are the the following: 1) Is there a way I could write the timezone transformation and get the correct timing or would I have to change after I download? 2) I have tried to use the xts constructor with the following command but was not successful. Any idea how to separate the T in the time? new-xts(bid[,3:4],order.by=strptime(x=as.character(bid$time),format=%Y-%m-%d %H:%M:%OS,tz=EST)) Thank you all, Nikos #Rbloomberg Code # Special options options(warn=-1) options(digits.secs = 3) options(java.parameters = -Xmx1000m) # Import libraries library(RODBC) library(Rbbg) #set time interval (transforms from 10:00:00.001 to 14:00:00.001) start_time-toString(format(as.POSIXct(2013-05-13 10:00:00.001, tz=EST5EDT), tz=UTC)) end_time-toString(format(as.POSIXct(2013-05-13 10:15:00.001, tz=EST5EDT), tz=UTC)) # Connect to Bloomberg API conn - blpConnect(log.level = finest) #Download command data - tick(conn, AAPL US Equity, c(TRADE,BID_BEST,ASK_BEST), start_date_time=start_time, end_date_time=end_time) [[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.
[R-SIG-Finance] Cumulative return
Hi all, I would appreciate if someone could help me out with the following problem. I am trying to calculate the cumulative returns of simple returns (P(i)-P(i-1))/P(i-1). I am using the following code: #calculate simple returns asset_ret$pnl-Return.calculate(asset_prices, method=simple) #zero first observation in daily PL asset_ret$pnl[1]-0 #create the cum PL asset_ret$cum.pnl-1 #calculate cum PL asset_ret$cum.pnl-(1+asset_ret$pnl)*lag(asset_ret$cum.pnl,k=1) #also tried to following # asset_ret$cum.pnl[2:len]-(1+asset_ret$pnl[2:len])*(asset_ret$cum.pnl[1:len-1]) Both ways produce the same result. pnl cum.pnl 12/31/1999 0 1 1/7/2000-0.0264143440.973585656 1/14/2000 0.042927439 1.042927439 1/21/2000 -0.0052073090.994792691 1/28/2000 0.001524739 1.001524739 2/4/2000-0.0704451960.929554804 2/11/2000 0.011650011 1.011650011 2/18/2000 -0.0511970150.948802985 2/25/2000 0.003199086 1.003199086 3/3/2000-0.0530005330.946999467 while the correct is pnl cum.pnl 12/31/1999 1 1/7/2000-0.0264143440.973585656 1/14/2000 0.042927439 1.015379194 1/21/2000 -0.0052073091.010091802 1/28/2000 0.001524739 1.011631928 2/4/2000-0.0704451960.940367318 2/11/2000 0.011650011 0.951322608 2/18/2000 -0.0511970150.902617731 2/25/2000 0.003199086 0.905505283 3/3/2000-0.0530005330.857513021 It seems that R uses the original values from the vector filled with ones instead the new calculated values. I apologize if the topic was discussed previously but was not able to find the answer. Thank you, Nikos [[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] R-SIG-Finance Digest, Vol 107, Issue 11
Assuming t=1, you forgot to discount updating the function fun - function(x, K=100) { (gbm(x) - 100) * dnorm(x) * exp(-0.05) } should give you the result you want. Nikos On 4/13/2013 6:00 AM, r-sig-finance-requ...@r-project.org wrote: Today's Topics: 1. euro call by integration (Dominykas Grigonis) -- Message: 1 Date: Sat, 13 Apr 2013 07:42:23 +0100 From: Dominykas Grigonis dominykasgrigo...@gmail.com To: r-sig-finance r-sig-finance@r-project.org Subject: [R-SIG-Finance] euro call by integration Message-ID: 31ae529de9c041beb5deec9b6837b...@gmail.com Content-Type: text/plain Valuing european call option by taking expectation and integrating: gmb - function(x,s0=100,r=0.05,vol=0.1){ s0*exp( (r - vol^2/2) + vol * x)} fun - function(x, K=100){ (gbm(x) - 100) * dnorm(x)} min = -(log(1) + (0.05-0.1^2/2)) / 0.1 integrate(fun,min,Inf) could someone tell me what am I doing wrong? I do not even know if this is R related question or not... returns 7.153855, while actual risk neutral price is 6.804958 Thank you in advance. Kind regards,-- Dominykas Grigonis [[alternative HTML version deleted]] -- ___ R-SIG-Finance mailing list R-SIG-Finance@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-finance End of R-SIG-Finance Digest, Vol 107, Issue 11 ** ___ 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] merge.xts problem
Hi all, Just wondering if someone has come across this problem with the merge.xts function after updating from 0.8-6 to 0.9-3 version. I am trying to merge 2 xts objects one with daily observations and another one with weekly. With the older packet and the following command: tradedata-merge.xts(timeseries.daily,timeseries.daily,join=left) the merge is done fine. With the new one does not work and although puts together the 2 datasets shows all the incoming observations as NA. Daily dataset Dates IMM0ECOL Index IMM0ECOS Index IMM0ENCL Index 12/26/2000 431638769 26834 1/2/2001549529995 15885 1/9/2001578641915 21845 1/16/2001 686641480 19696 Weekly dataset Index SP1.OPENSP1.HIGH 1/2/1990356.35 362.85 1/3/1990363.25 364.8 1/4/1990361.4 362.6 1/5/1990359.2 359.6 1/8/1990354.1 358.4 1/9/1990357.8 358.1 1/10/1990 351.9 353.2 1/11/1990 352.4 353.5 Has the command changed? Thanks, Nikos [[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.
[R-SIG-Finance] Conversion of xts to ts object
Hi all, I am trying to convert a xts to ts object in order to use with decompose() and forecast() functions. I am currently using the following command which works: tsdata-ts(tradedata$dif,frequency=252) where tradedata is the xts object. I would feel more comfortable if i did not have to set the trading days in advance cause I am dealing with many years of daily data. I have search the internet but most people suggest similar ways. Has anyone come across this problem? Thank you, Nikos ___ 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] Performance Analytics table.AnnualizedReturns
Hi all, I am using the t(table.AnnualizedReturns(tradedata$daily.pnl.norm[2003/2010],Rf=0,geometric=TRUE)) at the Performance Analytics package to calculate the annualized returns, stdev and sharpe for the strategies output. The function returns a table like the one below for all the years included at the dataseries: Annualized Return Annualized Std Dev Annualized Sharpe (Rf=0%) daily.pnl.norm0.1018 0.0617 1.649 I was wondering if there is a way to calculate the same metrics on a yearly basis. As an example: Annualized Return Annualized Std Dev Annualized Sharpe (Rf=0%) daily.pnl.norm[2003]0.1018 0.0617 1.649 daily.pnl.norm[2004]0.0200 0.0200 1.000 daily.pnl.norm[2005]0.0100 0.0200 0.500 . . . . Is there any table that i can use to calculate the above table? Thank you, Nikos [[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] Performance Analytics Calendar Returns
Thank you Garrett! Worked very nice! On Wed, Sep 5, 2012 at 2:16 PM, G See gsee...@gmail.com wrote: On Wed, Sep 5, 2012 at 12:21 AM, Nikos Rachmanis nikos.rachma...@gmail.com wrote: However, I am trying to transform the daily returns of my PL (which also include gaps) to monthly and unfortunately the to.monthly does not work very well. i am currently trying table.TrailingPeriods and rollapply. Any other ideas or functions? ?apply.monthly apply.monthly(PnL, sum) -Garrett [[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] PL Calculation
Thank you very much Joshua! na.locf worked amazingly good:) regarding quantstrat i was able to download the package but i am having difficulty finding the reference manual. Any idea where i could find it? Thank you again for the quick responce, Nikos On Thu, Aug 16, 2012 at 8:49 PM, Joshua Ulrich josh.m.ulr...@gmail.comwrote: Hi Nikos, See ?na.locf. quantstrat et al are under heavy development but they're also used by professionals every day, so there's no reason you can't use them. Best, -- Joshua Ulrich | about.me/joshuaulrich FOSS Trading | www.fosstrading.com On Thu, Aug 16, 2012 at 7:44 PM, Nikos Rachmanis nikos.rachma...@gmail.com wrote: Hi all, I would appreciate if someone could give me some feedback on the following problem. I am trying to estimate the PL of a strategy based on the trade entries. as you will see in the data below the entries are indicated by 0,1,-1 and they are suppose to be active until the next position follows. the object is xts and my difficulty is updating the vector between the trades. as an example between 05-15 and 05-29 the series should have been -1. i am using an excel like macro command to achieve this perfdata$trade[2:n]-ifelse(is.na (perfdata$trade[2:n]),perfdata$trade[1:n-1],perfdata$trade[2:n]) however i have noticed that the command will update only one element after a !=NA which i guess is using the data on the memory and not the updated one. is there are any other way to write the command without using a for loop? also, i have read about the blotter package and quant strat but it seems that they are still under heavy development. Are there any other libraries to run trading strategies? Thank you in advance, Nikos CL trade 1990-04-27 18.54NA 1990-04-30 18.54NA 1990-05-01 18.88NA 1990-05-02 18.68NA 1990-05-03 17.99NA 1990-05-04 17.98NA 1990-05-07 18.27NA 1990-05-08 18.28NA 1990-05-09 18.99NA 1990-05-10 19.02NA 1990-05-11 18.95NA 1990-05-14 19.71NA 1990-05-15 19.59-1 1990-05-16 19.03NA 1990-05-17 18.87NA 1990-05-18 18.76NA 1990-05-21 18.26NA 1990-05-22 17.68NA 1990-05-23 18.14NA 1990-05-24 17.83NA 1990-05-25 17.80NA 1990-05-29 17.98-1 1990-05-30 18.08NA 1990-05-31 17.40NA 1990-06-01 17.50NA 1990-06-04 17.14NA 1990-06-05 16.68NA 1990-06-06 16.92NA 1990-06-07 16.67 0 1990-06-08 16.78NA 1990-06-11 16.82NA 1990-06-12 17.51 1 1990-06-13 17.58NA 1990-06-14 17.13NA [[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. [[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.