[R-SIG-Finance] Defining many future_series() at once in FinancialInstruments

varcovar varcovar at live.com
Tue Jan 17 11:55:31 CET 2012


Hi guys, 

I have 100 Futures symbols that are defined using the future() function from
the FinancialInstrument package. I want to define their respective contracts
using the future_series() function. I have about 15000 contracts to define.
The problem here is that the time needed to define a contract with
future_series() increases exponentially with the number of contracts defined
(it is very fast for the first contract, and then goes slower and slower).  

Here is a reproducible example. I build a vector of 104 market symbols and
then a vector of 19136 contracts (184 contracts for each market symbol).
Then I calculate the time needed to define the first 200 contracts, and then
600 contracts. While it takes about 2.76 seconds on my desktop to define the
first 200 contracts, it takes more than 23 seconds for the next 600
contracts. At this increasing rate, it would take an eternity to define all
those 19136 contracts. 

library(quantstrat)
## create a vector of 104 symbols
symbols <- NULL
for (i in 1:4)
    symbols <- c(symbols, paste(LETTERS[(2 * i):26], LETTERS[1:26], sep =
""))
currency("USD")
## create a vector containing all contracts for the 104 symbols (thus 19136
contracts)
all_contracts <- NULL
for (i in 1:length(symbols)) {
    ## define futures
    future(primary_id = symbols[i], currency = "USD", multiplier = 100, 
        tick_size = 0.1, month_cycle = "F,G,H,J,M,Q,V,Z")
    ## create contracts series
    contracts <- build_series_symbols(
        roots = data.frame(
            primary_id  = getInstrument(symbols[i])$primary_id, 
            month_cycle = getInstrument(symbols[i])$month_cycle), 
        yearlist = 1990:2012)
    ## format contracts symbols
    contracts <- format_id(contracts, format = "CYY")
    ## append new contracts to all contracts
    all_contracts <- c(all_contracts, contracts)
}
## calculate time needed to define contracts 
system.time(future_series(all_contracts[1:200]))
system.time(future_series(all_contracts[201:800]))

Once all the future_series are defined, I expect to save them using the
saveInstruments() function for later use. Any suggestion for making this
process faster? I really appreciate your help! Thank you. 

Markus Douglas

--
View this message in context: http://r.789695.n4.nabble.com/Defining-many-future-series-at-once-in-FinancialInstruments-tp4302922p4302922.html
Sent from the Rmetrics mailing list archive at Nabble.com.



More information about the R-SIG-Finance mailing list