# Tag Info

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

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

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

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

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

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

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

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 be reached from any of the above links Some features: Can run in (pseudo)event-mode (called 'next') or (pseudo)vectorized mode (called ...

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

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

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 down to mapping of orders. On the project page you can see a list of other similar (some more, some less) python projects and may prove to ...

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

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

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)

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

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

1

When doing series like this in Python, I usually just add 1 to each return, then multiply across these sums for cumulative returns. Such as, if my returns over three days were -5.2%, 2.1% & 4.8%, then the values I would store would be: 1 + (-0.052) = 0.948 1 + (0.021) = 1.021 1 + (0.048) = 1.048 Then, to calculate my cumulative returns, I ...

1

highOutput = [] lowOutput = [] lsth = [None]*window lstl = [None]*window for i in range(0, len(highValue)): maxValue=0 lsth.append(highValue[i]) lsth = lsth[-window:] for j in range(0, len(lsth)): if lsth[j] > maxValue: maxValue = lsth[j] highOutput.append(maxValue) for i in range(0, len(lowValue)): ...

1

Native support is very limited. TradeStation's WebAPI pretty much works with any language because it is wrapped in HTTP calls using RESTful. If a platform has an API that supports std C/C++ interfaces, you can write a wrapper to extend the API to python. Search for "Calling C from Python". It is more work to code, but otherwise your choices are very ...

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