Introduction to Algorithmic Trading at Indian Stock Markets using Python

Introduction to Algorithmic Trading at Indian Stock Markets using Python

Pushpak Dagade (~pushpak)
|
06 Aug, 2017

76

Votes

Description:

For what audience is this talk intended?

For those interested in using the power of Python to book profits and save time by automating their trading strategies at Indian Stock Markets.

What is Algorithmic Trading?

Imagine if you can write a Python script which can, for example, automatically BUY 100 shares of company 'X' when its price hits 52 week low and SELL it when it rises by 2% of the purchase price or based on some other different strategy which suits you. Sounds cool, right?

Algorithmic Trading is the process of using computer programs, based on a predefined algorithm, for placing trades in order to generate profits at a speed and frequency that is impossible for a human trader.

(The above example is very basic. You can code very complex strategies!)

Tell me the advantages of Algorithmic Trading over Conventional Trading

Here are a few reasons why algorithmic trading can lead to high chances of success -

Ability to take into account large number of factors for decision making, which can be practically impossible for a human

Trades can be timed correctly. Manually placing trade involves delay which may result in significant price change by the time trade is placed

Human error eliminated while placing trades

Human emotions (greed/fear) taken out of execution, which otherwise may result in big losses

And lastly, you can use your precious time for something else! Just let your computer monitor the stock markets 24x7 and place trade orders for you.

Ok. Now that you have got me interested, tell me quickly what this TALK will cover.

For implementing Algorithmic Trading in Python, you need the following -

Ability to query real time data (current stock price)

Ability to query historical data

A strategy (ie the Algorithm), which gives out predictions whether to BUY, SELL or HOLD.

Backtesting framework to test the strategy

Ability to place BUY/SELL trade order at Indian Stock Exchanges (NSE/BSE)

This TALK will demonstrate all the above mentioned points for the below strategy.

Every Buy and Sell order is placed with 1% Stop Loss and 0.3% Target Price

This strategy generated an average profit of ~6% per month (~72% annually) on real data of TATASTEEL (NSE) during backtesting for the period 16th June - 14th August, 2017.

Click below to see the video of this backtesting strategy in action.

Prerequisites:

Basics of Python

[Optional] Basics of Trading is a plus. (I will introduce the relevant trading terms in the beginning of the TALK for those not familiar)

Content URLs:

If you are interested in more information about this, please drop me a mail at guanidene@gmail.com with your purpose for accessing other resources. Thanks.

Speaker Info:

I hold 3 degrees from IIT Delhi - Electronics, Computer Science & Physics. I first started using Python in 2009 and have been using ever since, everywhere possible - academics, work, hobby. I currently work at NVIDIA.

Sometime back, I worked for a startup, TapDiscover, where we created 2 fully functional Android apps. I was responsible for complete backend development using Django REST Framework. I have also worked with Numpy, Matplotlib, PyQt4. I read Pythonbooks in my free time. I heavily use Python for scripting in my current job.

0

0

2

Quite a challenging task. There are lot of factors :
1. Capital
2. Risk ratio
3. Stock price and its market standing
4. Stop loss
5. Stocks to monitor - gives user selectivity
Also, it would be great if you can somehow do web crawling for particular company site for news and then invest ( it will give user idea of downfall ). Moreover, it not always 1 year high low, user should be able to set time frame. I know, you want fully automated code but stock is something user wants to get involved and analysis of the stock "price" is small fraction to book profit.

1

Thanks for commenting Yash. Yes, agreed this is quite a challenging task. I have developed the framework, pyalgotrading, keeping scalability in mind and currently it supports most of the points you have mentioned. (You may want to read the proposal once again, as I have added my content links. And please do watch the video mentioned above.)

With the current framework, one can easily code up a strategy and backtest it with support for the following features -

Capital restriction (My example strategy, strategy2.py, (which I have mentioned above) ensures there is no more than 1 trade is open at any given time, thus indirectly restricting capital usage)

Please note I have kept the target audience as "Beginner" as I would like to larger audience to take interest in this hot topic. The topic of web crawling, though extremely powerful, may get out of scope as it would involve Machine Learning. Having said that, the framework should be easily expandable to plug in this feature for advanced users with minimal effort.

0

0

Target price and stop loss numbers have been set based on real scenario, so YES you can use this in real life and still make profits :-) I have not included broker charges in the proposal to keep things simple.

0

Target price and stop loss numbers have been set based on real scenario, so YES you can use this in real life and still make profits :-) I have not included broker charges in the proposal to keep things simple.

0

Hi, Would be interested in learning how you managed such a feat! and ofcourse learn in the process. I am a newbie at Python, but do want to learn it earnestly for real world application and automation.