[R-SIG-Finance] Problem with updatePortf

G See gsee000 at gmail.com
Fri Sep 21 04:43:59 CEST 2012


getPrice looks for a price column and it only works if the xts object
has colnames.

> getPrice(USDCHF)
Error in getPrice(USDCHF) :
  subscript out of bounds, no price was discernible from the data

You need to add colnames.

> colnames(USDCHF) <- c("Bid", "Ask", "Last.Price")
> getPrice(USDCHF)
           Last.Price
2005-09-01     1.2343
2005-09-02     1.2280
2005-09-05     1.2335
2005-09-06     1.2365
2005-09-07     1.2426
2005-09-08     1.2449
2005-09-09     1.2442
2005-09-12     1.2592
2005-09-13     1.2619
2005-09-14     1.2585
2005-09-15     1.2671
2005-09-16     1.2687
2005-09-19     1.2772
2005-09-20     1.2809
2005-09-21     1.2718
2005-09-22     1.2795
2005-09-23     1.2916
2005-09-26     1.2896
2005-09-27     1.2959
2005-09-28     1.2940

Although getPrice is not documented, you can look at its code to see
what it does.  If you do not provide a value for the "prefer"
argument, it looks for a column name that contains the word "price".
If it cannot find that, it looks for "trade".  Finally, it looks for
"close".  If your colnames don't contain any of those words, or if you
want to use a different column, you can specify that with the "prefer"
argument

> getPrice(USDCHF, prefer="Bid")
              Bid
2005-09-01 1.2558
2005-09-02 1.2368
2005-09-05 1.2344
2005-09-06 1.2404
2005-09-07 1.2444
2005-09-08 1.2470
2005-09-09 1.2470
2005-09-12 1.2597
2005-09-13 1.2640
2005-09-14 1.2613
2005-09-15 1.2696
2005-09-16 1.2729
2005-09-19 1.2815
2005-09-20 1.2818
2005-09-21 1.2825
2005-09-22 1.2809
2005-09-23 1.2918
2005-09-26 1.2965
2005-09-27 1.2998
2005-09-28 1.2984

Garrett

On Thu, Sep 20, 2012 at 9:30 PM, Worik Stanton <worik.stanton at gmail.com> wrote:
> On 21/09/12 14:10, Worik Stanton wrote:
>> [snip]
>> I am working on a small example that exhibits the problem but in the
>> mean time is there a way I can debug .updatePosPL?
>
> So here is an example without transactions.
>
> I am a novice with blotter so tis example could probably be smaller.  I
> have tried to distill what are the most important points (hence no
> transactions).
>
> When I run this I get...
>
>> go()
> 2005-09-01
> FOO
> Error in getPrice(get(Symbol, pos = env), symbol = symbol, prefer =
> prefer) :
>   subscript out of bounds, no price was discernible from the data
>>



More information about the R-SIG-Finance mailing list