2013-03-21 15 views
5

Come posso ottenere i dati storici di un INDICE in R da Interactive Brokers? Se fosse a termine, vorrei utilizzare questo comando (come suggerito qui IBrokers request Historical Futures Contract Data?):IBrokers Historical Index Data

library(twsInstrument) 
a <- reqHistoricalData(tws, getContract("ESJUN2013")) 

Ma il corrispondente comando con l'connid della S & P Index dà un errore:

> a <- reqHistoricalData(tws, getContract("11004968")) 
Connected with clientId 110. 
Contract details request complete. Disconnected. 
waiting for TWS reply on ES ....failed. 
Warning message: 
In errorHandler(con, verbose, OK = c(165, 300, 366, 2104, 2106, : 
    Error validating request:-'uc' : cause - HMDS Expired Contract Violation:contract can not expire. 

P.S. Qualcuno con abbastanza punti dovrebbe creare un tag per IBrokers

+1

Dove hai ottenuto che 'CONId' (" 11004968 ")? Se si desidera l'indice S & P, è necessario ottenere il [contratto SPX] (http://www1.interactivebrokers.ch/contract_info/v3.8/index.php?action=Details&site=GEN&conid=416904). Puoi farlo con 'getContract (" SPX ")', 'getContract (sintetico (" SPX "," USD "))', 'getContract (" 416904 ")' ecc. Se vuoi usare [twsInstrument] (https : //r-forge.r-project.org/R/? group_id = 1113), o usa 'twsIndex' da [IBrokers] (https://code.google.com/p/ibrokers/) come dimostrato da geektrader. – GSee

risposta

5

Non ho accesso ai dati di mercato per indicizzare i dati, ma penso che seguire dovrebbe funzionare.

reqHistoricalData(tws, twsIndex(symbol = "SPX", exch = "CBOE")) 
## waiting for TWS reply on SPX ....failed. 
## NULL 

## Warning message: 
## In errorHandler(con, verbose, OK = c(165, 300, 366, 2104, 2106, : 
## Historical Market Data Service error message:No market data permissions for CBOE IND 

seguito è risultato di reqContractDetails usando approccio simile come sopra, che dimostra che l'oggetto del contratto è stato creato correttamente twsIndex

reqContractDetails(tws, twsIndex(symbol = "SPX", exch = "CBOE")) 
## [[1]] 
## List of 18 
## $ version  : chr "8" 
## $ contract  :List of 16 
## ..$ conId   : chr "416904" 
## ..$ symbol   : chr "SPX" 
## ..$ sectype  : chr "IND" 
## ..$ exch   : chr "CBOE" 
## ..$ primary  : chr "" 
## ..$ expiry   : chr "" 
## ..$ strike   : chr "0" 
## ..$ currency  : chr "USD" 
## ..$ right   : chr "" 
## ..$ local   : chr "SPX" 
## ..$ multiplier  : chr "" 
## ..$ combo_legs_desc: chr "" 
## ..$ comboleg  : chr "" 
## ..$ include_expired: chr "" 
## ..$ secIdType  : chr "" 
## ..$ secId   : chr "" 
## ..- attr(*, "class")= chr "twsContract" 
## $ marketName : chr "SPX" 
## $ tradingClass : chr "SPX" 
## $ conId   : chr "416904" 
## $ minTick  : chr "0.01" 
## $ orderTypes : chr [1:22] "ACTIVETIM" "ADJUST" "ALERT" "ALLOC" ... 
## $ validExchanges: chr "CBOE" 
## $ priceMagnifier: chr "1" 
## $ underConId : chr "0" 
## $ longName  : chr "S&P 500 Stock Index" 
## $ contractMonth : chr "" 
## $ industry  : chr "Indices" 
## $ category  : chr "Broad Range Equity Index" 
## $ subcategory : chr "*" 
## $ timeZoneId : chr "CST" 
## $ tradingHours : chr "20130321:0830-1500;20130322:0830-1500" 
## $ liquidHours : chr "20130321:0830-1500;20130322:0830-1500" 
## 
0

Come fa una richiesta di informazioni del contratto per gli stock non statunitensi, ho provato le due chiamate di seguito e ottengo un errore nei dettagli del contratto, ma questi sono i simboli e lo scambio per i due titoli, posso estrarre informazioni per loro in TWS.

reqContractDetails (TWS, twsEquity (simbolo = "BMW", exch = "IBIS"))

reqContractDetails (TWS, twsEquity (simbolo = "BP", exch = "EBS"))

Ho anche provato con exch = 'SMART' ma fallisce per BMW e recupera la linea NYSE per BP. Questa chiamata è solo per le azioni statunitensi?

+0

L'ho capito, devi specificare la valuta per le scorte non statunitensi reqContractDetails (tws, twsEquity (symbol = "BMW", exch = "IBIS", valuta = 'EUR'))) – Arun