Tag Info

Hot answers tagged r

4

Ah, this is becoming a common question, just in R now. Please look at this [question] (GARCH model and prediction), it has R code to do the prediction. In brief, you keep predicting one day ahead. $\sigma_{t+k}^2 =w+\alpha u_{t+k-1}^2+\beta \sigma_{t+k-1}^2$. You already know $w,\space \alpha \space and \space \beta$ the starting values are the last ...

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 ...

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

To determine the optimal number of states in a HMM is indeed an intricate one. Please have a look at the following paper: The Number of Regimes Across Asset Returns: Identification and Economic Value by M. Gatumel and F. Ielpo (2011) From the abstract: A shared belief in the financial industry is that markets are driven by two types of regimes. Bull ...

3

A free to use Excel Add-on providing QuantLib-backed derivatives pricing analytics directly in Excel is available at http://www.deriscope.com Disclosure: answerer is author of the package.

2

There is no guarantee that the optimization method always converges! In an introduction the author of the package recommends using the "hybrid" solver, which starts out with the "solnp" and goes through the other solvers, if it doesn't converge. According to him, this should at least guarantee convergence in 90 % of the cases. ...

2

If you wander about the theoretical result of fitting parameters, the book GARCH Models, Structure, Statistical Inference and Financial Applications of FRANCQ and ZAKOIAN provides a step-by-step explanation. I think that it is not a big problem to implement these steps to R.

2

I would suggest you to add spreads to the implied hazard rates, spreads that you regress on the macroeconomic factors. Then you stress by calculating the spreads corresponding to the stressed factors.

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

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

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

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 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 ... 1 Nothing to be worried about: Method is the type of correlation which is not a graphical parameter. The method argument is being passed to the pairs function... The function is saying this not a graphical parameter It can be fixed in the source code (or just ignore it!) 1 This is a feature, when you pass a vector it's because the risk free rate has changed over time. E.g. you can assume a constant or changing risk free rate as each period of returns can have an associated risk free rate. 1 Why not just use PortfolioAnalytics, as if your matrix is non positive definite you will have problems using non optimization approaches. Here is an example taken from my blog: retmat is a matrix of returns library(PortfolioAnalytics) moms_portfolio = portfolio.spec(assets=colnames(retmat)) moms_portfolio = ... 1 The mean equation specification for ARIMAX(8,0,0)(5,0,1)[7] (as in the R code above):$$ (1 - \phi_1L^1 - \ldots - \phi_8L^8)(1-\Phi_1L^7 - \Phi_2L^{14} - \ldots - \Phi_5L^{35})y_t = \beta x_t + (1 + \Theta_1L^7)\varepsilon_t  where $x_t$ is the holiday dummy variable. Equivalent ARIMA fit in Matlab (+ GARCH and forecasting): % specify seasonal ...

1

I have the same problem as you. Up to my knowledge, there is no package allowing to combine seasonal ARIMA process with GARCH effects.

1

It is a classical misunderstanding, your model is right, you always have a acf equal to one at lag zero (and not one) since if there is no lag acf = covariance(x , x_lag 0) / variance x = variance x / variance x = 1. So you need to pay attention to the x axis , some software displays ACF starting at lag zero and some others from 1 (which make better ...

1

Did you try rmgarch package of R ? http://cran.r-project.org/web/packages/rmgarch/index.html http://unstarched.net/r-examples/rmgarch/mgarch-comparison-using-the-hong-li-misspecification-test/

1

There is no such thing as "free" option data. This is free -->http://www.nasdaq.com/symbol/aapl/option-chain You could crawl that. But to get the actual ticks or intraday data, you will unfortunately have to pay. I strongly suggest you find a college business program that has option data ticks and reach out to them. Best of luck, JL

1

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 ...

1

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 ...

1

Are you aware of the findata.org site and its directory? The code is also in a bazaar repository as well as GitHub repo.

1

I like Quantlib http://quantlib.org/index.shtml http://cran.r-project.org/web/packages/RQuantLib/index.html The QuantLib project is aimed at providing a comprehensive software framework for quantitative finance. QuantLib is a free/open-source library for modeling, trading, and risk management in real-life. QuantLib is written in C++ with a clean object ...

1

The mean could be the long run variance which is sig2 = fit.Constant/(1-fit.GARCH{1}-fit.ARCH{1}); I hope this explains. If not, note I ran this model through Matlab, I get different values. you can paste your m1 and m2 values and some other intermediate results so I can see why Matlab differs. EDIT: The question refers to forecasting the returns. ...

1

A risk measure $\rho$ applied to time series $X \in \mathbb{R^n}$ yields $Y \in \mathbb{R}$. i.e. $\rho: \mathbb{R^n} \rightarrow \mathbb{R}$ As for implementation (using R), see here. A look at the formulas for VAR and ES (which is exactly the same as CVAR) should clear up any confusion.

1

For the first, people regularly compute VaR or CVaR over time and plot the results. For two and three, the documentation for the ETL function says that you can either calculate it using a Gaussian approach or Cornish-Fisher expansion. These are both analytical methods. The Gaussian approach uses only the mean and variance (effectively assuming that the ...

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