[Blotter-commits] r312 - pkg/blotter/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Mar 28 19:17:55 CEST 2010


Author: braverock
Date: 2010-03-28 19:17:55 +0200 (Sun, 28 Mar 2010)
New Revision: 312

Modified:
   pkg/blotter/R/updatePosPL.R
Log:
- add capability for reversed exchange rate e.g. EURUSD required, but USDEUR available

Modified: pkg/blotter/R/updatePosPL.R
===================================================================
--- pkg/blotter/R/updatePosPL.R	2010-03-28 17:05:22 UTC (rev 311)
+++ pkg/blotter/R/updatePosPL.R	2010-03-28 17:17:55 UTC (rev 312)
@@ -49,6 +49,7 @@
     }
     CcyMult = NULL 
     FXrate = NULL
+    invert=FALSE
     if(!is.null(attr(Portfolio,'currency'))) {
         p.ccy.str<-attr(Portfolio,'currency')
         if (tmp_instr$currency==p.ccy.str) {
@@ -67,6 +68,8 @@
                     if(inherits(FXrate,"try-error")){ 
                         warning("Exchange Rate",FXrate.str," not found for symbol,',Symbol,' using currency multiplier of 1")
                         CcyMult<-1
+                    } else {
+                        invert=TRUE
                     }
                 }
             }
@@ -107,6 +110,12 @@
             CcyMult<-1
             PrevCcyMult<-CcyMult
         }
+        if(isTRUE(invert)){
+            # portfolio and instrument have different currencies, and FXrate was in the wrong direction
+            CcyMult<-1/CcyMult
+            PrevCcyMult<-1/PrevCcyMult
+        }
+        
         #TODO write a single getTxn and use the values instead of these lines
         TxnValue = getTxnValue(pname, Symbol, CurrentSpan)*CcyMult
         TxnFees = getTxnFees(pname, Symbol, CurrentSpan)*CcyMult



More information about the Blotter-commits mailing list