[R-SIG-Finance] addTxns addfees

G See gsee000 at gmail.com
Thu Jul 5 02:01:05 CEST 2012


Yeah, yeah, ok. Patched in Rev. 1100.

Your TxnData object must have  a column named "TxnFees" (instead  of
"TxnFee" because both addTxn and .calcTxnValue use "TxnFees").

If you need help checking out and building the current source code,
see here (http://stackoverflow.com/questions/11105131/cannot-install-r-forge-package-using-install-packages)

After updated, this should do what you want:

    library(blotter)
    currency('USD')
    stock("SPY", currency="USD", mulitplier=1)
    getSymbols('SPY', from='2012-03-01', to='2012-07-04')
    portf.name <- "dummy.Portfolio"
    initPortf(portf.name, 'SPY', initDate='2012-02-29')
    initAcct(portf.name, portf.name, initDate='2012-02-29', initEq=1e6)
    qty <- rep(c(1,-1), nrow(SPY)/2)
    price <- SPY[,4]
    txnfees <- rep(-5, nrow(SPY))
    txndata <- cbind(qty, price, txnfees)
    colnames(txndata) <- c("Quantity","Price","TxnFees")
    blotter:::addTxns(Portfolio=portf.name, Symbol='SPY', TxnData=txndata )
    txns <- getTxns(Portfolio=portf.name, Symbol='SPY')
    head(txns)

Best,
Garrett

On Wed, Jul 4, 2012 at 6:42 PM, Hideyoshi Maeda
<hideyoshi.maeda at gmail.com> wrote:
> Ah ok, I didn't look at the repository...is that expected to go in any time soon given its simplicity in adjustment?
>
> On 5 Jul 2012, at 09:36, G See wrote:
>
>> If you look at the code in the repository,
>>
>> https://r-forge.r-project.org/scm/viewvc.php/pkg/blotter/R/addTxn.R?view=markup&revision=1081&root=blotter
>>
>> you can see that there are comments saying that this isn't yet supported.
>>
>>        TxnFee <- 0 #TODO FIXME support transaction fees in addTxns
>>        #TxnFee <- ifelse( is.function(TxnFees), TxnFees(TxnQty,
>> TxnPrice), TxnFees)
>>
>> Sorry,
>> Garrett
>>
>> On Wed, Jul 4, 2012 at 6:29 PM, G See <gsee000 at gmail.com> wrote:
>>> My apologies.  I see what you are talking about, and I see where that
>>> is hardcoded in.  So, you would need to replace
>>>
>>> TxnFee <- 0
>>>
>>> with
>>>
>>> TxnFee <- as.numeric(TxnData[row, "txnfees"])
>>>
>>>
>>> On Wed, Jul 4, 2012 at 6:24 PM, Hideyoshi Maeda
>>> <hideyoshi.maeda at gmail.com> wrote:
>>>> Thanks for your response.
>>>>
>>>> I am aware that addTxn is not vectorized...
>>>>
>>>> but what I am using below is addTxns...(note the 's' after Txn)
>>>>
>>>> This allows transaction data through the TxnData argument
>>>>
>>>> It is, in effect, a vectorised version of addTxn...even the blotter demo from
>>>>
>>>> demo(amzn_test)
>>>>
>>>> uses this....
>>>>
>>>> However unlike the demo...i wanted to include Transaction fees, and wanted to know if this was possible...as the function for addTxns automatically assigns this to zero...
>>>>
>>>>
>>>>
>>>> On 5 Jul 2012, at 09:15, G See wrote:
>>>>
>>>>> Hi Hideyoshi,
>>>>>
>>>>> addTxn is not vectorized, and it does not have a txnData argument.  To
>>>>> see how the function is intended to be used, please read
>>>>>
>>>>> ?addTxn
>>>>>
>>>>> Then look at the demos that are included with blotter as well as the
>>>>> examples in ?blotter.
>>>>>
>>>>> HTH,
>>>>> Garrett
>>>>>
>>>>> On Wed, Jul 4, 2012 at 5:46 PM, Hideyoshi Maeda
>>>>> <hideyoshi.maeda at gmail.com> wrote:
>>>>>> If an example is required
>>>>>>
>>>>>> Here is an example:
>>>>>>
>>>>>> rm(list=ls(pos=.blotter),pos=.blotter)
>>>>>> rm(list=ls(pos=.instrument),pos=.instrument)
>>>>>> rm(list=ls(pos=.strategy),pos=.strategy)
>>>>>>
>>>>>> currency('USD')
>>>>>> stock("SPY", currency="USD", mulitplier=1)
>>>>>>
>>>>>> getSymbols('SPY', from='2012-03-01', to='2012-07-04')
>>>>>>
>>>>>> portf.name <- "dummy.Portfolio"
>>>>>>
>>>>>> initPortf(portf.name, 'SPY', initDate='2012-02-29')
>>>>>> initAcct(portf.name, portf.name, initDate='2012-02-29', initEq=1e6)
>>>>>>
>>>>>> qty <- rep(c(1,-1), nrow(SPY)/2)
>>>>>> price <- SPY[,4]
>>>>>> txnfees <- rep(-5, nrow(SPY))
>>>>>> txndata <- cbind(qty, price, txnfees)
>>>>>> colnames(txndata) <- c("Quantity","Price","txnfees")
>>>>>>
>>>>>> blotter:::addTxns(Portfolio=portf.name, Symbol='SPY', TxnData=txndata )
>>>>>>
>>>>>> txns <- getTxns(Portfolio=portf.name, Symbol='SPY')
>>>>>>
>>>>>> head(txns)
>>>>>> This will show the buying and selling of 1 share on alternate days at the close but will not show any of the fees relating to each transaction.
>>>>>>
>>>>>> Thanks
>>>>>>
>>>>>> HLM
>>>>>>
>>>>>> On 5 Jul 2012, at 01:48, Hideyoshi Maeda wrote:
>>>>>>
>>>>>>> Hi I am looking at the addTxns function in blotter, and I would like to add fees data/information in the TxnData argument (as a column).
>>>>>>>
>>>>>>> When looking at the function, by running
>>>>>>>
>>>>>>> blotter:::addTxns
>>>>>>> it seems to use the column names "Price" and "Quantity" but automatically sets/assigns the TxnFees to zero.
>>>>>>>
>>>>>>> Is there a way of overwriting this, so that it can be included in my analysis?
>>>>>>>
>>>>
>



More information about the R-SIG-Finance mailing list