Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

QuantiPy

Ishan Shah

© Copyright QuantInsti Quantitative Learning Private Limited v10.1.0 1


Outline
• Quant Strategy Workflow
– Data Gathering
– Screening
– Alpha Generation
– Performance Analysis
• Modular Programming

© Copyright QuantInsti Quantitative Learning Private Limited v10.1.1 2


Quant Strategy Workflow

© Copyright QuantInsti Quantitative Learning Private Limited v10.1.1 3


Data
• All quant strategies start with data
• Which dataset contains the information I need to predict future returns?
Example
Price series: Open, High, Low, Close, and Volume
Source: Quantra Blueshift, Quandl, your broker etc.

Fundamental: Valuations, Income Statement, Cash Flow Statements, Earnings


Calendar, Broker ratings, Analyst estimates, etc.
Source: Morningstar etc.

Sentiments: Trader mood


Source: stocktwits and PsychSignal

Legal, Regulatory, and Economic: Inflation rate, GDP, Fed meeting dates, etc.
Source: EventVestor

© Copyright QuantInsti Quantitative Learning Private Limited v10.1.1 4


OHLCV Data Example
1. Open data.py file
2. if the module nsepy is not available then
!pip install nsepy
3. Write a code to fetch data from nsepy

# Import get_history function from nsepy


from nsepy import get_history

# Fetch the data


data = get_history(symbol=inst_name,
start=start_date,
end=end_date)
# Return Open, High, Low, Close, and Volume columns
return data[['Open','High','Low','Close','Volume']]

© Copyright QuantInsti Quantitative Learning Private Limited v10.1.1 5


Fetch Data
1. Open check_data.py
2. Write a code to fetch OHLCV data for HDFC and store it in data

# Fetch Data
from data import get_stock_data
data = get_stock_data('HDFC', start_date, end_date)

© Copyright QuantInsti Quantitative Learning Private Limited v10.1.1 6


Screens
• In this step, you screen out instruments which you don’t want to be part of your
portfolio
Example
– Penny stocks
– Low liquidity
– High volatility

© Copyright QuantInsti Quantitative Learning Private Limited v10.1.1 7


Alphas
• Define the hypothesis which can predict future returns

Sell in May and go way


January effect
If the market rises for two days then it will continue to rise
Buy and hold quality stocks
Mean-reversion
Trend following

• Create an expression for your hypothesis

moving average 2 days > moving average of 7 days then buy and vice-versa

• Combine the Alphas (as single alpha factor won’t be sufficient)

© Copyright QuantInsti Quantitative Learning Private Limited v10.1.1 8


Analyze the performance
• Analyze the performance of the strategy
Example

Sharpe Ratio
Returns
Volatility
Sortino Ratio
Max Drawdown

© Copyright QuantInsti Quantitative Learning Private Limited v10.1.1 9


Options Trading Strategy
• Strategy:
– Short straddle before earnings announcement and square off after that.
• Rationale:
1. This strategy aims to exploit the implied volatility pattern observed before the
earnings announcement.
2. Before earnings announcement, there is a great amount of uncertainty
3. Because of this uncertainty,
1. the implied volatility of the options rises as the earnings announcement
date approaches and
2. drops sharply after the earnings are announced

© Copyright QuantInsti Quantitative Learning Private Limited v10.1.1 10


Options Trading Strategy
• Define a function to get options data using NsePy
• Define the parameters required for strategy
• Define Alpha
• Compute returns

© Copyright QuantInsti Quantitative Learning Private Limited v10.1.1 11


Thank you!

Ishan Shah

© Copyright QuantInsti Quantitative Learning Private Limited v10.1.1 12

You might also like