Hot answers tagged r
7
The clearest and most intuitive article I have seen so far is
Kritzman et al., Regime Shifts: Implications for Dynamic Strategies in FAJ (May / June 2012)
It not only shows how you can use HMM for financial modelling but it also goes through the actual estimation algorithm (Baum-Welch) step-by-step and even gives full MATLAB-code.
From the abstract:
...
6
A simple google search should get your started:
I like this one the best because it compares different packages:
http://stat-www.berkeley.edu/~brill/Stat248/kalmanfiltering.pdf
and here couple more:
http://www.r-bloggers.com/the-kalman-filter-for-financial-time-series/
http://cran.r-project.org/web/packages/dlm/index.html
...
5
Mh, well I am not sure about already implemented functions, sure, I think they will exist. I give you a solution, with the direct implementation of the EWMA, so it does not need a preimplemented function.
Here is the code:
# just simulating some values, not sensible ones, just for
# demonstration purposes
returnseries<-runif(1000, min=-0.2, max=0.2)
...
5
Systematic Investor also did a two part series implementation in R which is also quite helpful as he details the pitfalls too.
Post One:
http://systematicinvestor.wordpress.com/2012/11/01/regime-detection/
Part Two:
http://systematicinvestor.wordpress.com/2012/11/15/regime-detection-pitfalls/
4
The difference is not an artifact of floating point arithmetic; it's a difference in compounding frequency. The returns in your example are fairly close to zero, so they don't look that different. Larger changes in price will cause larger differences between the two calculation methods.
Pat Burns wrote a nice blog post about the difference between ...
4
The code of Euler Maruyama simulation method is pretty simple (nu is long run mean, lambda is mean reversion speed):
ornstein_uhlenbeck <- function(T,n,nu,lambda,sigma,x0){
dw <- rnorm(n, 0, sqrt(T/n))
dt <- T/n
x <- c(x0)
for (i in 2:(n+1)) {
x[i] <- x[i-1] + lambda*(nu-x[i-1])*dt + sigma*dw[i-1]
}
return(x);
}
4
You want to set the parameter n.roll to the number of n.ahead, n.roll rolling forecasts you want. (The n.ahead parameter controls how many steps ahead you want to forecast for each roll date.) Thus by setting n.roll to a number almost equal to your sample size, and critically setting the out.sample parameter almost equal to your sample size, you're telling ...
3
you need to use the forecast for both the mean and sigma. It should look something like this:
forecast = ugarchforecast(modelfit, n.ahead = 1, data = mydata);
sigma(forecast);
fitted(forecast)
Then plug these values into the equation:
\begin{align}
\hat{VaR}_{0.99,T|T-1}&=\hat{\mu}_{T|T-1} + \hat{\sigma}_{T|T-1} * q_{0.99}
\end{align}
where $T$ is ...
3
You can also use the Sim.DiffProc package.
Have a look at this document:
Sim.DiffProc: A Package for Simulation of Diffusion Processes in R
See esp. chapter 2.1.2
There is even a Graphical User Interface (GUI) available for some functions:
http://cran.r-project.org/web/packages/Sim.DiffProcGUI/index.html
See chapter 4 in the above document for details.
3
Some of your question was already answered on the question you mention. Please read it carefully to understand better. In particular it answers very well how to conclude if there is co-integration or not. Also note that this question is not really relevant here both on level and subject (It is a pure statistical question and can be asked on ...
3
I think an extremely interesting strand of research on this topic is represented by extensions of vine copulas with time-varying parameters.
For vine copulas in general have a look at this site from the Technische Universität München:
Vine Copula Models
One of their research projects, which is the most relevant in this context, is:Time varying vine copula ...
3
You said:"I understand that the generated ticks will be generated using interpolation (so they won't be exacts)".
You are very optimistic, they will not only be far away from being exact, they (the tick data) will be completely removed from reality, the only parameters known for the tick data will be boundary conditions, such as open high low close. You ...
3
You can create the data using the procedure described in the reference manual on pages 31 and 32. The necessary code is copied below:
# The following code may be used to generate an empty data set,
# which can then be filled with bond data:
ISIN <- vector()
MATURITYDATE <- vector()
STARTDATE <- vector()
COUPONRATE <- vector()
PRICE <- ...
3
It only indicates that the null hypothesis of uncorrelated increments is violated.
For the sake of simplicity, assume a time series is stationary. Then a sufficient statistic for arbitrary variance ratios is its covariance function. In general, a given deviation from the null can originate from different covariance functions, which in turn, entails that ...
3
I don't know how to select ARMA lag length when doing ARMA-GARCH. Perhaps someone can edit it into this answer.
For the univariate case you want rugarch package. If you're doing multivariate stuff you want rmgarch. The reason these are better than other packages is threefold; (i) Support for exogenous variables which I haven't seen in any other package, ...
2
of course you can use this test to elaborate on this matter. Basically this test measures the ratio of variance of series in period tn to n*variance of t preriod
$\frac{Var(tn)}{nVar(t)}$
in short:
constant ratio for random walk
increasing for series with trend
decreasing for mean reverting process, more decreasing (faster) - better mean reversion
2
Have a look at the following two papers, one from Chris Rogers and Liang Zhang where they introduce a model using HMM which captures stylized facts of financial returns. And the second where we extended this model to risk measures.
Implementation in R is strait forward using ML as mentioned in the paper.
...
2
A great example of kalman filtering is in the Kyle Model. I have attached a presentation on the application of R to the kalman filter in the Kyle Model.
http://www.rinfinance.com/RinFinance2009/presentations/microstructure-tutorial.pdf
Basically in the Kyle Model, a market maker finds the likelihood an asset is ending up at a certain price given that a ...
2
I think there is no mistake on your part, if you set sigma <- 0.0045 and
x <- seq(100, 112, length=100) // Lower values produce jagged edges
y <- seq(0.25, 1.1, length=60)
you'll get this:
With these parameters the density has about the same peak and the maximum of the density function also has a similar direction. Alas, a number of things are ...
2
When I first looked at this problem in the year 1999 using Monte Carlo, I realized that MC simulation do not work for modeling market events, especially when withdrawals are present; well, for several reasons (see my articles for that at my website). Thus, I developed my aftcast model in 2001 while writing my book "High Expectations and False Dreams". After ...
2
The difference is real, though it is very small if your return on capital is small. Let's say value of your asset went up from 10.03 to 10.05:
Here is my python code:
>>> from math import log
>>> 10.05 / 10.03 - 1
0.001994017946161719
>>> log(10.05) - log(10.03)
0.001992032531240806
The ROC is small, and difference between two ...
2
Once we start building time-varying copulas like Lopes suggests in that paper, I think we are better off venturing into the world of state space models. When viewed in a bayesian context, the similarities between the approaches are striking to me. The advantage of the copula, as I understand it, is that it is a quick and dirty way to understand the ...
2
Is it worth it to learn R?
Switching from C/C++ to R has increased my productivity and shrunk code line-counts for similar tasks by roughly an order of magnitude. To give a small flavor of why, consider one of the most common patterns of iteration over some collection, selection and action:
declare iterator for collection
for element in collection
...
2
Let's approximate the time to maturity to be 3 years and 10 months. Assume that coupon is paid on March 6 each year. Let face value $F=100$ and coupon $c=0.07375F$. Let the discount factor be $d(0,T)=e^{−r T}$ where $r=0.06535$. The price of the bond is
$$ce^{−10/12 \bullet r}+ce^{−22/12 \bullet r}+ce^{−34/12 \bullet r}+(F+c)e^{−46/12 \bullet r}=103.24 \; ...
2
Assuming you already have a way to obtain hedge ratios and the like, your best available choice is probably blotter (used to be just quantstrat). You will find that it isn't necessarily oriented toward options.
Generally for options backtesting, pros end up making their own or buying commercial software. There are tons of commercial providers, but I ...
1
Now I have trouble interpreting the results of Q-Statistics? First of all to test the mean equation, we look at the standardized residuals. These standardized residuals should behave iid(0,1). Since the p-values is very small, we can conclude, that they are not independent, since there exist serial correlation. Is this right?
Yes, as you mention near ...
1
The standard answer to your question would be to do the maximum likelihood estimation. When you say "plug in $\sigma$" you can show that the sample estimate of $\sigma$ is actually the maximum likelihood estimate of $\sigma$ for the normal distribution.
If I can assume that your data are IID then what you do is use your distribution with parameters ...
Only top voted, non community-wiki answers of a minimum length are eligible



