Hot answers tagged

12

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

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.


4

This does the trick. Given "U8", function will get the IMM date for Sep 2018. Given "U4", function gets the IMM date for Sep 2024 (or it will until we've passed that date). Could be easily modified to also pull historical IMMs from a given longer symbol eg. "U2014". def getIMMDate(IMMcode): '''Takes 2 digit IMM code and returns effective date as datetime ...


4

The installation process should be the same as on Linux. Once you have the C++ QuantLib library installed (instructions for that are on the QuantLib site, at http://quantlib.org/install/macosx.shtml) you can download the latest QuantLib-SWIG release, uncompress it and run: ./configure make -C Python sudo make -C Python install Note that the above work ...


4

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


3

Remember that all back testing is full of lies assumptions. Latency (both line latency and latency internal to the exchanges), adverse selection, market impact (yes, even you have market impact), etc, are all based on assumptions. These assumptions are educated guesses at best, but more often terrible models are used (you always get filled at at mid!) and ...


3

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


3

They expire 30 days before the expiration of the S&P monthly options. The latter usually expire on the third Friday of the month (however, in rare cases the S&P opts. expire on Thursday because the Friday is a holiday; the last time it happened was April 17, 2014 since April 18 2014 was a NYSE holiday). Neglecting the holiday thing, the expiration ...


3

What you need is more mutual information rather than Shannon entropy. It is dedicated to capture the influence of one variable on another (you can think about it as a non linear version of Pearson correlations). They are closely related since the mutual information $I$ between two variables $X$ and $Y$ reads: $$I(X;Y) = H(X,Y) - H(X|Y) - H(Y|X)$$ where $H$ ...


3

Edit (2016-06-21): Now with live data/trading integration with Interactive Brokers. It has taken a while but it has finally arrived. A (now) very mature (imho) Python backtesting framework is "backtrader": https://github.com/mementum/backtrader Blog posts with samples and new developments: http://www.backtrader.com The documentation on readthedocs can ...


3

I think the most sophisticated solutions are to be found within the R universe. One package that comes to mind is the quantmod package. You can use it to download data from Yahoo and Google finance, plot charts and filter your stocks using all kinds of technical indicators (that come with the package). It can be found on CRAN: https://cran.r-project.org/...


3

IBPy + IB Gateway + TWS and you can send order to any interactive brokers, how to setup


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

I calculate duration in Python using numpy, it's nice and simple: def durations(cfs, rates, price, ytm, no_coupons): import numpy as np mac_dur = np.sum([cfs[i]*i/np.power(1+rates[i],i) for i in range(len(cfs))])/price mod_dur = mac_dur/(1+ytm/no_coupons) return mac_dur, mod_dur


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, Rcpp::Named("...


2

PYTHON I have found this class from the statsmodels library for calculating Garch models. Unfortunately, I have not seen MGARCH class/library. Below you can see the basic information about the garch models in mentioned class from the statsmodels. Probably you have to implement it by your own in python, so this class might be used as a starting point. ...


2

The code below pulls AAPL time series from Yahoo Finance, computes mean/std and simulates 100 paths that are 20 days long. Input: import pandas as pd import numpy as np from numpy.random import normal # bring data ticker = 'AAPL' url = 'http://real-chart.finance.yahoo.com/table.csv?s=%s' % ticker data = pd.read_csv(url, index_col='Date', parse_dates=True) ...


2

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)


2

There is a times series DBMS (InfiniFlux) that can be easily used with Python. The database is not open source but it does provide a free version for evaluation, too. So you can try whether the DBMS is suitable for your project. You are asking 2M rows should be processed in less than 30 seconds, InfiniFlux can store and retrieve more than 500,000 data ...


2

Because your python script ends and with it the socket that ibpy has opened to connect to TWS. The demo samples in the sources of ibpy use simple time.sleep(x) to make sure some information has been delivered (for example fancy_marketdata.py) before the script ends. Try to remove the time.sleep(x) lines and see how the script also ends instantly. Have a ...


2

Edit (2016-06-21): Now with live data/trading integration with Interactive Brokers. It has taken a while but it has finally arrived. backtrader (https://github.com/mementum/backtrader) can do 1 and 3 and is in the process of getting 2 ironed out. A live data feed from IB will make it into the next release (due in the next few days) and it will then be ...


2

For ARIMA(2,1,4) you would need to use the ARIMA model, as described here. You would call with something like this ARIMA(endog, order = (2, 1, 4)) where endog is your endogenous variable and the tuple given for order follows the convention AR, Differencing, MA. For ARMA(1, 1) you could just use ARMA(endog, order = (1, 1)).


1

Look at matplotlib.finance It downloads data from yahoo finance as well but it is much quicker than the package that you are mentioning. Regarding the reliability, I think that the data source is quite reliable.


1

The average would be called the mid-price, not the best in my opinion, but that depends on your modeling. Another strategy is to weight the bid and offer prices according to size, also called the micro-price or bid-offer weighted price. This has the advantage of moving your calculated price closer to where it is traded as volume is depleted from whatever ...


1

Probably the easiest way to get it is through MacPorts, which will take care of the Python dependencies, et cetera, for you. If you have not already done so, you can get started with MacPorts using these instructions. After MacPorts is installed, you can simply invoke sudo port install QuantLib which pretty much just follows the official recommendations ...


1

Metastock uses a binary format that you would have to convert to text before exporting it to a SQL table. Also, there is no Python library that could extract data directly from Metastock's end-of-day servers. You may consider quandl which allows Python developers to download pricing data as well as economic indicators. You can download CSV, JSON, or XML. If ...


1

As soon as you're comfortable with Python, let's do this exercise in three steps: Download data and calculate cumulative returns (or value of your position as if you invested $1 in each of the stocks) Define function that will capture stock movements in excess of predefined threshold, 10% in this case. This function is going to be the "indicator" you ...


1

Convex Optimisation - CVXOpt and CVXPy. Textbook by Boyd & Vandenberghe Aside from CVXOPT (known for its cone programming, see http://cvxopt.org/) with extensive documentation by the authors, Boyd and Vandenberghe http://stanford.edu/~boyd/cvxbook/, there is CVXPY which provides an easier front end. CVXPY was designed and implemented by Steven Diamond,...


1

I'm guessing your best bet would be to get setup with an SFTP account with Bloomberg. Just contact your rep to get the ball rolling. We upload 10's of protfolio's 10's of times a day. I don't think there is an actual api for pulling data from PRTU as I'm not sure exaclty what you'd pull other than the last upload time.


1

In Python, simple geometric returns: import numpy as np import pandas as pd sp500 = pd.io.data.DataReader('^GSPC', 'yahoo')['Close'] simple_ret = sp500.pct_change() (1+simple_ret).cumprod()[-1] -1 0.74751768460019963 Log-returns: log_ret = np.log(1+simple_ret) np.exp(log_ret.cumsum()[-1]) -1 0.74751768460020074 In ...



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