# Tag Info

17

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

11

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

5

A website that replicates partially some quant papers is: http://www.volopta.com/

5

The risk-neutral probability density function $q(.)$ is indeed given by $$q(S_T=s) = \frac{1}{P(0,T)} \frac{ \partial^2 C }{\partial K^2} (K=s,T)$$ where $P(0,T)$ figures the relevant discount factor. This is known as the Breeden-Litzenberger identity. Because you do not observe a continuum of call prices in practice, you can use a finite difference ...

4

The price difference is so large -- that the only possible reason is that you have spot and strike confused between the two functions. And indeed: R> fOptions.BAW <- BAWAmericanApproxOption(TypeFlag, S, X, Time, + r, b, sigma, title = NULL, description = NULL) R> quantlib.BAW <- AmericanOption("call", X, S, b, r, Time, + ...

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

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

It is very hard to answer this quiz as people might be good at different at tools. For example, if you are good at VBA, then you can achieve the same effect compared to R in most cases. The following parts are the reasons why I prefer to R based on my own situation. 'package'. This is the most obvious strength of R over Excel in terms of convenience. You ...

4

To test for model misspeicfication: First ensure that auto correlation of standardized residuals resulted from the ARMA-GARCH model are not significant. Further, you can use Box-Ljung test. It test joint significance of auto correlation upto lag $K$. Leverage effect is tested by sign bias test. If $p$ value is less than .05 (assumed significance level) ...

4

The rsgt is a skewed generalized t distribution, whereas your picture is a skewed student-t distribution. Try using fGarch package. Plot reproduced: library(fGarch) x<-seq(-2.5, +2.5, by=0.001) plot(x, fGarch::dsstd(x, mean = 0, sd = 1, nu = 30, xi = 1 + 0.5), type = "l", ylim=c(0, 2.4), lty = 1, xlab="z", ...

3

First and foremost you are using bad data. min(data) gets me -3.67 (it's random remember) which would be -367% as in the position went bankrupt and took out two other ones (could be possible in a levered porftolio). However for the sake of an reproducible answer lets use the edhec data set, very little changes to your original code need to be done. ...

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

Try the following: library(quantmod) # also loads xts and TTR # Fetch all Symbols & store only the tickers to retrieve the data symbols <- stockSymbols() symbols <- symbols[,1] Next we will specify where to to store data dataset<- xts() # Only run once The following code is the loop that will download OHLC data to your environment. It ...

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.

3

This simply suggests the linear model is a poor fit in high frequency. But is this that surprising, even before you crunch the numbers? I argue not, for the following reasons: Even at low frequencies (i.e. monthly or annually), it is known that the classical CAPM (which is what you're running, albeit at a much higher frequency) does not fit well. It'd be ...

3

Some advantages of R over Excel: R is a scripting language, which allows to record a data manipulation script once and reuse it multiple times. R, as a [scripting] programming language is much more flexible than very limited Excel's GUI. In fact, R has become a de facto statistical programming environment, which delivers most recent statistical techniques. ...

3

You know that : $X \sim N(\mu,\sigma^2)$. $Z = \large\frac{X-\mu}{\sigma}$. $\text{Var}(Z) = \large\frac{1}{\sigma^2}\text{Var}(X) = \large\frac{1}{\sigma^2}\sigma^2 = 1$. So that $Z \sim N(0,1)$. However note that the pdf evaluated for X and Z have different domains. The following figure illustrate it : $X$ is plotted in a) and $Z$ in b) ...

3

$\alpha=0$ does not imply constant volatility. Consider just a simple Garch(1,1): $$\sigma^2_t = \omega + \alpha \eta_t^2 + \beta \sigma^2_{t-1}$$ Note that: $$\sigma^2_t = \omega + (\alpha + \beta) \eta_t^2 - \beta (\eta_t^2- \sigma^2_{t-1})$$ Now add $\eta_{t+1}^2$ to both sides: $$\eta_{t+1}^2 = \omega + (\alpha + \beta) \eta_t^2 - \beta ... 3 Well, it wasn't easy because you didn't mentioned how your data is formatted. I create my own data.frame() basing on data you provided. You can skip this part if your data.frame is ready. Here's code I used to create a dataframe: > #given dates > dates=c("2000-1-3","2000-1-4","2000-1-5","2000-1-6","2000-1-7","2000-1-10","2000-1-11") > #formating ... 3 There is one minor mistake: If you compute sum(mean.var) you'll obtain -1 instead of 1. So it should be mean.var<-xt/sum(xt) in order to ensure that the weights sum up to one. The remainder is correct. Incorporating a risk aversion parameter into the framework requires the solution to the minVar problem (See for example here). Therefore, dividing ... 3 1) You are computing the "actual" VaR, in the sense that you are not forecasting it to see if your VaR model is able to estimate it, but you are just computing the VaR that "has taken place". To obtain a volatility forecast (either in-sample or out-of-sample) you can use the "ugarchforecast" function. 2) I think you are estimating the VaR on the wrong side ... 2 The standardized error in a GARCH model has unit variance (which is needed for identification) and a zero mean. Whatever the conditional distribution, it is scaled and shifted so as to fit those requirements. The answers to your questions are: No. No, they don't drop the assumption of mean zero and variance one; and Yes, they are using something like a ... 2 What are the limitations of R? The limitations of the R kernel are well-documented in Sridharan and Patel (2014): Spends more than 85% time in processor and memory stalls High rate of cache misses (about 90% on linear regression and k-means tasks) Triggers garbage collection very frequently Creates a large number of unnecessary temporary objects, ... 2 The major advantage of Python (w/ pandas) over R is that Python supports OOP (object-oriented programming). It makes sense to organize a large code base using a hierarchy of classes. Python also supports the notion of polymorphism so that we can use well-known design patterns (e.g., Strategy, Observer, etc.) in our code. 2 For non-normal asset price models you could look at the theory of Lévy-processes. If we assume that you work in the physical probability measure P and that the random numbers that you have generated are daily log-returns, then you can do the following: Asset i has starting price S_0^i and for the future prices you can put$$ S_t^i = S_0^i ...

2

Most technical indicators must be available in the TTR package. However, if they are not then you can write a custom indicator for use in quantstrat as follows. fractalindicator.up <- function(x) { High <- Hi(x); Bars <- nrow(x) afFrUp <- rep(NA, Bars) for(iBar in seq(8,Bars-2)) { if(High[iBar-1]<High[iBar-2] && ...

2

The calculation of rebalanced portfolio returns using PerformanceAnalytics functions makes use of what the package authors call "end-of-period" weights. As described in the documentation for Return.portfolio, the rebalancing uses the weights for the last trading day of the period to rebalance the portfolio after the markets close on that day. As an ...

2

When position = 1, then you are long the S&P ETF. When position is -1, your portfolio consist of a short position of -1 S&P ETF. You will therefore have a vector like $Pos = (1,1,1,1,1,-1,-1,-1,-1,1,1,1,-1,-1,-1, \ldots)$, that will give you the evolution of your portfolio. Your returns are then the daily returns on the S&P multiplied by your ...

2

A high R-squared (1.0) means that you can explain the movements of one time series using the other. The lower your R-squared is, the worse your explanation is -- that includes the 'quality' of your beta. You can try to improve your R-squared score using different regression types. Beware of overfitting.

2

It is all in the code:: Rcpp::List rl = Rcpp::List::create(Rcpp::Named("value") = opt.NPV(), Rcpp::Named("delta") = opt.delta(), Rcpp::Named("gamma") = opt.gamma(), Rcpp::Named("vega") = (excType=="european") ? opt.vega() : R_NaN, ...

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