# Tag Info

## Hot answers tagged r

13

This is interesting because I see another trend: Matlab is being replaced by R, but I guess this is another story. I use R for my academic (I am also teaching this stuff) as well as my consulting work (I am mainly working in the $\mathbb{P}$ area, with some excursions into $\mathbb{Q}$). I tried Python but it didn't work for me. I think the main reasons I ...

12

My deal is HFT so what I care about is read/load data from file or DB quickly in memory perform very efficient data-munging operations (group,transform) visualize easily the data I think is is pretty clear that 3. goes to R, graphics and ggplot2 and others allow you to plot anything from scratch with little effort. About 1. and 2. I am amazed reading ...

10

I've used both R and Python with Pandas in a professional quantitative financial work to do both large and small scale projects. I would strongly recommend Python with Pandas over R for most new projects in the field especially in time series analysis. While I don't dispute vonjd in that you will find more libraries in R with algorithms on the bleeding ...

6

For data analysis, particularly for large data analysis project, pretty much most of the top quant hedge funds and a lot of the banks are using Python (over R) for a couple of reasons, although many still have bits and pieces of R for specific packages or functions (I work at a bank and interface with quite a few quant hedge funds on data analysis): ...

4

The NS model should be fit directly to bond prices. If you have the prices of all the Treasuries, you should use those directly. See this paper for how the Fed does it http://www.federalreserve.gov/pubs/feds/2006/200628/200628pap.pdf The "Daily Treasury Yield Curve Rates" are already fitted par yields (they're fitted using a cubic spline model to on-the-run ...

4

Instead of wild guesses about R's/python's future in the community, here some facts: The following query on StackExchange Data Explorer counts the number of questions that have <r> or <python> tags. If you scroll down on one of the three webpages provided below, you can see a graph with data on a monthly basis. You can easily run this query on ...

4

If you can add linear constriants (as you can do in quadprog) then you can formulate $w \mu = c_1$ as linear constraint, no matter what $\mu$ is (and first delete it from the objective by setting the parameter to zero. The only problem is the one norm. Let my clarify, this is: $$\sum_{i=1}^n |w_i| < c_2$$ Thus you allow for short sales but you want to ...

4

At first we considered it to be a bug where the overrides does not propagate correctly. Edit: Here is a corrected examples, thanks to @Sid. Setting it as an options field works: library(Rblpapi) blpConnect() ## initalize data import end.dt <- Sys.Date() start.dt <- end.dt - 100 # keep it simple for example index.growth <- "MXUS000G Index" ...

4

You're setting an option, not an override. Your code works fine if you replace names(overrides.px) = "periodicity" px = bdh(securities = indices,fields = "px_last",start.date = start.dt,end.date = end.dt, overrides = overrides.px) with names(overrides.px) = "periodicitySelection" px = bdh(securities = indices,fields = "px_last",start.date = ...

3

You can use Matlab too, that, in my humble opinion, is simpler than R from a syntax point of view. The model you need for is run by the Matlab function arima that can be used with seasonality option to do what you have to do. Here you can find an example and a brief explanation of the model. Type ctrl + F and search for: "Specify a seasonal ARIMA model" ...

3

For the tasks listed, both Python and R preform very well. There are some packages in Python not in R and visa-versa, my solution for this is to simply call R from Python. This allows for the best of both worlds. It is also important to note I do not write any R code other than calling an R library from Python. Calling Python from R does not work equally ...

3

Answering my own question as it could be useful for others. Actually package fOptions is vectorized. The only constraint (and that make sense) is that you can't compute at the same time 2 different greeks, or mix up calls and puts. So assuming that you want to compute the delta of a set of puts, the code will be the following: ...

3

Yes, it exists and it is called ccgarch package. You can install that by simply running in R install.packages("ccgarch") and learn more about that on the CRAN relative paper. Moreover, I suggest you to read this lecture hold by the author during an R conference. Hope this help.

2

I'm going to separate your question in two. The key thing you're asking is that how does Return.rebalancing treat your different frequencied and number of asset return and weight objects. Data munging: It subsets the first ncol(weight) columns of R (as ncol(edhec) > ncol(weights) ncol R is now 11. Checks if the first date in R is less than the first date ...

2

I found out that the upper time series is the result of a call > tail(Return.rebalancing(edhec,weights)) portfolio.returns 2009-03-31 0.005082048 2009-04-30 0.022982981 2009-05-31 0.037432398 2009-06-30 0.011107189 2009-07-31 0.025580507 2009-08-31 0.017983519 (by optical comparison. ;-) ) A glance ...

2

PortfolioAnalytics, has the ability to optimize portfolios based on factors or whatever groups/characteristics you enter. https://r-forge.r-project.org/R/?group_id=579 Please refer to the vignette in the package in the package PortfolioAnalytics (https://r-forge.r-project.org/scm/viewvc.php/pkg/PortfolioAnalytics/vignettes/?root=returnanalytics I use it ...

2

My favorite tool is Sornette's own Finanical Crisis Observatory: http://tasmania.ethz.ch/pubfco/fco.html If you are interested, I have developed my own tool in Java and JavaCL which can be found here: https://thebubbleindex.codeplex.com/

2

Actually, neither of your two results are quite correct. As explained in the Details for the Return.calculate function, most of the PerformanceAnalytics functions use discrete returns, not log returns. To get the correct results, you will have to convert your data from log returns to simple returns. Compare the charts from the following: ...

2

The documentation of the R package PerformanceAnalytics provides examples for both the Return.annualized() and Return.cumulative() functions. The annualized return scales up sub-annual returns to an annual return. You may observe the difference by typing Return.annualized (without any parameters) in your R console to see the functions implementation. Look ...

2

Use PortfolioAnalytics See my previous response here: http://quant.stackexchange.com/a/16002/2154 , you will find links to the documentation there. You can use the constraint function to add a factor exposure constraint of 0. use add.constraint(your_portfolio_name,type='factor_exposure',B = your_vector_of_betas,lower=0,upper=0)

2

7 years ago I had to solve the problem of a efficiency frontier under linear constraints on the asset weights and also stumbled upon Markowitz Critial Line Algorithm. I still have a directory with some resources in it. Since Bryce already gave a practical implementation with R code by Eric Zivot, I will concentrate on some papers which might help. I ...

2

Both R and Python can do this very nicely. For Python you would need the pandas package and its dependencies. pandas has a lot of basic statistics, but for more advanced statistics like it looks like you want to do, you can use the statsmodels package, which can work directly with pandas data types. It can also download the csv files directly off the ...

2

Similar to Juan Gil's answer but a bit differently I would say the following based on this: The OU process $$dX_t = \kappa(\theta-X_t)dt + \sigma dW_t$$ can be (Euler-Maryuama discretization) discretized at times $n \Delta t,n=1,\ldots,\infty$ which gives with $t = k \Delta t$ $$X_{k+1} - X_k = \kappa \theta \Delta t -\kappa X_k \Delta t + \sigma (W_{k+1} ... 2 For a Ornstein-Uhlenbeck process, the maximum likelihood parameters are the ones from least squares regression. If your process is:$$ dX=\kappa (\theta-X)dt+\sigma dW $$you can do a linear regression in the form$$ \frac{dX}{dt}=a+bX+\epsilon $$So your parameters will be:$$ \kappa=-b  \theta=-\frac{a}{b}  \sigma=std(\epsilon dt) $$2 Looking at your code, you seem to be mixing the risk minimization formulation of the mean-variance problem with the risk aversion formulation. Both formulations include the "budget" constraint, that the sum of the weights equal 1, and can require that each of the weights be greater than zero, the "long-only" inequality constraints. In the risk minimization ... 2 You can do this using the optim function in R. One possible solution is as follows: base <- c(0.9190, 0.0739, 0.0072, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0113, 0.9126, 0.0709, 0.0031, 0.0021, 0.0000, 0.0000, 0.0000, 0.0010, 0.0256, 0.9119, 0.0533, 0.0062, 0.0021, 0.0000, 0.0000, 0.0000, 0.0021, 0.0536, 0.8794, ... 2 R package TTR has rolling window algorithms and understands day counting etc. It stands on the shoulders of xts (which extends zoo) and quantmod 2 There are a couple of issues with your example. First, for this ticker, there is a problem with the Yahoo price data for the period 2014-11-26 through 2014-12-03 in which the prices drop about 80% and then return to their trend line. This appears to be related to a stock split which Yahoo isn't handling properly and isn't real. Its causing part of your ... 2 In the paper you cited in the question, the equation (1) is not the equation of state in kalman filter model, but an AR(3) estimated via OLS as shown in Stock & Watson (2002). What the authors estimated in the paper using the Kalman filter is the latent variables f_t,_h and the relative lags through which they estimated both the equation (1) and ... 2 I wonder if it's possible to use solve.QP from quadprog by using dummy variables. One dummy variable y_i would be used for each w_i, each y_i would be constrained to be greater than zero, and the leverage constraint would be applied to the sum of the y_i. Problem formulation would look like$$ \text{min } w^tΣw  subject to the ...

Only top voted, non community-wiki answers of a minimum length are eligible