[R-SIG-Finance] Blotter - Setting up a futures_series
Wolfgang Wu
wobwu22 at yahoo.de
Thu May 6 12:23:46 CEST 2010
It seems like the error occurs when you run updatePortf() for a date where one of the symbols are not defined. So TE_N9 doesn't have a row for the date '2009-01-02' which is causing this error. I guess this will happen often as there might be holidays or non trading days which might be different for different symbols (maybe trading on different exchanges, etc..). Are there any work-arounds to this problem?
Also is it possible to add or remove symbols to a portfolio object later than initPortf?
Thanks
Wolfgang Wu
----- Ursprüngliche Mail ----
Von: Wolfgang Wu <wobwu22 at yahoo.de>
An: Brian G. Peterson <brian at braverock.com>; R SIG Finance <R-SIG-Finance at stat.math.ethz.ch>
Gesendet: Donnerstag, den 29. April 2010, 14:44:32 Uhr
Betreff: Re: [R-SIG-Finance] Blotter - Setting up a futures_series
Sorry for being a pain in the neck but I've got another problem
When running the folloing code I get the error when I call updatePortf(): Error in if (!all(i <= 0)) stop("only zeros may be mixed with negative subscripts") :
missing value where TRUE/FALSE needed
#Example
library(FinancialInstrument)
library(blotter)
currency("USD", multiplier=1);
future("TE", "USD", 1000)
future_series("TE", "M9", "2009-01-02", "2009-01-03")
future_series("TE", "N9", "2009-01-03", "2009-01-04")
TE_M9 <- xts(rbind(cbind(54.28, 55.92, 53.57, 55.73, 78959, 1), cbind(55.50, 55.70, 54.38, 55.63, 75464, 2)), order.by=as.Date(c("2009-01-02", "2009-01-03")))
colnames(TE_M9) <- c("Open","High","Low","Close","Volume", "OpenInterest");
TE_N9 <- xts(rbind(cbind(54.28, 55.92, 53.57, 55.73, 78959, 1), cbind(55.50, 55.70, 54.38, 55.63, 75464, 2)), order.by=as.Date(c("2009-01-03", "2009-01-04")))
colnames(TE_N9) <- c("Open","High","Low","Close","Volume", "OpenInterest");
initPortf(name='fPortfolio', symbols = c('TE_M9', 'TE_N9'), initPosQty = 0, initDate='2009-01-01')
initAcct(name='fAccount',portfolios='fPortfolio', initDate='2009-01-01', initEq=10000000);
addTxn('fPortfolio', Symbol='TE_M9', TxnDate="2009-01-02", TxnPrice=55, TxnQty=100, TxnFees=0, verbose=TRUE);
updatePortf(Portfolio='fPortfolio', Dates = "2009-01-02");
#-----------------------------------------------
Any idea what I am doing wrong or where the problem is?
Thanks!!
Wolfgang Wu
----- Ursprüngliche Mail ----
Von: Brian G. Peterson <brian at braverock.com>
An: Wolfgang Wu <wobwu22 at yahoo.de>; R SIG Finance <R-SIG-Finance at stat.math.ethz.ch>
Gesendet: Donnerstag, den 29. April 2010, 12:21:36 Uhr
Betreff: Re: AW: [R-SIG-Finance] Blotter - Setting up a futures_series
On 04/29/2010 02:15 AM, Wolfgang Wu wrote:
> Understood.
>
> But in order to mark the book at some point you will need historical data of the contracts. How is the link from the contract specifications, using the future() and future_series() functions to the actual
> historical data. What would be the equivalent to the example of a stock like this:
>
> #Defined the stock as financial instrument
> stock("GSPC",currency="USD",multiplier=1)
> #Get the historical data for variable with name "GSPC"
> getSymbols('^GSPC', src='yahoo', index.class=c("POSIXt","POSIXct"),from='1998-01-01')
>
> Assuming I have the time series for CLM9 and CLN9 in an xts format
>
FinancialInstrument uses an underscore to separate the root symbol
(primary_id) from the series symbol (suffix_id). In your example, this
means that your historical contract series data should be named
CL_M9
CL_N9
So that the blotter code can find them (blotter follows the quantmod
convention of naming market data for the instrument)
you can see this by doing
ls(pos=.instrument)
which will show you the environment where the instrument definition
objects are kept.
Regards,
- Brian
> CLM9
> Open High Low Close Volume OpenInterest
> 2009-03-23 54.28 55.92 53.57 55.73 78959 187205
> 2009-03-24 55.50 55.70 54.38 55.63 75464 190182
> 2009-03-25 55.35 55.58 53.50 54.19 119624 198422
> ...
> 2009-05-19 59.16 60.48 58.55 59.65 40957 1838
>
> and
>
> CLN9
> Open High Low Close Volume OpenInterest
> 2009-04-22 50.95 51.14 49.72 50.70 95249 178023
> 2009-04-23 50.38 51.38 50.09 51.07 90781 181605
> 2009-04-24 51.13 53.09 50.40 52.94 70061 187690
> ...
> 2009-06-22 69.89 69.89 66.25 66.93 32070 4299
>
> Regards,
>
>
> Wolfgang Wu
>
>
>
> ----- Ursprüngliche Mail ----
> Von: Brian G. Peterson<brian at braverock.com>
> An: Wolfgang Wu<wobwu22 at yahoo.de>
> CC: R SIG Finance<R-SIG-Finance at stat.math.ethz.ch>
> Gesendet: Donnerstag, den 29. April 2010, 0:28:48 Uhr
> Betreff: Re: [R-SIG-Finance] Blotter - Setting up a futures_series
>
> Wolfgang Wu wrote:
>
>> Hello,
>>
>> I am playing around with blotter and am trying to set up several futures contracts. So assume I've got data for the crude oil future CL. I want to set up futures for the June 09 and July 09 contract.
>> What I've done is the following:
>>
>> currency("USD", multiplier=1); future("CL", "USD", 1000, identifiers=c("CLM9", "CLN9"))
>> future_series("CL", "M9", "2009-03-23", "2009-05-19")
>> future_series("CL", "N9", "2009-04-22", "2009-06-22")
>>
>>
>> 1.) How do I link the future to the future_series? I assume this is by using the primary_id, correct?
>>
> correct
>
>
>> 2.) What do I specify in the identifiers in the futures function?
>>
> anything or nothing at all. identifiers are for other symbols, e.g. Bloomberg, Reuters, etc. In your example, I would probably not add identifiers to the main contract.
>
>
>> 3.) What is the multiplier in the future mean? Is it the value for one tick or for one point? So for oil one tick is 10 USD and one point move is 1000 USD.
>>
> 'point value' in your terminology. It is used to get from the price to the notional value in the listed currency. I'll probably add tick value to the model later this week.
>
>
>> Thanks!!!
>>
> You're welcome.
>
> Regards,
>
> - Brian
>
>
>> Wolfgang Wu
>>
>>
>>
>> _______________________________________________
>> R-SIG-Finance at stat.math.ethz.ch 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.
>>
>
> -- Brian G. Peterson
> http://braverock.com/brian/
> Ph: 773-459-4973
> IM: bgpbraverock
>
>
>
>
--
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock
_______________________________________________
R-SIG-Finance at stat.math.ethz.ch 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.
More information about the R-SIG-Finance
mailing list