SlideShare a Scribd company logo
1 of 61
Download to read offline
Large
Problem
Medium
Problem
Medium
Problem
Medium
Problem
Small
Problem
Small
Problem
Small
Problem
Small
Problem
Small
Problem
Small
Problem
Small
Problem
Small
Problem
mean median first last stddev
rank() zscore()
factor1	>	
factor2
& |
rank() percentile()
cross_product()
Factors Filters
Classifiers
(2)
a	+	a	+	a 3a
SQL
numpy
In	[3]:
Out[3]:
from	zipline.assets	import	AssetFinder
	
finder	=	AssetFinder("sqlite:///data/assets.db")
lifetimes	=	finder.lifetimes(
				dates=pd.date_range('2001-01-01',	'2015-10-01'),	
				include_start_date=True,
)
lifetimes.head(5)
In	[4]: daily_count	=	lifetimes.sum(axis=1)
daily_count.plot(title="Companies	in	Existence	by	Day");
In	[5]: AAPL_prices	=	pd.read_csv(
				'data_public/AAPL-split.csv',	
				parse_dates=['Date'],	
				index_col='Date',
)
def	plot_prices(prices):
				price_plot	=	prices.plot(title='AAPL	Price',	grid=False)
				price_plot.set_ylabel("Price",	rotation='horizontal',	labelpad=50)
				price_plot.vlines(
								['2014-05-08'],	0,	700,	
								label="$3.05	Dividend",	
								linestyles='dotted',
								colors='black',
				)
				price_plot.vlines(
								['2014-06-09'],	0,	700,	
								label="7:1	Split",	
								linestyles='--',	
								colors='black',
				)
				price_plot.legend()
				sns.despine()
				return	price_plot
In	[6]: plot_prices(AAPL_prices);
In	[7]: naive_returns	=	AAPL_prices.pct_change()
naive_returns.plot();
In	[8]: from	bcolz	import	open
from	humanize	import	naturalsize
all_prices	=	open('data/equity_daily_bars.bcolz')
min_offset	=	min(all_prices.attrs['calendar_offset'].itervalues())
max_offset	=	max(all_prices.attrs['calendar_offset'].itervalues())
calendar	=	pd.DatetimeIndex(all_prices.attrs['calendar'])[min_offset:max_offset]
nassets	=	len(lifetimes.columns)
ndates	=	len(calendar)
nfields	=	len(('id',	'open',	'high',	'low',	'close',	'volume',	'date'))
print	"Number	of	Assets:	%d"	%	nassets
print	"Number	of	Dates:	%d"	%	ndates
print	"Naive	Dataset	Size:	%s"	%	naturalsize(
				nassets	*	ndates	*	nfields	*	8
)
Number	of	Assets:	20353
Number	of	Dates:	3480
Naive	Dataset	Size:	4.0	GB
In	[9]: !du	-h	-d0	data/equity_daily_bars.bcolz
!du	-h	-d0	data/adjustments.db
299M	 data/equity_daily_bars.bcolz
30M	 data/adjustments.db
In	[9]: !du	-h	-d0	data/equity_daily_bars.bcolz
!du	-h	-d0	data/adjustments.db
299M	 data/equity_daily_bars.bcolz
30M	 data/adjustments.db
In	[10]: import	pandas	as	pd
from	zipline.utils.tradingcalendar	import	trading_day
from	zipline.pipeline.data	import	USEquityPricing
from	zipline.pipeline.loaders	import	USEquityPricingLoader
loader	=	USEquityPricingLoader.from_files(
				'data/equity_daily_bars.bcolz',
				'data/adjustments.db'
)
dates	=	pd.date_range(
				'2014-5-20',	
				'2014-06-30',	
				freq=trading_day,
				tz='UTC',
)
In	[11]:
Out[11]:
#	load_adjusted_array()	returns	a	dictionary	mapping	columns	to	instances	of	`Ad
justedArray`.
(closes,)	=	loader.load_adjusted_array(
				columns=[USEquityPricing.close],
				dates=dates,
				assets=pd.Int64Index([24,	5061]),
				mask=None,
).values()
closes
Adjusted	Array:
Data:
	array([[	604.4	,			39.74],
							[	604.55,			39.69],
							[	606.28,			40.35],
							...,	
							[		90.35,			42.02],
							[		90.92,			41.73],
							[		91.96,			42.24]])
Adjustments:
{13:	[Float64Multiply(first_row=0,	last_row=13,	first_col=0,	last_col=0,	value=0
.142860)]}
In	[14]:
Out[14]:
dates_iter	=	iter(dates[4:])
window	=	closes.traverse(5)
window
_Float64AdjustedArrayWindow
Window	Length:	5
Current	Buffer:
[[	604.4					39.74	]
	[	604.55				39.69	]
	[	606.28				40.35	]
	[	607.33				40.105]
	[	614.14				40.12	]]
Remaining	Adjustments:
{13:	[Float64Multiply(first_row=0,	last_row=13,	first_col=0,	last_col=0,	value=0
.142860)]}
In	[15]: #	This	cell	is	run	multiple	times	to	show	the	numbers	scrolling	up	until	we	hit	
the	split.
data	=	next(window)
print	data
print	next(dates_iter)
[[	604.4					39.74	]
	[	604.55				39.69	]
	[	606.28				40.35	]
	[	607.33				40.105]
	[	614.14				40.12	]]
2014-05-27	00:00:00+00:00
float bool
dask
Developing an Expression Language for Quantitative Financial Modeling

More Related Content

Similar to Developing an Expression Language for Quantitative Financial Modeling

Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence Portfolio
eileensauer
 
Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence Portfolio
eileensauer
 
Anders Nielsen AD Model-Builder
Anders Nielsen AD Model-BuilderAnders Nielsen AD Model-Builder
Anders Nielsen AD Model-Builder
David LeBauer
 
E_Commerce Data model
E_Commerce Data modelE_Commerce Data model
E_Commerce Data model
SilpiNandi1
 
BABOKv2_SummaryTaskAssociationMatrix_v0_03
BABOKv2_SummaryTaskAssociationMatrix_v0_03BABOKv2_SummaryTaskAssociationMatrix_v0_03
BABOKv2_SummaryTaskAssociationMatrix_v0_03
Alan Maxwell, CBAP
 

Similar to Developing an Expression Language for Quantitative Financial Modeling (20)

Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence Portfolio
 
Business Intelligence Portfolio
Business Intelligence PortfolioBusiness Intelligence Portfolio
Business Intelligence Portfolio
 
3. R- list and data frame
3. R- list and data frame3. R- list and data frame
3. R- list and data frame
 
Youth Tobacco Survey Analysis
Youth Tobacco Survey AnalysisYouth Tobacco Survey Analysis
Youth Tobacco Survey Analysis
 
KPMG - TASK 1.pdf
KPMG - TASK 1.pdfKPMG - TASK 1.pdf
KPMG - TASK 1.pdf
 
Data Types of R.pptx
Data Types of R.pptxData Types of R.pptx
Data Types of R.pptx
 
DataCamp Cheat Sheets 4 Python Users (2020)
DataCamp Cheat Sheets 4 Python Users (2020)DataCamp Cheat Sheets 4 Python Users (2020)
DataCamp Cheat Sheets 4 Python Users (2020)
 
Anders Nielsen AD Model-Builder
Anders Nielsen AD Model-BuilderAnders Nielsen AD Model-Builder
Anders Nielsen AD Model-Builder
 
R Programming Intro
R Programming IntroR Programming Intro
R Programming Intro
 
Ggplot2 v3
Ggplot2 v3Ggplot2 v3
Ggplot2 v3
 
E_Commerce
E_CommerceE_Commerce
E_Commerce
 
E_Commerce Data model
E_Commerce Data modelE_Commerce Data model
E_Commerce Data model
 
R programming
R programmingR programming
R programming
 
Final project kijtorntham n
Final project kijtorntham nFinal project kijtorntham n
Final project kijtorntham n
 
Forecast stock prices python
Forecast stock prices pythonForecast stock prices python
Forecast stock prices python
 
Programming in R
Programming in RProgramming in R
Programming in R
 
Historical Finance Data
Historical Finance DataHistorical Finance Data
Historical Finance Data
 
A Deep Dive into Spark SQL's Catalyst Optimizer with Yin Huai
A Deep Dive into Spark SQL's Catalyst Optimizer with Yin HuaiA Deep Dive into Spark SQL's Catalyst Optimizer with Yin Huai
A Deep Dive into Spark SQL's Catalyst Optimizer with Yin Huai
 
BABOKv2_SummaryTaskAssociationMatrix_v0_03
BABOKv2_SummaryTaskAssociationMatrix_v0_03BABOKv2_SummaryTaskAssociationMatrix_v0_03
BABOKv2_SummaryTaskAssociationMatrix_v0_03
 
What's New in C++ 11/14?
What's New in C++ 11/14?What's New in C++ 11/14?
What's New in C++ 11/14?
 

Recently uploaded

Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
AldoGarca30
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
jaanualu31
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
chumtiyababu
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 

Developing an Expression Language for Quantitative Financial Modeling