Hot answers tagged

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


13

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


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


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


8

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 but 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): Earlier ...


5

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


4

For the tasks listed, both Python and R perform very well. There are some packages in Python not in R and vice 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 ...


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

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


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


4

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


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

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

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

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


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

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