2014-12-02 8 views
1

계정의 총 순 청산 액수를 얻으려고합니다. 본질적으로 모든 포지션 포트폴리오의 총 금액에 현금을 더한 금액입니다. 그러나 동봉 한 코드는 내가 얻을 수있는만큼 가깝습니다. 내가 수동으로 아래의 데이터에서 구할 수 있습니다대화 형 중개인을위한 IBrokers API를 사용하는 당좌 계좌

library(IBrokers) 
tws <- twsConnect() 
test<-reqAccountUpdates(tws) 
test 

나는 다음과 같은 데이터를 얻을 :

AccountCode      XXXX    
    AccountOrGroup     XXXX  USD  
    AccountReady      true     
    AccountType      PARTNERSHIP   
    AccruedCash      0    USD  
    AccruedCash.S     0.00   USD  
    AccruedDividend     0.00   USD  
    AccruedDividend.S    0.00   USD  
    AvailableFunds     1478.69 USD  
    AvailableFunds.S     1478.69 USD  
    Billable       0.00   USD  
    Billable.S      0.00   USD  
    BuyingPower      9812.27 USD  
    CashBalance      1478  USD  
    CorporateBondValue    0    USD  
    Currency       USD   USD  
    Cushion       1      
    DayTradesRemaining    -1      
    DayTradesRemainingT.1   -1      
    DayTradesRemainingT.2   -1      
    DayTradesRemainingT.3   -1      
    DayTradesRemainingT.4   -1      
    EquityWithLoanValue    1478.69 USD  
    EquityWithLoanValue.S   1478.69 USD  
    ExcessLiquidity     1478.69 USD  
    ExcessLiquidity.S    1478.69 USD  
    ExchangeRate      1.00   USD  
    FullAvailableFunds    1478.69 USD  
    FullAvailableFunds.S    1478.69 USD  
    FullExcessLiquidity    1478.69 USD  
    FullExcessLiquidity.S   1478.69 USD  
    FullInitMarginReq    0.00   USD  
    FullInitMarginReq.S    0.00   USD  
    FullMaintMarginReq    0.00   USD  
    FullMaintMarginReq.S    0.00   USD  
    FundValue      0    USD  
    FutureOptionValue    0    USD  
    FuturesPNL      0    USD  
    FxCashBalance     0    USD  
    GrossPositionValue    0.00   USD  
    GrossPositionValue.S    0.00   USD  
    IndianStockHaircut    0.00   USD  
    IndianStockHaircut.S    0.00   USD  
    InitMarginReq     0.00   USD  
    InitMarginReq.S     0.00   USD  
    IssuerOptionValue    0    USD  
    Leverage.S      0.00     
    LookAheadAvailableFunds   1478.69 USD  
    LookAheadAvailableFunds.S  1478.69 USD  
    LookAheadExcessLiquidity   1478.69 USD  
    LookAheadExcessLiquidity.S  1478.69 USD  
    LookAheadInitMarginReq   0.00   USD  
    LookAheadInitMarginReq.S   0.00   USD  
    LookAheadMaintMarginReq   0.00   USD  
    LookAheadMaintMarginReq.S  0.00   USD  
    LookAheadNextChange    0      
    MaintMarginReq     0.00   USD  
    MaintMarginReq.S     0.00   USD  
    MoneyMarketFundValue    0    USD  
    MutualFundValue     0    USD  
    NetDividend      0    USD  
    NetLiquidation     1478.69 USD  
    NetLiquidation.S     1478.69 USD  
    NetLiquidationByCurrency   1479  USD  
    OptionMarketValue    0    USD  
    PASharesValue     0.00   USD  
    PASharesValue.S     0.00   USD  
    PostExpirationExcess    0.00   USD  
    PostExpirationExcess.S   0.00   USD  
    PostExpirationMargin    0.00   USD  
    PostExpirationMargin.S   0.00   USD  
    PreviousDayEquityWithLoanValue 1478.69 USD  
    PreviousDayEquityWithLoanValue.S 1478.69 USD  
    RealCurrency      USD   USD  
    RealizedPnL      0    USD  
    SegmentTitle.S     US Securities   
    StockMarketValue     0    USD  
    TBillValue      0    USD  
    TBondValue      0    USD  
    TotalCashBalance     1479  USD  
    TotalCashValue     1478.69 USD  
    TotalCashValue.S     1478.69 USD  
    TradingType.S     PMRGN     
    UnrealizedPnL     0    USD  
    WarrantValue      0    USD  

나는 또한 twsPortfolioValue 덤비는했지만, 그것을 작동시킬 수 없습니다.

이상적으로, X 레코드 수를 읽는 대신 필드를 지정하고 싶습니다. IE "행 58"과 반대되는 "NetLiquidation"을 지정하려고합니다.

의견이 있으십니까? 도와 주셔서 정말 감사합니다!

+0

대신'str (test)'를 게시하면 더 나은 대답을 얻을 수 있습니다. –

+0

감사합니다 BondedDust. 그것이 어떻게 도움이되는지 확신하지 못합니다. 설명 할 수 있니? –

+0

우리는 객체'test'가 실제로 무엇인지 알지 못합니다. 당신은'print()'- 표현만을 보여 줬다. –

답변

1

test은 목록입니다. 첫 번째 구성 요소는 처럼 보이게하는 자체 인쇄 방법이있는 eventAccountValue으로 분류 된 개체입니다. 그러나 unclass(test[[1]])으로 전화하면 실제로는 목록에 불과합니다.

그래서, 당신은 영업 이익의 값과 일치하도록 변경이

test[[1]][["NetLiquidation"]] 
# value* currency 
# "1478.69"  "USD" 

* 값처럼 test 개체의 첫 번째 구성 요소의 "NetLiquidation"구성 요소에 액세스 할 수 있습니다.

+0

이것은 훌륭합니다. 나는 구문의 유형을 본 적이 없으므로 이것은 분명 도움이됩니다. 고맙습니다. 이 데이터에서 숫자 값을 어떻게 추출 할 수 있는지 알고 있습니까? –

+0

이게 뭔가요? test [[1]] [[ "NetLiquidation"]] [[1]] as.numeric (test [[1]] [ ])'. 시험받지 않은. – GSee

+0

완벽한, Gsee 감사합니다! –