[Blotter-commits] r852 - in pkg/FinancialInstrument: . R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Nov 19 01:04:15 CET 2011


Author: gsee
Date: 2011-11-19 01:04:15 +0100 (Sat, 19 Nov 2011)
New Revision: 852

Modified:
   pkg/FinancialInstrument/DESCRIPTION
   pkg/FinancialInstrument/R/buildSpread.R
   pkg/FinancialInstrument/R/redenominate.R
Log:
 - when x is univariate and FX is OHLC, only use a single column from redenominate (Thanks Markus)
 - In buildSpread and redenominate, only use 1st column returned by getPrice style functions.
   The assumption is that prices will come before other data e.g. Open will come before OpenInterest
 - in buildSpread, when one leg is univariate, use colnames of the OHLC leg 



Modified: pkg/FinancialInstrument/DESCRIPTION
===================================================================
--- pkg/FinancialInstrument/DESCRIPTION	2011-11-17 16:42:07 UTC (rev 851)
+++ pkg/FinancialInstrument/DESCRIPTION	2011-11-19 00:04:15 UTC (rev 852)
@@ -11,7 +11,7 @@
     meta-data and relationships. Provides support for
     multi-asset class and multi-currency portfolios. Still
     in heavy development.
-Version: 0.9.1
+Version: 0.9.2
 URL: https://r-forge.r-project.org/projects/blotter/
 Date: $Date$
 Depends:

Modified: pkg/FinancialInstrument/R/buildSpread.R
===================================================================
--- pkg/FinancialInstrument/R/buildSpread.R	2011-11-17 16:42:07 UTC (rev 851)
+++ pkg/FinancialInstrument/R/buildSpread.R	2011-11-19 00:04:15 UTC (rev 852)
@@ -106,7 +106,7 @@
         } else pref=prefer
         if (!is.logical(instr_prices) || ncol(instr_prices) > 1) instr_prices <- getPrice(instr_prices,prefer=pref)
         if (instr$currency != spread_currency) 
-            instr_prices <- redenominate(instr_prices,spread_currency,instr$currency)
+            instr_prices <- getPrice(redenominate(instr_prices,spread_currency,instr$currency), pref=pref)
         instr_norm <- instr_prices * instr_mult * instr_ratio
         colnames(instr_norm) <- paste(as.character(spread_instr$members[i]), 
             prefer, sep = ".")

Modified: pkg/FinancialInstrument/R/redenominate.R
===================================================================
--- pkg/FinancialInstrument/R/redenominate.R	2011-11-17 16:42:07 UTC (rev 851)
+++ pkg/FinancialInstrument/R/redenominate.R	2011-11-19 00:04:15 UTC (rev 852)
@@ -177,22 +177,22 @@
     mrat <- mult1 / mult2
 
     if (is.OHLC(x1) && is.OHLC(x2)) {
-        op <- Op(x1) / Op(x2) * mrat
-        cl <- Cl(x1) / Cl(x2) * mrat
-        if (!has.Ad(x1)) x1$Adjusted <- Cl(x1)
-        if (!has.Ad(x2)) x2$Adjusted <- Cl(x2)
-        ad <- Ad(x1) / Ad(x2) * mrat
+        op <- Op(x1)[,1] / Op(x2)[,1] * mrat
+        cl <- Cl(x1)[,1] / Cl(x2)[,1] * mrat
+        if (!has.Ad(x1)) x1$Adjusted <- Cl(x1)[,1]
+        if (!has.Ad(x2)) x2$Adjusted <- Cl(x2)[,1]
+        ad <- Ad(x1)[,1] / Ad(x2)[,1] * mrat
         rat <- cbind(op,cl,ad)
         colnames(rat) <- paste(rat.sym, c("Open","Close","Adjusted"),sep='.')
     } else if (is.BBO(x1) && is.BBO(x2)) {
-        bid <- Bi(x1)/As(x2) * mrat
-        ask <- As(x1)/Bi(x2) * mrat
+        bid <- Bi(x1)[,1]/As(x2)[,1] * mrat
+        ask <- As(x1)[,1]/Bi(x2)[,1] * mrat
         if (has.Mid(x1) && has.Mid(x2)) {
-            mid <- Mid(x1) / Mid(x2) * mrat 
+            mid <- Mid(x1)[,1] / Mid(x2)[,1] * mrat 
         } else {
-            mid <- ((Bi(x1)+As(x1))/2) / ((Bi(x2)+As(x2))/2) * mrat
+            mid <- ((Bi(x1)[,1]+As(x1)[,1])/2) / ((Bi(x2)[,1]+As(x2)[,1])/2) * mrat
         }
-        rat <- cbind(bid,ask,mid)        
+        rat <- cbind(bid,ask,mid)
         colnames(rat) <- paste(rat.sym,c('Bid','Ask','Mid'),sep='.')
     } else if (NCOL(x1) == 1 && NCOL(x2) == 1) {
         rat <- x1 / x2 * mrat #coredata(x1) / coredata(x2)
@@ -202,7 +202,7 @@
             div <- if (NCOL(x2) == 1) {
                         x2
                    } else if (has.Mid(x2)) {
-                        Mid(x2)
+                        Mid(x2)[,1]
                    } else getPrice(x2)
             rat <- mrat * x1[,1] / div
             if (NCOL(x1) > 1) {
@@ -214,13 +214,14 @@
             num <- if (NCOL(x1) == 1){
                         x1
                     } else if (has.Mid(x1)) {
-                        Mid(x1)
+                        Mid(x1)[,1]
                     } else getPrice(x1)
             rat <- mrat * num / x2[,1]
             if (NCOL(x2) > 1) {
                 for (i in 2:NCOL(x2)) {
                     rat <- cbind(rat, mrat * num/x2[,i])
-                }                  
+                }
+                colnames(rat) <- colnames(x2)                  
             }  
         }    
     } else if (periodicity(x1)$frequency < 86400) {
@@ -229,10 +230,10 @@
             div <- if (NCOL(x2) == 1) {
                         x2
                     } else if (has.Cl(x2)) {
-                        Cl(x2)
+                        Cl(x2)[,1]
                     } else if (has.Ad(x2)) {
-                        Ad(x2)    
-                    } else getPrice(x2)
+                        Ad(x2)[,1]    
+                    } else getPrice(x2)[,1]
             rat <- mrat * x1[,1] / div
             if (NCOL(x1) > 1) {            
                 for (i in 2:NCOL(x1)) {
@@ -243,10 +244,10 @@
             num <- if (NCOL(x1) == 1) {
                         x1
                     } else if (has.Cl(x1)) {
-                        Cl(x1)
+                        Cl(x1)[,1]
                     } else if (has.Ad(x1)) {
-                        Ad(x1)
-                    } else getPrice(x1)
+                        Ad(x1)[,1]
+                    } else getPrice(x1)[,1]
             rat <- mrat * num / x2[,1]
             if (NCOL(x2) > 1){
                 for (i in 2:NCOL(x2)) {
@@ -348,8 +349,8 @@
         } else if(is.BBO(rate)) {
             if (periodicity(x)$scale == 'daily') {
                 rate <- .to_daily(rate, EOD_time) #This doesn't make OHLC, the rest do.
-            } else rate <- to.period(Mid(rate), periodicity(x)$units) 
-        } else rate <- to.period(getPrice(rate), periodicity(x)$units)
+            } else rate <- to.period(Mid(rate)[,1], periodicity(x)$units) 
+        } else rate <- to.period(getPrice(rate)[,1], periodicity(x)$units)
     }
 
     # If you have intraday data for x and daily data for rate



More information about the Blotter-commits mailing list