Hot answers tagged

40

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


27

Aside from Zipline, there are a number of algorithmic trading libraries in various stages of development for Python. From the commercial side, RapidQuant looks very interesting though I haven't tried it yet. It's from some of same developers that brought us the excellent Pandas data analysis library. I think Wes McKinney (Pandas's main author) is involved....


24

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


21

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


21

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


15

Edit (2016-06-21): Now with live data/trading integration with Interactive Brokers. It has taken a while but it has finally arrived. Edit (2017-09-20): live data/trading includes Visual Chart and Oanda (legacy accounts), order types, timers and market calendars, update with Python 3.6 and the community and other links updated A (now) very mature (imho) ...


14

I don't know why it was removed, but the R package "orderbook" was available: http://journal.r-project.org/archive/2011-1/RJournal_2011-1_Kane~et~al.pdf http://cran.r-project.org/web/packages/orderbook/index.html In the IBrokers package, the function "reqMktDepth" is used for streaming order book data. http://cran.r-project.org/web/packages/IBrokers/...


14

I took a quick look at Matlab's Financial Toolbox and attempted to map the features to corresponding Python packages – For asset allocation, portfolio optimization, and risk analytics: Standard packages such as scipy provide a large number of optimizers that should suit your needs. There are also pre-canned packages that do portfolio optimizations more ...


13

In Pandas 0.19.2++: def Bolinger_Bands(stock_price, window_size, num_of_std): rolling_mean = stock_price.rolling(window=window_size).mean() rolling_std = stock_price.rolling(window=window_size).std() upper_band = rolling_mean + (rolling_std*num_of_std) lower_band = rolling_mean - (rolling_std*num_of_std) return rolling_mean, ...


12

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


11

You can get this using a pandas rolling_max to find the past maximum in a window to calculate the current day's drawdown, then use a rolling_min to determine the maximum drawdown that has been experienced. Lets say we wanted the moving 1-year (252 trading day) maximum drawdown experienced by a particular symbol. The following should do the trick: import ...


11

I have started to do the same thing a few months ago. You can test your strategies pretty much in any platform: I have tried: backtrader - www.backtrader.com - python based, open source, with great documentation and community support, helpful author and some great features. If you have basic python then thiswould be my recommendation. ninjatrader - free ...


11

I found out what I was doing wrong - the OLS function was regressing with no intercept value - so I had to use the "add_constant" method to add an intercept term to the X series (z_lag) as follows: z_lag = np.roll(z_array,1) z_lag[0] = 0 z_ret = z_array - z_lag z_ret[0] = 0 #adds intercept terms to X variable for regression z_lag2 = sm.add_constant(z_lag) ...


10

def bbands(price, length=30, numsd=2): """ returns average, upper band, and lower band""" ave = pd.stats.moments.rolling_mean(price,length) sd = pd.stats.moments.rolling_std(price,length) upband = ave + (sd*numsd) dnband = ave - (sd*numsd) return np.round(ave,3), np.round(upband,3), np.round(dnband,3) sp['ave'], sp['upper'], sp['...


10

At this time, there's no specific documentation for QuantLib-Python, except for a series of screencasts that I started a while ago (you can find them on YouTube at https://www.youtube.com/playlist?list=PLu_PrO8j6XAvOAlZND9WUPwTHY_GYhJVr) but which is far from exhaustive; there's just a few of them for now, and there's no definite learning path. However, the ...


9

It doesn't matter if you use *100 or just pct_change, as long as you are consistent. However, in practice, due to underlying floating point numerical instabilities in the underlying optimization algorithms/default tolerances used in scipy/arch, having the returns expressed in %, i.e. multiplied by 100, will have a better chance of converging during the ...


9

QuantConnect has had users work on contributing REST bitcoin brokerages - its fully open source and has complete modeling support for currencies. It also has python support in beta. https://www.quantconnect.com/forum/discussion/958/bitfinex-brokerage (I'm the founder of QuantConnect) Edit: Fully support python and cryptocurrencies now. We've pushed GDAX ...


8

So one such visualization package is demonstrated in http://www.tradeworx.com/movie/booklet_demo/temp/booklet_demo2.mov. AFAICT it looks like a tk script. Trading Technologies (TT) sells another visualization tool. But TBH writing your own tool takes a few hours and allows you to focus on what information you are interested in finding.


8

Firstly, you'll probably be directed to consider Zipline. It's worth a look but I don't think that it's a good starting point, since: Quantopian's developers don't have a financial background and it shows through in the Zipline source code. Zipline is dreadfully slow if you compare it to any commercial platform with backtesting functionality in a compiled ...


8

OpenTSDB is good for large-scale time series storage. metrilyx/opentsdb-pandas and wiktorski/opentsdb_pandas seems to provide the interface with pandas. OpenTSDB and HBase rough performance test | MoreDevs provides a benchmark, may not exactly match your requirements but you can try.


8

No, I'm afraid you're comparing apples with oranges. Your calculation of the DV01 of the swap is correct (with a caveat, see below), but the figure returned from swap.fixedLegBPS is not comparable. The DV01 tells you what happens to the NPV if the interest-rate curve change; in the case of the fixed leg, this affects the discount factors used to discount ...


8

You seem to have two distinct problems: How to generate random portfolios How optimal portfolios are structured Ad 1) A straightforward way to simulate the weights of random portfolios is to use the Dirichlet distribution $Dir(\alpha_1,\ldots,\alpha_n)$. This is a distribution on the Simplex (i.e. on $S=\{x\in\mathbb{R}^n | \sum x_i =1, x_i\geq 0\}$, ...


7

Check out my ccxt library on GitHub: https://github.com/ccxt/ccxt With it you can access market data and trade bitcoin and altcoins with many cryptocurrency exchanges. The library is in Python 2 & 3 (JavaScript and PHP versions are also available as well). You can deploy it from PyPI, with npm or by cloning from GitHub repository. The ccxt library is ...


7

In the call to Bisection.solve, the question mark must be the Python function whose zero you want to find. In your case, it should be something reproducing the logic of IRRSolver::operator() in Mick Hittesdorf's code, i.e., something like this (which I haven't tested): cashflows = fixedRateBond.cashflows() npv = fixedRateBond.NPV() def ...


7

I reproduce the Ametrano-Bianchetti paper on dual-curve bootstrapping in Python with QuantLib in a chapter of the QuantLib Python Cookbook. (Note: I'm not sure what the etiquette is about plugging one's own for-sale book. Moderators, please let me know if that's out of line.) That includes both OIS and LIBOR bootstrapping with different tenors, and it's ...


6

possible update: http://pmorissette.github.io/bt/ based on http://pmorissette.github.io/ffn/ both were easily installed and somewhat usable for a novice. would love some examples other that github documentatiion


6

I guess what they are trying to say here is that, assume you have two time series $X$ and $Y$ which are exactly the same i.e. $X=Y$, the correlation is : $$\rho_{X,Y}= \frac{Cov(X,Y)}{\sigma_X \sigma_Y}\overset{X=Y}{=}\frac{Cov(X,X)}{\sigma_X \sigma_X}=\frac{\sigma_X^2}{\sigma_X^2}=1$$ Now assume a time series $Z=2 \cdot X$, you have: $$\sigma_Z=2 \...


6

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


6

Also in the high frequency / medium frequency field here. I received a "mixed" consensus regarding the use of R and its prevalence in the field (specifically HFT). Speaking with someone who works in the equity option industry at a relatively small proprietary firm in San Francisco, I was told, "R is a legacy language". However, speaking with someone who ...


6

You will find a tutorial of QuantLib using python with simple examples here: http://gouthamanbalaraman.com/blog/quantlib-python-tutorials-with-examples.html I have been writing these as a means to be instructive to others going through the process of learning and working with QuantLib. If you have suggestions on what topics you would like to read, please ...


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