Presentation is loading. Please wait.

Presentation is loading. Please wait.

SQL & VBA for Quant Finance

Similar presentations


Presentation on theme: "SQL & VBA for Quant Finance"— Presentation transcript:

1 SQL & VBA for Quant Finance
Satyadhar Joshi  stable calm slow and less nervous quite place and normal speaking Wirless mcorphnes for mobile

2 Loops is trickier in SQ L easier in VBA
Output format not so friendly in SQL easier in VBA Long data cannot be used in formula in VBA – date elements greater and 200k entries File opening for big data easier in SQL not in VBA 1 million rows takes time to calculate average of columns in Excel – whereas it happens in flash of second in SQL No need to open any file and wait for it to load – just run the query SQL in VBA Connecting MS SQL R2 in VBA

3 References change the setting to enable integration
sConnString (this is the connection credentials like server name - username password etc) ADODB.Recordset ADODB.Connection sqlQuery (it is a string that carries the query such as select from where) References change the setting to enable integration ADO = ActiveX Data Objects 2.8 Library Elements of the Code

4 The only hurdle in the coding–connection
sConnString = "Provider=SQLOLEDB.1;Integrated Security=SSPI; Persist Security Info=True;" & _ "Initial Catalog=saa_solvencydb_dev1;Data Source=xl-inv-solvency-dev;" & _ "Use Procedure for Prepare=1;Auto Translate=True; Packet Size=4096;" & _ "Use Encryption for Data=False;" & _ "Tag with column collation when possible=False"

5 Importing the data Conn.Open sConnString Set rs = Conn.Execute(sqlQuery) If Not rs.EOF Then ' Transfer result. Sheets("Sheet").Cells(1,1).CopyFromRecordset rs ' Close the recordset rs.Close Else MsgBox "Error: No records returned.", vbCritical End If

6 Operations in SQL SQL is different from MATLAB where would use the matrix calculations Advantage of SQL is its speed where ti can calculate means average tables from 100s thousands rows and get you the output very fast In SQL creating tables is our main weapon – we would create new tables – new columns- but we would avoid making new entries or tuples to store our information Once we have different tables we would join to join the tables to get the final ouput Sorting is used for the percentile – and no maths formulas are directly used – some operations are given in 2012 t sql but none in 2008 r2

7 Operating after getting data in VBA
This seems to be an easier optios for those who feel it tougher in SQL

8 Creating Temporary Tables
Creating tables in another tables Naming of tables Row vs column things

9 Tricker Tasks Creating percentile in SQL
Arranging data in SQL in a given format so that we can get what we want Group by Order by

10 References


Download ppt "SQL & VBA for Quant Finance"

Similar presentations


Ads by Google