Sie sind auf Seite 1von 45

Page |1

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 1


Page |2

Table of Contents
Page 06 | Alphas for Algo Trading
Page 14 | Machine Learning for Trading
Page 28 | Coding Cases
Page 33 | Quantitative Trading in Crypto Currencies
Page 44 | Upcoming Conferences in Mumbai/Delhi

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 2


Page |3

*Oaths inspired by Noufal Ibrahim, Founder Haman Technologies LLP

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 3


Page |4

Benefits of Algo Trading for Retail Investors, Institutions


1. Save Time

A good ATS Execution Strategy saves time spent in sending manually orders- punching and modifying. Similarly, a ATS
signal generation strategy saves valuable time spent in analyzing a stock. Therefore, by saving time in repetitive tasks
though ATS, a trader can focus on managing strategies. Having an ATS is like hiring an assistant for repetitive tasks.

2. Save Money

For active traders, an ATS can save lakhs of rupees spent in slippage. Reducing the trading costs is considered most
important benefits of algo trading. Let us explain it with an example:

Assume you decide to buy Nifty Futures based on momentum and look at its order book. The Best Buyer|Best Seller are
at 8520.20|8520.50

To manually punch order, you press F1, fill limit at 8520.50, click on Send and then click on Confirm.

By the time the limit order goes to exchange, prices move further up- 8520.50|8520.70. Your order is now pending in
exchange as Best Buyer

Since it is momentum based trade, Nifty does not fill your order and moves further upto 8520.80|8521.00

Realizing that your pending order has minimal chances of getting filled, you frantically move on. Go to pending orders
window, Cancel pending order, Press F1, fill limit price at 8521.00, click on Send and then click on Confirm.

By the time the limit order goes to exchange, prices move further up- 8521.20|8521.50. Your order is once again
pending in exchange as Best Buyer.

You frantically repeat the process of cancelling pending order and sending fresh buy order at 8522.00 and get filled.

In such manual trading, you first decided to buy when Best Seller was at 8520.50 but actually bought at 8522.00. This
difference of Rs 1.50 is called as slippage. However, if you had a very fast computer (server) on your side to
automatically send orders, you could have bought near 8520.50, say 8520.60. Thus the ATS can save Rs. 1.40 per trade
per lot. For a intraday trader who makes two trades daily with 3 lots of Nifty, it will amount to monthly saving of Rs.
1.40 *50* 3*2*22= Rs. 9240!!

3. Minimize Emotions

Emotions tend to be the biggest enemy of a trader. When a trader’s intelligence is disturbed by impulsive mind, he may
risk too much on a strategy or abandon a strategy without proper performance measurement.

Since ATS executes pre-defined trading logic, no human emotions are involved. This is considered the second most
important benefits of algo trading.

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 4


Page |5

4. Inculcate Discipline

Discipline once developed can be maintained even when markets are highly volatile or when prices are stagnant for
days. An ATS forces a trader to think systematically by executing trades on well-defined trading logic. It minimizes
emotional impulses.

5. Intellectual Engagement

This is perhaps the best advantage of ATS. Since ATS forces systematic trading, it pushes the traders to continuously
research for better strategies. It engages there intellect to the fullest by calculating risks, costs along with the rewards
of each strategy. Hence it improves the productivity of a trader as person.

6. Minimize Human Errors

Every active trader loses money to menial errors like punching wrong order quantity, wrong order price or sending the
order in wrong scrip. ATS minimizes such errors.

7. Reduce Gambling Tendency

Indians love to gamble a lot- which cricket team will win match or which politician will win elections. By intellectual
engagement ATS also limits gambling tendency.

8. Diversify Trading

Having ATS as assistant saves time to allow you diversifying in more scrips, multiple strategies and multiple segments

9. Complex Strategies

Execute complex strategies which include auto-modifcation, multi-leg, multi-client, multi-scrip and multi-exchange
execution. Therefore, for institutional trading and fund managers, ATS is unavoidable.

10. How much does benefits of algo trading costs?

Impressed by the benefits of algo trading? Let’s look at its costs. The simplest form of algo trading- a bracket order is
provided free by many brokers. The cost of deploying an ATS depends upon the complexity of decision making and
execution logic.

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 5


Page |6

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 6


Page |7

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 7


Page |8

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 8


Page |9

SENKOU SPAN LINES


• The two Senkou Span (leading) lines are pushed forward in time to represent past support and
resistance ( support will continue to provide support until broken when it becomes resistance)
This “cloud” not only defines the trend, but acts as support and resistance for price.
Cloud = Kumo
• Clouds play the role of support/resistance areas and help identify trends. When the price is above the
clouds, the trend is bullish. When the price is below the clouds, the trend is bearish.
Ichimoku Breakout Strategy
1. Placing a trade when the price closes outside the cloud
2. First, you open your trade in the direction of the respective breakout and then hold the position until
the security breaches the Kijun on a closing basis.
3. The lagging indicator (chinkou span) breaks cloud in same direction.
4. The price trading above/below 9 and 26 period moving averages.
5. The future cloud is sloping direction of trend.
Other Ichimoku Popular setups
Four Other Popular Set-ups:
1.Break of the Cloud: STOP: Other Side of the Cloud
2.Buy/Sell the TS with Stop at KS
3.Buy/Sell the KS with Stop in the Cloud
4.Buy/Sell the TS/KS crosover

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 9


P a g e | 10

Ichimoku Breakout Modified Investment Strategy


●Placing a trade when the price closes outside the cloud along with flatness of SSB and breadth of the cloud
●First, you open your trade in the direction of the respective breakout and then hold the position until the
security breaches 50 EMA on a closing basis. (Partial exit strategy also possible)
● Re-enter again if Price closes above 50 EMA and Price is still above the cloud

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 10


P a g e | 11

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 11


P a g e | 12

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 12


P a g e | 13

Ichimoku Breakout Modified Investment Strategy


●Placing a trade when the price closes outside the cloud along with flatness of SSB and breadth of the
cloud
●First, you open your trade in the direction of the respective breakout and then hold the position
until the security breaches 50 EMA on a closing basis. (Partial exit strategy also possible)
● Re-enter again if Price closes above 50 EMA and Price is still above the cloud

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 13


P a g e | 14

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 14


P a g e | 15

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 15


P a g e | 16

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 16


P a g e | 17

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 17


P a g e | 18

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 18


P a g e | 19

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 19


P a g e | 20

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 20


P a g e | 21

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 21


P a g e | 22

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 22


P a g e | 23

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 23


P a g e | 24

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 24


P a g e | 25

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 25


P a g e | 26

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 26


P a g e | 27

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 27


P a g e | 28

Coding Cases
By Saurabh Lohiya, Founder AlgoJi

Coding Ichimoku Charts in Amibroker:


Kijun_sen = ( HHV( H, 26 ) + LLV( L, 26) )/2;

Tankan_sen = ( HHV( H, 9 ) + LLV( L, 9 ) )/2;

Span1 = Ref((( Kijun_sen + Tankan_sen )/2),-26);

Span2 = Ref((HHV( H, 52) + LLV(L, 52))/2,-26);

“Placing a trade when the price closes outside the cloud”

Buy = Ref(H,-1)> Ref(Max(span1,span2),-1) AND Ref(H,-2)<= Ref(Max(span1,span2),-2);

“Break of the Cloud: STOP: Other Side of the Cloud”

Sell = Ref(L,-1)< Ref(Min(span1,span2),-1) AND Ref(L,-2)>= Ref(Min(span1,span2),-2);

“Buy/Sell the TS/KS crossover”

Buy= Cross(Tankan_sen, Kijun_sen);

Sell= Cross(Kijun_sen,Tankan_sen);

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 28


P a g e | 29

Hedging Bank Nifty Future Position by Bank Nifty Put/Call

Part 1: Selecting the put/call strike

1. Calculate days in current month- 30, 31, 28 or 29


2. Calculate date of coming Thursday based on total number of days in current month
3. Select 3 letters of the month of strike price: based on whether coming Thursday falls in current month or
next month. This competes the selection of the correct expiry series for options.
4. Based on Bank Nifty Future price, select strike price of put/call

Part 2: Generating signals at the same time in Future and Option

1. Define Buy and Sell conditions using Foreign() to access all data of Futures & Options
2. Generate Buy/Sell based on condition whether current symbol is the correct future/option

The Optimization Problem (raw example)

Consider you are optimizing a moving average crossover strategy. You have two moving averages whose
periods ranges from 1 to 100, which you want to optimize.

That's 10000 combinations – means you need 10K backtests to complete the optimization. Even if it takes 10
milliseconds to compete a single backtest, it will take 100 seconds – that’s one hand a half minute- to complete
the optimization.

Now, suppose you decide to add a SL to the strategy, so that there is limit on the max loss you will take per
trade. Assume you want to optimize the SL from 10-50 points with step interval of 0.5 points. So, it will add
40*2 = 80 combinations.

Also assume you add a profit target to the MA strategy. You may like to optimize the target from 20-100 points
with step interval of 0.5 points. This adds 80*20= 160 combinations.

This brings us to 100*160*80= 1,280,000 seconds or aprox 15 days to complete the optimization!!!

Using Evolution Strategy - Covariance Matrix Adaptation Evolution Strategy (CMAES)

1. Start with initial guess of optimal parameters, and the step size
2. Generate first set of offspring from the initial mean
3. Evaluate the offspring and rank it by fitness

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 29


P a g e | 30

4. Update the mean using weights on fitness


5. Update the covariance matrix
6. Repeat the steps until no significant improvement is achieved

Amibroker Code to achieve all this:

OptimizerSetEngine("cmae"); //that’s all 😊

Connecting Amibroker with Python for Machine Learning


Part1: Pass values from AFL to Python
Pred = py.ForecastChange(range_lo,range_hi,MACDarr,RSIarr,Change);
// Stores 7 predictions on the last seven bar counts
CandleColor = py.ForecastColor(range_lo,range_hi,MACDarr,RSIarr,CandlestickColor);
// Stores 7 predictions on the last seven bar counts

Part2: Apply Machine Learning in Python


import sklearn.linear_model as sklm
def ForecastChange(self,range_lo,range_hi,macd,rsi,change):
size = 10000
X = numpy.matrix([list(range_lo[-size:-4]), list(range_hi[-size:-4]), list(macd[-size:-
4]), list(rsi[-size:-4]) ]).T
y = numpy.array(list(change[-size:-4]))
regr = sklearn.svm.SVR(C=100.0,epsilon = 0.0001)
regr.fit(X,y)
predicted = regr.predict(numpy.matrix([range_lo[-7:], range_hi[-7:], macd[-7:], rsi[-
7:]]).T)
return predicted

def ForecastColor(self,range_lo,range_hi,macd,rsi,candlecolor):
size = 10000
X = numpy.matrix([list(range_lo[-size:-4]), list(range_hi[-size:-4]), list(macd[-size:-
4]), list(rsi[-size:-4]) ]).T
y = numpy.array(list(candlecolor[-size:-4]))
classif = sklearn.svm.SVC(C=100.0)
classif.fit(X,y)
predicted = classif.predict(numpy.matrix([range_lo[-7:], range_hi[-7:], macd[-7:], rsi[-
7:]]).T)
return predicted

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 30


P a g e | 31

Inter-Exchange Crypto Currency Arbitrage

Importing Crypto Currency data in Amibroker

1. Download data from Kaggle, Quandl or any of the Exchange APIs


2. In excel, convert unix time stamp to separate Date & Time columns.

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 31


P a g e | 32

Bitcoin Charts in Amibroker

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 32


P a g e | 33

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 33


P a g e | 34

Features
No central body to create units

Public Ledger called BLOCKCHAIN

Transactions are secured cryptographically into a block

How do they work


Transaction Blocks are verified by MINERS/NODES by solving the cryptographic puzzle

Verified blocks get added to the blockchain

Miners get rewarded in the native currency for verifying the blocks

Categorization of Cryptocurrencies
Altcoins
Derived from the Bitcoins Open Source Protocol

Peercoin, Litecoin, Dogecoin

Coins that have their own Blockchain and Protocols

Ethereum, Ripple, Nxt

Tokens
Representation of a particular asset/utility that usually resides on top of another blockchain.

SALT, Blocktix

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 34


P a g e | 35

What are tokens


A token is a unit of value that an organization creates to self-govern its business model

Empowers users to interact with its products

Facilitates sharing of rewards

The functionality of creating tokens is made possible through the use of SMART CONTRACTS

(self executing programmable computer codes)

Tokens are distributed to the public through an ICO ( Initial Coin Offering )

ICO vs IPO

Unregulated means of raising funds for a new cryptocurrency venture

No Track record in most cases. Credibility is established based on the project


developers/whitepaper/communication channels

ICO coin does not grant ownership of the project

Coin Value correlates with PERCEIVED utility

Level playing field for all investors

Types of Tokens
Utility Tokens / Network Access Tokens

Ether – Allows you to run Smart Contracts

Asset Tokens – Tokenize Traditional Asset Classes

GoldMint – Tokenize Gold

Equity Tokens – Represents Ownership and Control

DAO – Investor Directed VC Fund

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 35


P a g e | 36

How to profit from cryptos ?


Mine/Lend/Stake

Invest in ICOs

Follow a Buy and Hold strategy

Use trading strategies

Quantitative Approaches to trade cryptos

Trend Following Models

Cross Exchange Arbitrage

Market Neutral Strategies

Factor models based on Short Term Momentum

Sentiment Analysis

Machine Learning

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 36


P a g e | 37

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 37


P a g e | 38

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 38


P a g e | 39

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 39


P a g e | 40

Cross exchange arbitrage – How do you do it ? – OPTION 1


LTC is trading at 100 $ on BITTREX and 110 $ on BINANCE (Bittrex and Binance are popular cryptocurrency
trading exchanges)

Buy LTC on BITTREX

Transfer the LTC to BINANCE

Sell LTC on BINANCE

Cross exchange arbitrage – How do you do it ? – Option 2


Hold Dollars/USDT (Tokenized Dollar) in Bittrex

Hold some LTC on Binance

LTC is trading at 100 $ on BITTREX and 110 $ on BINANCE

Buy LTC on BITTREX with USDT and SELL LTC which you already hold on BINANCE

Cross exchange arbitrage – Pitfalls and risks


Transactions Costs

exchange withdrawal fees, trading fees

Counterparty Risk

Coins are stored on exchanges which can get hacked.

Execution Risk

Low execution speeds resulting in the price being taken by some other trader.

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 40


P a g e | 41

Cross exchange arbitrage – Pitfalls and risks


Movement Risk

Risks associated with moving the coins from one exchange to the other.

Price Decline Risk

In BEAR markets arbitrage profits will not be enough to offset the decline in the asset price.

Regulatory Risk

Market neutrality with factor models


Generate a universe of ‘N’ coins to be traded

Bitcoin, Litecoin, Ethereum, Ripple, Monero, Dash, Nem

Total of 7 coins

Compute a ranking system based on the factors

Short term returns based momentum

Average returns over the past ‘x’ days

Market neutrality with factor models


Generate a rebalancing schedule

Every day, every week, every month

Choose the number of coins to be to be traded out of ‘N’

Long on 3 coins and short 3 coins

On the rebalancing day compute the rank and go long on the top ranked coins and short on the bottom ranked
coins

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 41


P a g e | 42

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 42


P a g e | 43

Are there other ways to hedge my risk ?


Diversify among
Assets

Asset Classes

Strategies

Styles

Exchanges

Allocate Conservatively
Allocate to Cryptos only What you can afford to lose

Allocate to minimize downside rather than maximize upside

Thank You!

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 43


P a g e | 44

Upcoming Conferences

PS: It is hard to call them “conference” because they include online courses, hands-on training
sessions and so many other things 😊

Mumbai Algo Traders Conference - 5th May 2018


What’s Special:
- Breakout sessions for hands-on practice on your own laptop, irrespective of your programming skills.
We keep the focus on algo trading limiting the job of technology as an enabler.
- Breakout session ‘Algos Using Python & Data Science’ will be delivered by Dr. Hari. He has done
Ph.D in Applied and Computational Mathematics from IISc Bangalore. He is a Quantitative
Researcher and Data Scientist who has Worked as trader, researchers, data scientist, developer on
different projects.
For details & registration visit https://algoji.com/training/mumbai/

Delhi Algo Traders Conference – 4th August 2018 (details to be announced soon)

Mumbai Meetup 2017 organized by AlgoJi

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 44


P a g e | 45

COPYRIGHT ALGOJI ENTERPRISES, ALL RIGHTS RESERVED| PAGE 45

Das könnte Ihnen auch gefallen