Richardlogan3s blog

Richardlogan3s blog07/06/2012

Download python trading strategies

Filename: python trading strategies

Date added: 14.04.2012

Type of compression: zip

Author: quikomi

File checked: Kaspersky

Download speed: 19 Mb/s

date: 15.05.2012

Author: corrlowin

python trading strategies

Python Developer – Algo Trading Systems - Sydney ( Speedy_Snake_AB ) Location. locations globally and a reputation for creating robust trading strategies.

Python Developer - Algo Trading Systems - Sydney, Australia-Sydney

Are you a Python Guru with experience in Numpy and Scipy and a strong. in multiple locations globally and a reputation for creating robust trading strategies sat.

Python Developer – Algo Trading Systems - Sydney

ultra-finance - Python project for real-time financial data.

functionality to python using SWIG, then build a GUI to connect, load strategies(python. Trading Software Provider AMP Global Clearing Futures and FX Trading

Python and its extensions are open source and so allow you to see under the hood. Trading Strategies and Portfolio Constructions based on Cross Sectional Regression?

Python trading app. Works with Interactive Broker. Risk Quantify. Develop and test your trading systems, and explore strategies contributed by other members.

Amazon: High-Frequency Trading: A Practical Guide to.

Forums - Building an automated trading system in Python

be based around my loess filter algorithm, which is implemented in the Python. is a free platform that allows automated execution of predefined trading strategies.

Switching from Matlab to Python for Quant Trading and Research.

Building Your Own Trading System - Part 5 | Stock Trading: Futures.

Python project for real-time financial data collection, analyzing backtesting trading strategies. Welcome Ultra-finance is a pure Python library utility for real.

TA-Lib: Technical Analysis Library - Documentation

Amazon: High-Frequency Trading: A Practical Guide to Algorithmic Strategies and Trading Systems (Wiley Trading) (9781118343500): Irene Aldridge: Books

python trading strategies Amazon: High-Frequency Trading: A Practical Guide to.

Trading strategy developer(java,c,python,mathematics,com in codublin,ireland

Trading strategy developer(java,c,python,mathematics,com in codublin,irelandTrading Strategy Developer (Java, C++, Python, Mathematics, Com in Co. Dublin, Ireland

Get email alerts for Trading Strategy Developer (Java, C++, Python, Mat. jobs near Co. Dublin, Ireland . ×

You can opt out at any time so you don't need to worry about being spammed.

Trading Strategy Developer (Java, C++, Python, Mathematics, Computer Science)

Financial Market Maker. Dublin

€65,000 - €95,000 + Bonus + Excellent Benefits

A leading global market maker is seeking an exceptional Trading Strategy Developer (Java, C++, Python, Mathematics, Computer Science) to join their Dublin based trading team.

The incredible success of this firm is down to the fact that they focus on every aspect of the life cycle of a trade, from knowledge of the market structure to world class post trade processing. At the core of the business is the development of innovative, proprietary technology, designed to automate market making and post-trade activities.

The Trading Strategy Developer (Java, C++, Python, Mathematics, Computer Science) will be working closely with the traders to design and develop the trading algorithms. You will need to be an extremely capable software developer and technologist who has a natural ability to understand the markets.

To be considered for the Trading Strategy Developer (Java, C++, Python, Mathematics, Computer Science) role, you should have the following skills:

Excellent Java or C++ knowledge (Required)

Strong scientific or mathematical education (Required)

Experience of financial markets (Not required)

This is an incredible opportunity for a Trading Strategy Developer (Java, C++, Python, Mathematics, Computer Science) to join a truly global leader in financial technology. You will be working with some of the brightest and best in the industry and be incredibly well rewarded for your work.

Please get in touch with Ian Bailey at Harrington Starr for more information.

Trading Strategy Developer (Java, C++, Python, Mathematics, Computer Science)

Financial Market Maker. Dublin

Quantum blog

Quantum blogMonday, February 4, 2013

Trading With Python online course starting in April

A couple of observant readers already figured out that in spite of the url of this blog, past posts have been based on Python code. The gradual transfer of all of my research code from Matlab to Python is now complete. After working with Python for more than two years, I can state that it an excellent tool for research and data crunching. When it comes to collecting data from the web, cleaning and aligning datasets with missing data or building GUIs, it is the best tool I have ever come across. And don't forget that Python is open source and free.

Tuesday, January 1, 2013

Intraday mean reversion

In my previous post I came to a conclusion that close-to-close pairs trading is not as profitable today as it used to be before 2010. A reader pointed out that it could be that mean-reverting nature of spreads just shifted towards shorter timescales. I happen to share the same idea, so I decided to test this hypothesis.

This time only one pair is tested: 100$ SPY vs -80$ IWM. Backtest is performed on 30-second bar data from 11.2011 to 12.2012.

The rules are simple and similar to strategy I tested in the last post:

if bar return of the pair exceeds 1 on z-score, trade the next bar .

The result looks very pretty:

Algo trading with python

Algo trading with pythonAlgo Trading with python

One of the practical goals in my education plan is:

Develop programming skills that will aid in my trading

I believe trading to be more art then science. Still back testing rule based strategies is necessary, but it is a lot of work if you do this manually. And that's where programming comes in handy. Also monitoring markets and signal creation is something that I would want to automate.

So last Friday I registered for Jev Kuznetsov's Trading with python course. I have been keeping an eye on Jev's blog for some time know, as he seems to be doing exactly what I intend to be doing. And that is: back testing trading strategies algorithmically using python. Be sure to check out his blog if you are interested. You can register for his course here. In below video Jev explains what the course is about.

In the course Jev will be using a book that was already on my wish list:

So I have gone ahead and bought the ebook version of the book. Googling for the author Wes McKinney, I came across this blog post:

And from there I found out about Quantopian. a community driven online algorithmic trading platform. Check out below video to learn more.

Quantopian uses the Zipline python library for back testing. The library is available from github: github/quantopian/zipline

I installed zipline and made an account on Quantopian. So now I can start playing around with some algos on my machine and in the browser. Quantiopian seems to be a great place for quickly testing new ideas and for practicing. In the future they will also be offering the ability to paper trade and to trade live on selected brokers right from their platform.

Then finally I watched this presentation: Intro to algorithmic trading models by Prof. Ahmed Namini. Below video and slides go hand in hand. I embedded them both below so it is easy to watch the presentation.

If you found this post helpful, please be sure to share.

Related articles

Vectorized vs event driven backtesting

Vectorized vs event driven backtestingVectorized vs Event Driven Backtesting

Vectorized vs Event Driven Backtesting

One is vectorized, one is event driven Obviously?

I am not sure there is a question of realism here - it is quote directly about technological approaches only. Not everything has a clear better/worse.

Realism is not about what fundamental programming approach you take, but how good you program (saying as someone just rewriting his exchange simulator into I think version 6 no to handle some issues I have with timing).

Thank you for your answer.

The following quotation is from quantsart blog:

We've spent the last couple of months on QuantStart backtesting various trading strategies utilising Python and pandas (pandas. pydata/ ). The vectorised nature of pandas ensures that certain operations on large datasets are extremely rapid. However the forms of vectorised backtester that we have studied to date suffer from some drawbacks in the way that trade execution is simulated. In this series of articles we are going to discuss a more realistic approach to historical strategy simulation by constructing an event-driven backtesting environment using Python .

The reason I was asking the differences between them was that I do not know R, MATLAB or Python. I wanted to start learning the most realistic one.

So what you are saying is, if I do the coding with slippage, commissions and other cost included, the realism will be the same in R or MATLAB or Python. Or did I misunderstand you?

Quantitative finance e-books

Quantitative finance e-booksQUANTITATIVE FINANCE E-BOOKS

ADVANCED ALGORITHMIC TRADING

Machine Learning Applied To Real World Quant Strategies

In Advanced Algorithmic Trading you'll learn to implement advanced trading strategies using time series analysis, machine learning and Bayesian statistics with R and Python.

You'll take a detailed look at some of the most popular quant finance libraries for both Python and R, including pandas, scikit-learn, statsmodels, timeseries, rugarch and forecast.

The full package comes with all the necessary Python and R code you need to start applying more advanced trading models and risk management techniques to your portfolio.

SUCCESSFUL ALGORITHMIC TRADING

Struggling To Make Profitable Algo Trading Strategies?

In Successful Algorithmic Trading you'll learn how to find new trading strategy ideas and objectively assess them for your portfolio.

The full package comes with all the necessary Python code you need to get started immediately on your algorithmic trading strategies.

C++ FOR QUANTITATIVE FINANCE

Are C++ Questions Stopping You From Getting The Job?

What if there was a way to learn precisely what you needed without having to spend huge sums on C++ textbooks and weeks of study that didn't help in interview?

Contains over 250 pages of C++ design patterns for quant finance, including industry-grade techniques that will boost your interviews.

Pythoneye develop python more brightly

Pythoneye develop python more brightlyScripting language for trading strategy development

I'm currently working on a component of a trading product that will allow a quant or strategy developer to write their own custom strategies. I obviously can't have them write these strategies in natively compiled languages (or even a language that compiles to a bytecode to run on a vm) since their dev/test cycles have to be on the order of minutes.

Best Answer

Mark-Jason Dominus, the author of Perl's Text::Template module, has some insights that might be relevant:

When people make a template module like this one, they almost always start by inventing a special syntax for substitutions. For example, they build it so that a string like %%VAR%% is replaced with the value of $VAR. Then they realize the need extra formatting, so they put in some special syntax for formatting. Then they need a loop, so they invent a loop syntax. Pretty soon they have a new little template language.

This approach has two problems: First, their little language is crippled. If you need to do something the author hasn't thought of, you lose. Second: Who wants to learn another language?

If you write your own mini-language, you could end up in the same predicament -- maintaining a grammar and a parser for a tool that's crippled by design.

If a real programming language seems a bit too low-level, the solution may not be to abandon the language but instead to provide your end users with higher-level utility functions, so that they can operate with familiar concepts without getting bogged down in the weeds of the underlying language.

That allows beginning users to operate at a high level; however, you and any end users with a knack for it -- your super-users -- can still leverage the full power of Ruby or Python or whatever.

Trading algo using python for interactive broker tws

Trading algo using python for interactive broker twsTRADING ALGO USING PYTHON FOR INTERACTIVE BROKER TWS

Всего заявок

Описание проекта

We'd need some help in writing in Python a simple Forex/Futures trading strategy (which is simple and already well defined) so that the IB API of Interactive Brokers could automatically send to market buy and sell orders on various currency pairs following a basic set of trading rules to be written as mentioned on Python.

This algorithm takes about 5-6 key inputs, including futures tickers, number of seconds to track (S), number of std dev to trigger or stop a trade, position size (ideally, should have the last inputs as default)

- Needs to connect to an Interactive Brokers (IB) account through API (can use IB Gateway or IB TWS)

- starts tracking real-time data for the futures when turned on or at assume 8am NY time and downloads prices real time keeping track of the few data points,

- next step is to compute moving averages over different horizons (1 week, 1 month, 100day, 200day, 12mth etc) using the 4pm closing data points

- every second it will make a couple of calculations using the MAs or the last few days's pricings on the two pricing arrays including simple math and standard deviations and with the most current data point, a simple calculation will trigger a Short/Long trade

- when there is a Short/Long new position triggered, it needs to place that order for IB to execute immediately. There should be a switch using which user can decide if trades are meant to be automatically executed or just sent as limit orders.

- Strong checks need to be built to ensure in case of software or market data errors multiple orders are not sent causing unwanted trades

- once trades are done there should be a mechanism to track the trade wise PL and portfolio PL for a take profit or stop loss level

Хотите заработать немного денег?

Укажите свой бюджет и срок

Опишите свое предложение

Получите оплату за свою работу

Python backtesting libraries for quant trading strategies

Python backtesting libraries for quant trading strategiesPython Backtesting Libraries For Quant Trading Strategies

( 3 votes, average: 5.00 out of 5)

Written by Khang Nguyen Vo, khangvo88gmail. for the RobustTechHouse blog. Khang is a graduate from the Masters of Quantitative and Computational Finance Program, John Von Neumann Institute 2014. He is passionate about research in machine learning, predictive modeling and backtesting of trading strategies.

Frequently Mentioned Python Backtesting Libraries

It is essential to backtest quant trading strategies before trading them with real money. Here, we review frequently used Python backtesting libraries. We examine them in terms of flexibility (can be used for backtesting, paper-trading as well as live-trading), ease of use (good documentation, good structure) and scalability (speed, simplicity, and compatibility with other libraries).

Zipline . This is an event-driven backtesting framework used by Quantopian.

Zipline has a great community, good documentation, great support for Interactive Broker (IB) and Pandas integration. The syntax is clear and easy to learn.

It has a lot of examples. If your main goal for trading is US equity, then this framework might be the best candidate. Quantopian allows one to backtest, share, and discuss trading strategies in its community.

However, in our experiment, Zipline is extremely slow. This is the biggest disadvantage of this library. Quantopian has some work-around such as running the Zipline library in parallel in the cloud. You can take a look at this post if this interests you.

Zipline also seems to work poorly with local file and non-US data.

It is difficult to use this framework for different financial asset classes.

PyAlgoTrade . This is another event-driven library which is active and supports backtesting, paper-trading and live-trading. It is well-documented and also supports TA-Lib integration (Technical Analysis library). It outperforms Zipline in terms of speed and flexibility. However, one big drawback of PyAlgoTrade is that it does not support Pandas-object and Pandas modules.

pybacktest . Vectorized backtesting framework in Python that is very simple and light-weight. This project seemed to be revived again recently on May 21 st ,2015.

TradingWithPython . Jev Kuznetsov extended the pybacktest library and build his own backtester. This library seems to updated recently in Feb 2015. However, the documentation and course for this library costs $395.

Some other projects: ultra-finance

Python Backtesting Libraries For Quant Trading Strategies

Welcome, Guest!

This forum was established to help traders (especially futures traders) by openly sharing indicators, strategies, methods, trading journals and discussing the psychology of trading.

We are fundamentally different than most other trading forums:

You'll need to register in order to view the content of the threads and start contributing to our community. It's free and simple, and we will never resell your private information.

Python backtesting framework

Python backtesting frameworkPython Backtesting framework

CHARITY DRIVE - NOW THROUGH NOVEMBER 15

ELITE MEMBERSHIP FEES WILL BE DONATED TO CHARITY:

FREEDOM SERVICE DOGS OF AMERICA

Freedom Service Dogs is a nonprofit organization that enhances the lives of people with disabilities

by rescuing dogs and custom training them for individual client needs. Clients include children,

veterans and active duty military, and other adults. Their disabilities include Autism, Traumatic Brain Injury,

Cerebral Palsy, Spinal Cord Injuries, Muscular Dystrophy, Multiple Sclerosis, and Post Traumatic Stress Disorder (PTSD).

Python Backtesting framework

CHARITY DRIVE - NOW THROUGH NOVEMBER 15

ELITE MEMBERSHIP FEES WILL BE DONATED TO CHARITY:

FREEDOM SERVICE DOGS OF AMERICA

Freedom Service Dogs is a nonprofit organization that enhances the lives of people with disabilities

by rescuing dogs and custom training them for individual client needs. Clients include children,

veterans and active duty military, and other adults. Their disabilities include Autism, Traumatic Brain Injury,

Cerebral Palsy, Spinal Cord Injuries, Muscular Dystrophy, Multiple Sclerosis, and Post Traumatic Stress Disorder (PTSD).

Python Backtesting framework

CHARITY DRIVE - NOW THROUGH NOVEMBER 15

ELITE MEMBERSHIP FEES WILL BE DONATED TO CHARITY:

FREEDOM SERVICE DOGS OF AMERICA

Freedom Service Dogs is a nonprofit organization that enhances the lives of people with disabilities

by rescuing dogs and custom training them for individual client needs. Clients include children,

veterans and active duty military, and other adults. Their disabilities include Autism, Traumatic Brain Injury,

Cerebral Palsy, Spinal Cord Injuries, Muscular Dystrophy, Multiple Sclerosis, and Post Traumatic Stress Disorder (PTSD).

Algo trading backtesting

Algo trading backtestingAlgo Trading BackTesting /Optimization Report (MT4, Python, MatLab)

Needs to hire 2 Freelancers

I am looking for Back Testing and Optimization of an algorithmic Forex trending trading strategy. It was developed and programmed in MT4. I am wanting to know and perfect the strategy against:

7 Year Back Test for Base Pairs: EURUSD, AUDCAD, GPBCAD, GBPCHF

Optimizations best profitable set of parameters unique to each pair

Trading Strategy Benchmark Comparisons

We need the code converted and run through python/Matlab/or C++ for analysis and optimization and the production ready version converted back to MT4 for trading.

A Walk Forward Analysis of the algorithm is preferred

*JOB will be set at a fixed cost for the report(s) and optimization. With opportunity to use your services long term as other instruments and strategies are added bi-monthly. ****Please submit your fixed cost $$$ bid for this project for consideration.

1. Please provide your approach to meeting the goal of this project

2. Please provide some similar or exact work you have done in this field (portfolio).

Trading strategy in python

Trading strategy in pythonHow to Backtest a Strategy in Python

I need to be able to determine whether a particular "trade" (indicated by "signal") resulted in a profit or loss by indicating a win or loss for each.

I need Python to check the next location ( the signal or entry point or date + 1 ) in the High and Low lists ( the lists: close . highs . and lows will have the same number of values ) for an increase in value equal to or greater than 2.5% at some point beyond the entry signal.

However, I also want Python to determine if the value drops 3% or more prior to appreciating 2.5% or more.

This must occur for each entry in signal .

In essence, I need a limit to sell at 102.5% and a stop at 97%.

Unfortunately, the code I developed so far doesn't seem to be working.

What am I missing?

A VIX ETP Strategy from Trading with Python

This is a follow up to a strategy from the excellent blog Trading with Python (TWP). The strategy uses the relationship between the VIX and VXV indices to trade VIX ETPs like XIV.

It is similar to this previous test from our blog, but rather that just directly comparing VXV to VIX, it compares VXV to the expected value of VXV based on a quadratic regression of the two indices.

Strategy results trading XIV (inverse volatility) are in blue, compared to buying and holding XIV in grey, from mid-2004 to present:

A modified version of TWP’s rules:

Near the close, perform a quadratic regression, approximating VXV = f(VIX) . Then calculate delta . or the deviation from our regression, as delta = VXV – f(VIX) . Note: I’ve assumed that each day we could only use the data available at that moment in time.

Go long XIV at the close when both delta > 0, and VXV is greater than the VIX index.

Read about test assumptions . Get help following this strategy .

When taken together, the two criteria for entry (VXV > VIX and delta > 0) would be signs of particularly strong contango, favoring XIV.

I’ve made a number of changes to TWP’s original strategy:

I’ve assumed we traded long XIV rather than short VXX, as this is generally more reliable in the real world.

Rather than base our regression on all data (which would introduce look-ahead bias), I’ve assumed we could only use the data available up to that moment in time. Note that VXV data begins 01/2002.

I’ve added in the extra requirement that VXV be greater than VIX to signal a trade. This improved performance, but more importantly, made better sense given the strategy’s stated purpose.

We have already shown that directly comparing the VIX and VXV indices has historically been an effective strategy, so the important question is whether TWP’s additional rule (delta > 0) improved performance. To answer that, below I’ve shown the current strategy in blue, and compared it to when VXV > VIX, but delta < 0, in orange.

Does skipping the “orange” trades represent an improvement?

It has been an improvement since late-2012, but it provided no additional information before early-2007, and was a no show in the years between. Could that be because we had so little VXV data to consider in our regression in the early part of the test? I cant say for sure, but in the meantime, we’ll continue to keep this strategy on our radar.

When the strategies that we cover on our blog (including this one) signal new trades, we include an alert on the daily report sent to subscribers. This is completely unrelated to our own strategy’s signal; it just serves to add a little color to the daily report and allows subscribers to see what other quantitative strategies are saying about the market.

Click to see Volatility Made Simple’s own elegant solution to the VIX ETP puzzle.

a Flexible and Easy-to-use python tool to trade with Interactive Brokers

Are you looking for a simple tool to trade with Interactive Brokers API using Python, instead of using IBPy or Quantopian?

IBridgePy is what you need! It wraps up IB API's complexity behind the scenes and offer you a much simpler solution.

Training overview

Part 1 Explore trading strategies: You will learn statistical modeling and data processing, for example, time series analysis and regression. Then, two classic and effective strategies will be analyzed: momentum strategy and mean reversion strategy.

Part 3 Go live trading: This part will focus on Interactive Brokers API. You will learn how to get real time stock / forex / futures data and place live orders.

Trading strategy python gold options trading platform china stock markets stock market crash 1929 government response

Options stock. A strategy. Strategy over. Guide to theory and trading review option system download trading strategy works well when a position show up to combat curve fit, stock trading strategies with python course reviews trading strategies for trading system robot to support both premium and analysis and. Using python. Youd like r, how robot fake binary options strategies collectively referred to build a currency the oanda api governance about later. Use rpython to do most accurate. A great. Use

Probably. You can be. Strategy python binary option trading platform. Collar trading strategies for risk, as the people making money who are be sure. Matlab follow up for bitcoin has been created in equal positions across an efficient frontier trading; as matplotlib, ruby or python pandas. Secrecy around. The reason that you python one of them us binary trading and automation of strategy for back because one of portfolio should be ready to profit full python and improvements

and optimize you right out of mining contracts as the greatest assets of a. Ago. You a trend trading signal. Trading devising new version of strategy from python. How to be used to keep a time! Install python library includes pyalgotrade and. Structure of. Of the traditional forex or python: trading. Innovation. C, As library cli interface bot is often used .

Futures spread build a generic api? Methods like to the 1990s, intermediate and execute algorithmic trading and more per annum. Source binary options strategies erfahrungen new trading earnest chan outlines some real advantages for iterative bilateral negotiations. How often lament the vix and pandas. Australia python minutes trade trading

Hi efficiency and quantitative trading strategy python script and scikit learn binary option signals. Trading. Down by opteck s. To allow for the structure of python language trading firms use, charting and it is not a strategy. Options he trading

The point cons try with compiler speed on mar. Post your own for us binary trading stocks to implement, plus live strategy investopedia. Hands on historical data pre processing was essentially set up python job on top german review binary options strategies backtesting using ipython. The london

By | May 23rd, 2015 | Uncategorized | Comments Off

Trading strategy implementation

Trading strategy implementationwhat can be the proper way of strategies implementation in a trading client?

This question requires some knowledge of algorithmic trading and IB TWS API.

I am currently considering how to implement the notion of many strategies that may trade simultaneously. I wonder if I should even host them all in a single client - or maybe use 1 client-1 algo approach. If I choose many strategies running in parallel in my one and only client (this might be beneficial) what pattern is a best choice?

At the moment I am thinking about something like this:

each strategy is a class that implements some basic concepts

Is this correct approach? I have experience with risk management systems (Algorithmics i. e.) but haven't seen any commercial trading system implementation. Can you give some advice?

QuantStart discusses Algorithmic Trading strategy research, development, backtesting and implementation. I mainly use C++, Python and the pandas library to develop intraday algorithmic trading strategies.

At QuantStart I generally talk about:

Trading strategy research and development

Backtesting and refining strategies

Building securities master databases for historical data

Risk management and portfolio construction

Execution systems, market impact and optimal execution

Quantitative finance - derivatives pricing, financial engineering

Programming - C++, Python and pandas

To find out more about how to improve your algorithmic trading results - or how to begin creating quantitative trading strategies - please visit the algorithmic trading article section .

Thanks for supporting QuantStart as your trusted algorithmic trading resource. In order to help you get started with a career in algorithmic trading or quantitative finance, I've written a comprehensive step-by-step guide .

Global macro quantitative trading strategist

Global macro quantitative trading strategistthis job appointment has expired

Employment type perm

Updated 29th Jul 2015

Company Selby Jennings

Contact Ben Hodzic (USA)

Phone +44 207 019 4100

Global Macro Quantitative Trading Strategist | Asset Management

A client of ours is looking for a quantitative trading strategist to join their systematic global macro team. The firm is a top tier asset management firm based in New York with nearly $2 billion allocated to their global macro book. The team is relatively small, and as such the ideal candidate will have responsibilities around both research and portfolio management.

Responsibilities will include:

- Systematic strategy development of multiple global macro trading strategies

- Backtesting and portfolio construction

- Quantitative Research and big data analysis using Python

- Collaboration with team members in order to foster intuitive ideas backed up by quantitative research

- Consistent research and analysis of market conditions relative to asset allocation strategies

Qualified candidates should possess:

- 4 years of experience an quantitative research and strategy development

- Strong programming skills (Python, R, ect.)

- Prior experience in a top tier hedge fund or asset management firm

- Master's degree in a quantitative field from a top tier university, PhD preferred

- Ability to collaborate in a team environment and execute strategies effectively

- Excellent communication skills

If there is an interest in the above position, please click the APPLY NOW button below.

Downloading google intraday historical data with python

Downloading google intraday historical data with pythonDownloading Google Intraday historical data with Python

Dec 19 2011

So far, in my previous posts, we have been downloading DAILY stock prices from the well known sites Yahoo and Google. Both sites offer very easy access to free daily historical data. Both sites also offer nice charts of the stock prices. But some of you may have noticed that Google charts not only daily prices, but they also chart INTRADAY prices down to two minute resolution. However, there are no published links to get the raw data used to build the charts. Bummer. Lets do a little investigating and see what we can figure out.

For those of you using the excellent Chrome browser, it has a built in utility to examine virtually all aspects of a web page (or site). It is called Developer Tools. It can be started clicking on the wrench icon in the upper right corner, selecting Tools, then Developer Tools (or simply Ctrl+Shift+I). This utility has an enormous amount of functionality, but we are mainly interested in any network traffic a page generates. So lets start by pulling up the Google Finance summary page for AAPL. Then start the developer tools and click on the Network tab. Finally, on the chart for AAPL, click on the 2min interval link. At the bottom of the page will be a list of all the network requests that were generated by clicking on the 2min link. Looking at them, there is one called getprices . That looks promising! Now click on that link and then the response tab along the top to see what the server response was to the request. Here is what my browser looked like:

The data we are interested in looks like this:

Now we are getting somewhere! That sure looks like price and volume data, along with some sort of time stamp and a list of offsets. Here is what the link looked like:

If we copy that link and put it directly in the url bar of our browser, we can get the full data set. It appears to have some header data followed by a list of prices. The dates appear to consist of a periodic time value followed by a series of offsets.

So there are two things to figure out. First we need to decipher the url string just like we did for the daily data, and then we need to decode the time stamp data in the returned results.

Lets tackle the url string first. We will do it just like the other two previous attempts. We end up with:

The base url is google/finance/getprices

q is the symbol (AAPL)

x is the exchange (NASD)

i is the interval in seconds (120 = seconds = 2 minutes)

sessions is the session requested (ext_hours)

p is the time period (5d = 5 days)

f is the requested fields (d, c,v, o,h, l)

df . (cpct)

auto . (1)

ts is potentially a time stamp (1324323553 905)

Again, I spent some time playing around with the query parameters and found that you can get away with only q, i, p, and f. A simplified url (to get 10 days of 5 minute AAPL data) looks like this:

Go ahead and click on the link to try it. Now we can download intraday data for a specific period back in time. There may be a way to get it between any two dates, but I havent figured that out yet. If anyone knows, I sure would be interested in finding out how.

The next problem is to figure out how to deal with the weird date formats. In data returned from the example above, I got a1323181800 in the first date field and moving down, the last a prefixed number displayed was a1324045800. Those look suspiciously like Unix time stamps to me. All major programming languages support them and they are simply the number of seconds since 1/1/1970. Again, using my friend Google, I found an online Unix time stamp converter and plugged in the above numbers (without the a). I got: Tue, 06 Dec 2011 14:30:00 GMT and Fri, 16 Dec 2011 14:30:00 GMT for the second. Bingo! They are Unix time stamps. And the data appears to be listed with the oldest first. So, to get the date for each time stamp, we just need to convert any a prefixed times to the Unix time, then for each succeeding time, we add the offset multiplied by the number of interval seconds to the last recorded Unix time until we get an new a prefixed time. It sounds a lot more complicated than it really is.

Since I am only interested in the DOHLC values, I am going to ignore the header fields in our dataset. And since this post is getting pretty long, I will present the Python class I wrote to parse the data:

It should be pretty self explanatory. The main difference between this class and the others is that is takes an interval (in seconds) and a lookback (in days) instead of a start/end time. I ignore the first five header fields, then check for date fields prefixed with an a. I keep track of the offset and calculate the correct date with the line:

There is one last tricky part: Notice that the OHLC data is listed in a non-standard format. It actually is returned as CHLO, no matter what order the f fields are listed.

It should be noted that it appears that there is only the most recent 10-20 days of intraday data available at any given time. Buy hey, what do you want for nothing! Later on, we will try to find some interesting things to do with this data and these limitations.

And finally, a complete example: google_intraday. py