[R-SIG-Finance] Blotter package would it work for cross currencies

ce zadig_1 at excite.com
Fri Oct 17 20:44:33 CEST 2014


Thank you very much Brian. Following your guidance I have following code.  I still don't understand some field in the output. 
Manually I  buy 25,000 EURAUD at price 1.4552 and sell it next day at price 1.4512. I should earn 100 AUD.
 $symbols$EURAUD$txn section confirms it. But I don't understand $symbols$EURAUD$posPL.USD section.  25,000 EUR makes 31569.64 USD,  you calculate it 45940.14 ( = 25,000 * 1.262786 * 1.4552), why ? 
Also I don't understand why there is a -126.7427 ? Is it because you USD/EUR conversion during trade days ? 
How come end equity is 42.11206 ? 

library(quantstrat)
library(quantmod)
options("getSymbols.warning4.0"=FALSE)

currency("USD")
currency("EUR")
currency("AUD")

exchange_rate("EURAUD", currency="EUR", counter_currency="AUD", src=list(name='EUR/AUD', src='oanda'))
exchange_rate("USDEUR", currency="USD", counter_currency="EUR", src=list(name='USD/EUR', src='oanda'))

getSymbols("EURAUD", from=Sys.Date()-30)
getSymbols("USDEUR", from=Sys.Date()-30)
colnames(EURAUD) <- "price"
colnames(USDEUR) <- "price"

initPortf("PF1", symbols= c("EURAUD","USDEUR"), initDate="2014-10-12")
initAcct("myacct", portfolios="PF1", initDate="2014-10-12", initEq=30000)
initOrders(portfolio="PF1",initDate="2014-10-12")

addTxn("PF1", Symbol="EURAUD", TxnDate="2014-10-13", TxnPrice=1.4552, TxnQty= 25000)
addTxn("PF1", Symbol="EURAUD", TxnDate="2014-10-14", TxnPrice=1.4512, TxnQty=-25000)

updatePortf("PF1",   Dates = "2014-10-12::2014-10-15")
updateAcct("myacct", Dates = "2014-10-12::2014-10-15")
updateEndEq("myacct",Dates = "2014-10-12::2014-10-15")

getPortfolio("PF1")
getAccount("myacct")

> getPortfolio("PF1")
$summary
      Long.Value Short.Value Net.Value Gross.Value
2014-10-12 00:00:00       0.00           0      0.00        0.00
2014-10-12 20:00:00       0.00           0      0.00        0.00
2014-10-13 00:00:00   45940.14           0  45940.14    45940.14
2014-10-13 20:00:00   45982.26           0  45982.26    45982.26
2014-10-14 00:00:00       0.00           0      0.00        0.00
2014-10-14 20:00:00       0.00           0      0.00        0.00
                    Period.Realized.PL Period.Unrealized.PL Gross.Trading.PL
2014-10-12 00:00:00             0.0000              0.00000     0.000000e+00
2014-10-12 20:00:00             0.0000             0.00000     0.000000e+00
2014-10-13 00:00:00             0.0000              0.00000     0.000000e+00
2014-10-13 20:00:00       0.0000             42.11206     4.211206e+01
2014-10-14 00:00:00          -126.7427            126.74271     9.947598e-14
2014-10-14 20:00:00             0.0000              0.00000     0.000000e+00
                    Txn.Fees Net.Trading.PL
2014-10-12 00:00:00        0   0.000000e+00
2014-10-12 20:00:00        0   0.000000e+00
2014-10-13 00:00:00        0   0.000000e+00
2014-10-13 20:00:00        0   4.211206e+01
2014-10-14 00:00:00        0   9.947598e-14
2014-10-14 20:00:00        0   0.000000e+00

$symbols
$symbols$USDEUR
$symbols$USDEUR$txn
           Txn.Qty Txn.Price Txn.Value Txn.Avg.Cost Pos.Qty Pos.Avg.Cost
2014-10-12    0         0         0            0       0            0
           Gross.Txn.Realized.PL Txn.Fees Net.Txn.Realized.PL Con.Mult
2014-10-12                     0        0                   0        0

$symbols$USDEUR$posPL.USD
                    Pos.Qty Con.Mult Ccy.Mult Pos.Value Pos.Avg.Cost Txn.Value
2014-10-11 20:00:00       0        0        1         0            0         0
2014-10-12 00:00:00       0        0        1         0            0         0
2014-10-12 20:00:00       0        0        1     0            0         0
2014-10-13 20:00:00       0        0        1         0            0         0
2014-10-14 20:00:00     0        0        1         0            0         0
                    Period.Realized.PL Period.Unrealized.PL Gross.Trading.PL
2014-10-11 20:00:00                  0                    0                0
2014-10-12 00:00:00                  0                    0                0
2014-10-12 20:00:00                  0                0                0
2014-10-13 20:00:00                  0                    0                0
2014-10-14 20:00:00             0                    0                0
                    Txn.Fees Net.Trading.PL
2014-10-11 20:00:00        0              0
2014-10-12 00:00:00        0              0
2014-10-12 20:00:00        0              0
2014-10-13 20:00:00        0            0
2014-10-14 20:00:00        0              0

$symbols$USDEUR$posPL
                    Pos.Qty Con.Mult Ccy.Mult Pos.Value Pos.Avg.Cost Txn.Value
2014-10-11 20:00:00       0        0        1         0            0         0
2014-10-12 00:00:00       0  0        1         0            0         0
2014-10-12 20:00:00       0        0        1         0            0         0
2014-10-13 20:00:00       0        0        1         0            0         0
2014-10-14 20:00:00       0        0        1         0            0         0
                    Period.Realized.PL Period.Unrealized.PL Gross.Trading.PL
2014-10-11 20:00:00       0                    0                0
2014-10-12 00:00:00                  0                    0                0
2014-10-12 20:00:00                  0                    0                0
2014-10-13 20:00:00                  0                    0   0
2014-10-14 20:00:00                  0                    0                0
                    Txn.Fees Net.Trading.PL
2014-10-11 20:00:00        0              0
2014-10-12 00:00:00        0              0
2014-10-12 20:00:00        0              0
2014-10-13 20:00:00        0              0
2014-10-14 20:00:00        0              0


$symbols$EURAUD
$symbols$EURAUD$txn
   Txn.Qty Txn.Price Txn.Value Txn.Avg.Cost Pos.Qty Pos.Avg.Cost
2014-10-12       0    0.0000         0       0.0000       0       0.0000
2014-10-13   25000    1.4552     36380       1.4552   25000       1.4552
2014-10-14  -25000    1.4512    -36280       1.4512       0       0.0000
           Gross.Txn.Realized.PL Txn.Fees Net.Txn.Realized.PL Con.Mult
2014-10-12                     0        0                   0        0
2014-10-13                     0        0                   0        1
2014-10-14        -100        0                -100        1

$symbols$EURAUD$posPL.USD
                    Pos.Qty Con.Mult Ccy.Mult Pos.Value Pos.Avg.Cost Txn.Value
2014-10-11 20:00:00       0        0 1.262786      0.00     0.000000      0.00
2014-10-12 00:00:00       0 0 1.262786      0.00     0.000000      0.00
2014-10-12 20:00:00       0        0 1.262786      0.00     0.000000      0.00
2014-10-13 00:00:00   25000        1 1.262786  45940.14     1.837606  45940.14
2014-10-13 20:00:00   25000        1 1.267427  45982.26     1.844360      0.00
2014-10-14 00:00:00       0        1 1.267427      0.00     0.000000 -45982.26
2014-10-14 20:00:00     0        1 1.268875      0.00     0.000000      0.00
                    Period.Realized.PL Period.Unrealized.PL Gross.Trading.PL
2014-10-11 20:00:00             0.0000              0.00000     0.000000e+00
2014-10-12 00:00:00             0.0000           0.00000     0.000000e+00
2014-10-12 20:00:00             0.0000              0.00000     0.000000e+00
2014-10-13 00:00:00       0.0000              0.00000     0.000000e+00
2014-10-13 20:00:00             0.0000             42.11206     4.211206e+01
2014-10-14 00:00:00          -126.7427            126.74271     9.947598e-14
2014-10-14 20:00:00             0.0000              0.00000     0.000000e+00
                    Txn.Fees Net.Trading.PL
2014-10-11 20:00:00        0   0.000000e+00
2014-10-12 00:00:00 0   0.000000e+00
2014-10-12 20:00:00        0   0.000000e+00
2014-10-13 00:00:00        0   0.000000e+00
2014-10-13 20:00:00    0   4.211206e+01
2014-10-14 00:00:00        0   9.947598e-14
2014-10-14 20:00:00        0   0.000000e+00

$symbols$EURAUD$posPL
                    Pos.Qty Con.Mult Ccy.Mult Pos.Value Pos.Avg.Cost Txn.Value
2014-10-11 20:00:00       0        0        1    0       0.0000         0
2014-10-12 00:00:00       0        0        1         0       0.0000         0
2014-10-12 20:00:00     0        0        1         0       0.0000         0
2014-10-13 00:00:00   25000        1        1     36380       1.4552     36380
2014-10-13 20:00:00   25000        1        1     36280       1.4552         0
2014-10-14 00:00:00       0        1        1         0       0.0000    -36280
2014-10-14 20:00:00       0        1        1         0       0.0000         0
               Period.Realized.PL Period.Unrealized.PL Gross.Trading.PL
2014-10-11 20:00:00                  0                    0            0
2014-10-12 00:00:00                  0                    0                0
2014-10-12 20:00:00                  0           0                0
2014-10-13 00:00:00                  0                    0                0
2014-10-13 20:00:00             0                 -100             -100
2014-10-14 00:00:00               -100                  100                0
2014-10-14 20:00:00                  0                    0                0
                    Txn.Fees Net.Trading.PL
2014-10-11 20:00:00        0              0
2014-10-12 00:00:00        0              0
2014-10-12 20:00:00        0              0
2014-10-13 00:00:00        0              0
2014-10-13 20:00:00        0           -100
2014-10-14 00:00:00        0              0
2014-10-14 20:00:00        0              0



attr(,"class")
[1] "blotter_portfolio" "portfolio"
attr(,"currency")
[1] "USD"
attr(,"initDate")
[1] "2014-10-12"
> getAccount("myacct")
$portfolios
$portfolios$PF1
                    Long.Value Short.Value Net.Value Gross.Value Realized.PL
2014-10-12 00:00:00       0.00           0      0.00        0.00      0.0000
2014-10-12 00:00:00       0.00           0      0.00        0.00      0.0000
2014-10-12 20:00:00       0.00           0      0.00        0.00      0.0000
2014-10-13 00:00:00   45940.14           0  45940.14    45940.14      0.0000
2014-10-13 20:00:00   45982.26           0  45982.26 45982.26      0.0000
2014-10-14 00:00:00       0.00           0      0.00        0.00   -126.7427
2014-10-14 20:00:00       0.00           0      0.00        0.00      0.0000
                    Unrealized.PL Gross.Trading.PL Txn.Fees Net.Trading.PL
2014-10-12 00:00:00       0.00000     0.000000e+00        0   0.000000e+00
2014-10-12 00:00:00       0.00000     0.000000e+00        0   0.000000e+00
2014-10-12 20:00:00       0.00000     0.000000e+00        0   0.000000e+00
2014-10-13 00:00:00       0.00000    0.000000e+00        0   0.000000e+00
2014-10-13 20:00:00      42.11206     4.211206e+01        0   4.211206e+01
2014-10-14 00:00:00     126.74271     9.947598e-14        0   9.947598e-14
2014-10-14 20:00:00       0.00000     0.000000e+00        0   0.000000e+00


$summary
                    Additions Withdrawals Realized.PL Unrealized.PL Interest
2014-10-12 00:00:00         0     0      0.0000       0.00000        0
2014-10-12 00:00:00         0           0      0.0000       0.00000        0
2014-10-12 00:00:00         0           0      0.0000       0.00000        0
2014-10-12 20:00:00         0           0      0.0000       0.00000        0
2014-10-13 00:00:00         0           0      0.0000       0.00000        0
2014-10-13 20:00:00         0          0      0.0000      42.11206        0
2014-10-14 00:00:00         0           0   -126.7427     126.74271        0
2014-10-14 20:00:00         0           0      0.0000       0.00000        0
                    Gross.Trading.PL Txn.Fees Net.Trading.PL Advisory.Fees
2014-10-12 00:00:00     0.000000e+00        0   0.000000e+000
2014-10-12 00:00:00     0.000000e+00        0   0.000000e+00             0
2014-10-12 00:00:00     0.000000e+00        0   0.000000e+00             0
2014-10-12 20:00:00     0.000000e+00        0   0.000000e+00             0
2014-10-13 00:00:00     0.000000e+00        0   0.000000e+00             0
2014-10-13 20:00:00     4.211206e+01        0   4.211206e+01             0
2014-10-14 00:00:00     9.947598e-14        0   9.947598e-14             0
2014-10-14 20:00:00     0.000000e+00        0   0.000000e+00             0
                    Net.Performance   End.Eq
2014-10-12 00:00:00    0.000000e+00  0.00000
2014-10-12 00:00:00    0.000000e+00  0.00000
2014-10-12 00:00:00    0.000000e+00  0.00000
2014-10-12 20:00:00    0.000000e+00  0.00000
2014-10-13 00:00:00    0.000000e+00  0.00000
2014-10-13 20:00:00    4.211206e+01 42.11206
2014-10-14 00:00:00    9.947598e-14 42.11206
2014-10-14 20:00:00    0.000000e+00 42.11206

$Additions
           Additions
2014-10-12         0

$Withdrawals
           Withdrawals
2014-10-12           0

$Interest
           Interest
2014-10-12        0

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



-----Original Message-----
From: "Brian G. Peterson" [brian at braverock.com]
Date: 10/12/2014 05:50 PM
To: r-sig-finance at r-project.org
Subject: Re: [R-SIG-Finance] Blotter package would it work for cross
	currencies

Yes, it can, with a few minor difficulties.

To start with, you need to choose the currency of your Portfolios and 
Account.  Other wise it will default to USD.

also, you will want to specify your instruments correctly.  they are
of type exchange_rate.  See documentation and examples in the 
FinancialInstrument package.

Brian

On 10/12/2014 04:39 PM, ce wrote:
>
> Sorry for the double post.
>
> I would like to know it blotter package can be used to calculate performance/returns  of a portfolio mixed with cross currencies like GBP.EUR , CAD.CHF ?
> I can create a stock with
>
> stock("GBP",currency="EUR",multiplier=1)
>
>
> but functions like PortfReturns , getEndEq don't seem to care about currency ?

_______________________________________________
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