Algo trading(Minor Project) strategy EMA with Ipython
1. ALGORITHMIC TRADING
Minor Project
Deb Prakash Ganguly 1401227154
Guided by (ASST PROF.NAMITA BAJPAI)
27,NOVEMBER,2017
C.V RAMAN COLLEGE OF ENGINEERING
.
Algo Trading Short Title 1/23
3. INTRODUCTION
• It is the process of using set of rules or any mathematical
model to generate profits at a high speed frequency that is
impossible for a human trader
• It is simply a way to minimize the cost, market impact and
risk in execution of an order.It is widely used by investment
banks and hedge funds.
Algo Trading Short Title 3/23
4. OBJECTIVE
• To predict stock prices through lagger indicator.
• Investor will evaluate strategies from a rigorous scientific
perspective to prevent financial crises .
• It will help in portfolio management to make a prediction
individual stocks.
• Trades will be instantly, to avoid significant price changes
Reduced transaction costs or brokerage charge.
• Reduced possibility of mistakes by human traders based
on psychological factors.
Algo Trading Short Title 4/23
5. SOFTWARE REQUIRED
• Automated trading can be done by c, c++, java script,
ipython, etc.out of which we are using interactive
python(Ipython)
• Most of the quant traders prefer Python algorithmic trading
as it helps them build their own execution mechanisms .
• Python can be used to develop some great treading
platform where using c or c++ is a time consuming job .
• It has packages like Pandas, NumPy, PyAlgoTrade,
MatPlotLib which support google finance, csv files.Are free
of cost.
Algo Trading Short Title 5/23
6. Interactive python
IPython provides a rich architecture for interactive computing
with:
• A powerful interactive shell.
• A kernel for Jupyter.
• Flexible, amendable interpreters to load into your own
projects.
Algo Trading Short Title 6/23
7. ARCHITECTURE
• The entire automated trading system can now be broken
down into 3 parts :
• The exchange(s) the external world
• The server
• Market Data receiver
• Store market data
• Store orders generated by the user
• Application
• Take inputs from the user including the trading decisions
• Interface for viewing the information including the data and
orders
• An order manager sending orders to the exchange
Algo Trading Short Title 7/23
9. NEW ARCHITECTURE
• The traditional architecture could not scale up to the needs
and demands of Automated trading with Direct market
access (DMA).
• The latency between origin of the event to the order
generation went beyond the dimension of human control .
• Order management also needs to be more robust and
capable of handling many more orders per second.
Algo Trading Short Title 9/23
10. • The infrastructure level of this module is superior
compared to traditional system . Hence the engine which
runs the logic of decision making,is known as the Complex
Event Processing engine, or CEP .
• The risk checks are performed now by a separate Risk
Management System (RMS) within the Order Manager
(OM), just before releasing an order.
Algo Trading Short Title 10/23
12. • The new architecture was capable of scaling to many
strategies per server, the need to connect to multiple
destinations from a single server emerged.
• The order manager hosted several adapters to send orders
to multiple destinations and receive data from multiple
exchanges.
• To avoid this hassle of adapter addition, standard protocols
have been designed. The most prominent among them is
the FIX (Financial Information Exchange) .
Algo Trading Short Title 12/23
13. Automated trading Strategies
As per the new architecture is capable of scaling too many
strategies out of which we apply 2 of them .
• Simple Moving Average (SMA)
• The simple moving average is the simplest type of moving
average.
• It is arguably the most popular technical analysis tool used
by traders.
• A simple (or arithmetic) moving average is an arithmetic
moving average calculated by adding the elements in a time
series and dividing this total by the number of time periods.
• [SMA = (Sum of data points in the moving average
period)/(Total number of periods)]
Algo Trading Short Title 13/23
14. • Exponential Moving Average (EMA or EWMA)
• The simple moving averages are sometimes too simple and
do not work well when there are spikes in the price of the
security. Exponential moving averages give more weight to
the most recent periods. This makes them more reliable
than the SMA and a better representation of the recent
performance of the security.
• alpha = 0.1 to 0.3 [ EMA = (Closing price minus EMA of
previous day/bar) x alpha) + EMA of previous day/bar
Rewritten as: EMA = (Closing price) x alpha + (EMA of
previous day/bar) x (1 minus multiplier)
Algo Trading Short Title 14/23
15. Algorithm
• Step 1:- Start
• Step 2:- Import packages
• Step 3:-Request for API
• Step 4:-Retrive access token
• Step 5:-Request trade segment in NSE or BSE
• Step 6:-Request for history data for a particular script from
NSE
Algo Trading Short Title 15/23
16. Algorithm
• Step 7:- Slicing dataframe.
• Step 8:- converting dataframe to csv file.
• Step 9:- calculation SMA[ n/n].
• Step 10:- calculation
EMA[(alpha*prev.close)+(1-alpha*prev.ema)
where alpha=( 2/1-n).
• Step 11:- Cal. EMA for 5,8 and 13 days.
• Step 12:- Convert all csv data to dataframe.
Algo Trading Short Title 16/23
17. Algorithm
• Step 13:- Plotting graph through dataframe.
• Step 14:- By using euclidean formula, distance between
two lines[dist((x, y), (a, b)) = (x − a)2 + (y − b)2]
• Step 15:- Cal.risk line= [dist((x, y), (a, b)) - [dist((x1, y1),
(a1, b1))
• Step 16:- If risk line == 0, check if (x,y) >(x1,y1) generate
’BUY’ signal else ’SELL’.
Algo Trading Short Title 17/23
20. Limitations
• Algorithmic trading is not 100 percent accurate.We just
predict future stock price basis upon past stock behaviour.
• Algorithmic trading is not universal. one algorithm cannot
be applied to every situation.
• Investor has to check daily news or updates of individual
script.
• Due to this market goes to more volatility.
Algo Trading Short Title 20/23
21. Conclusion
Trading is extremely difficult for both full time and especially part
time traders.The best road to gain profit is finding your own
trading strategies.Once you got it, is your goals and
objectives.No,trading strategies lasts forever and i find myself
constantly reinventing my strategy.I learned all of these
lessons,and many more from trade academy during my
internship.
Algo Trading Short Title 21/23
22. Future Enhancement
In year of 2008 SEBI started allowing DMA.In the US and other
developed markets HFT estimated 70 percentage of equity
market share.In India is around 12 percentage. As technology
is growing,financial technology is growing up same space.
In recent years,the number of machine learning packages has
increased in finance trading. some established funds like
Medallion,Citadel,JPmorgan using artificial intelligence, and
there performance is in peak level.
Upcoming years algo trading with AI power will have a huge
impact in Indian market.
Algo Trading Short Title 22/23
23. References
• Fundamental of dataframe by Yves Hilpisch,2016, p.137
• API connection
website:https://github.com/upstox/upstox-python
• Algo Trading architecture
https://www.quantinsti.com/blog/trading-systems-
architecture
Algo Trading Short Title 23/23