[R-SIG-Finance] Possible bug in blotter

Peter Carl peter at braverock.com
Tue Dec 21 16:40:06 CET 2010


Wolfgang,

Your example is sending in prices in a way that blotter doesn't expect. 
I've modified your example to construct the price series that blotter can
work with.  We'll have to figure out a way to check the price series and
warn the user when it's mangled, so I appreciate the use case.

I've modified your script to construct a time series of prices for the
instrument being traded, ABC.  blotter uses FinancialInstrument to
associate the prices with the instrument, so that you don't have to.  I'd
refer you to the documentation, but we're still writing it...

library(blotter)
currency('USD')
stock('ABC', currency='USD', multiplier=1)
initPortf('portA', symbols="ABC", initDate='2010-01-01');
initAcct('accA',portfolios='portA', initDate='2010-01-01', initEq=100);
#Buy on day 2
addTxn("portA", Symbol='ABC', TxnDate='2010-01-02', TxnPrice=100, TxnQty =
1, TxnFees=0, verbose=TRUE)
ABC <- xts(100, order.by=as.Date('2010-01-02'))
colnames(ABC) = "Close"
updatePortf('portA', Dates = '2010-01-02')
updateAcct('accA', Dates = '2010-01-02')
updateEndEq('accA', Dates = '2010-01-02')
#Sell on day 3
addTxn("portA", Symbol='ABC', TxnDate='2010-01-03', TxnPrice=100, TxnQty =
-1, TxnFees=0, verbose=TRUE)
ABC <- rbind(ABC, xts(100, order.by=as.Date('2010-01-03')))
updatePortf('portA', Dates = '2010-01-03')
updateAcct('accA', Dates = '2010-01-03')
updateEndEq('accA', Dates = '2010-01-03')
#Equity wrong?
getPortfolio('portA')
getAccount('accA')

That results in:
> getAccount('accA')
$portfolios
$portfolios$portA
           Long.Value Short.Value Net.Value Gross.Value Realized.PL
2010-01-01          0           0         0           0           0
2010-01-02        100           0       100         100           0
2010-01-03          0           0         0           0           0
           Unrealized.PL Gross.Trading.PL Txn.Fees Net.Trading.PL
2010-01-01             0                0        0              0
2010-01-02             0                0        0              0
2010-01-03             0                0        0              0


$summary
           Additions Withdrawals Realized.PL Unrealized.PL Int.Income
2010-01-01         0           0           0             0          0
2010-01-02         0           0           0             0          0
2010-01-03         0           0           0             0          0
           Gross.Trading.PL Txn.Fees Net.Trading.PL Advisory.Fees
2010-01-01                0        0              0             0
2010-01-02                0        0              0             0
2010-01-03                0        0              0             0
           Net.Performance End.Eq
2010-01-01               0    100
2010-01-02               0    100
2010-01-03               0    100

attr(,"currency")
[1] "USD"
attr(,"initEq")
[1] 100
attr(,"class")
[1] "portfolio_account" "account"

... which is, I think, what you're looking for.

pcc
-- 
Peter Carl
http://www.braverock.com/~peter

> Consider the following example. Initialise portfolio on day 1 with 100
> USD, buy
> stock ABC on day 2 at a price of 100, sell stock ABC on day 3 at a price
> of 100.
> Now the End.Eq in getAccount is showing 200 USD.
>
>
> library(blotter)
> currency('USD')
> stock('ABC', currency='USD', multiplier=1)
> initPortf('portA', symbols="ABC", initDate='2010-01-01');
> initAcct('accA',portfolios='portA', initDate='2010-01-01', initEq=100);
> #Buy on day 2
> addTxn("portA", Symbol='ABC', TxnDate='2010-01-02', TxnPrice=100, TxnQty =
> 1,
> TxnFees=0, verbose=TRUE)
> currentPrice <- xts(100, order.by=as.Date('2010-01-02'))
> updatePortf('portA', Dates = '2010-01-02', Prices=currentPrice)
> updateAcct('accA', Dates = '2010-01-02')
> updateEndEq('accA', Dates = '2010-01-02')
> #Sell on day 3
> addTxn("portA", Symbol='ABC', TxnDate='2010-01-03', TxnPrice=100, TxnQty =
> -1,
> TxnFees=0, verbose=TRUE)
> currentPrice <- xts(100, order.by=as.Date('2010-01-03'))
> updatePortf('portA', Dates = '2010-01-03', Prices=currentPrice)
> updateAcct('accA', Dates = '2010-01-03')
> updateEndEq('accA', Dates = '2010-01-03')
> #Equity wrong?
> getPortfolio('portA')
> getAccount('accA')
>
> Wolfgang Wu
>
>
>
>
> _______________________________________________
> R-SIG-Finance at 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.
>



More information about the R-SIG-Finance mailing list