[R-SIG-Finance] PerformanceAnalytics package: modern econometrics (...)

Bengoechea Bartolomé Enrique (SIES 73) enrique.bengoechea at credit-suisse.com
Tue Mar 6 16:03:14 CET 2007


Hi Brian,

Thanks a lot for sharing this package, which I find very very interesting, and fills an important gap in R financial packages.

After reviewing the docs I have some remarks which I know are mainly a matter of personal preference rather than real issues, and I know YMMV, but please let me share them with you.

First, on function names. When I started programming in R I created verbose names like the ones in this package. I came from a background in languages like Java where communicating purpose is important when naming functions and variables, and typing long names is not an issue because IDEs make your life easy. Nevertheless, R is also an *interactive* environment, and I realized I was typing the same long names again and again on the GUI, which was repetitive, prone to error, and bad for my RSI. So with time I renamed functions like "CalculateReturns" and "MaxDrawdown" to "returns" or "mdd", and I'm much happier now... 

I also learnt to turn my functions into methods. As a functional language, functions are first-class elements in R. It's generally recommeded to avoid polluting the namespace with tons of new functions, which makes them hard to remember. The preferred design is to create new classes that use standard methods as much as possible, as they are already known and easily remembered by other R users. An example of this for financial users is the difference between classes "timeSeries" and "zoo". I extensively tested both of them (and several others), and decided to use "zoo" for what is stated on its documentation:

"key design goals are (...) consistency with ts and base R by providing methods to standard generics. Therefore, standard functions can be used to work with "zoo" objects and memorization of new commands is reduced."

I really like "timeSeries", but having to remember and type "diffSeries" each time instead of just "diff", which I can apply to many different classes of objects, is a pain in the ass for me. And I see similar design decisions on this PerformanceAnalytics package.

With respect to parameters naming, I also find disturbing to have the main parameter of each function called "R", the name of the language itself!!! I started applying different conventions to my functions, but ended up using those in the base R package, where the main argument is usually called "x", "data", or similar.

I hope this is useful.

Best,

Enrique



More information about the R-SIG-Finance mailing list