Brooklyn College Ogbonnaya Akpara
CISC 7510X HW#7
Professor Alex S.
For this homework, feel free to use whatever you think is appropriate for correlation
(if not sure, try Pearson; Take a log of the percentage gain, and apply pearson on top of that.
Yes, you can do all this in SQL.).
Linear Regression
select tdate,symbol,tim,price,qty,slope,intercept
from (
select a.*,
floor(mod(floor(tim),100)+mod(floor(tim/100),100)*60+floor(tim/10000)*3600) ticks,
count(*) over (partition by tdate,symbol order by ticks
range between 3200 preceding and current row) N,
sum(ticks) over (partition by tdate,symbol order by ticks
range between 3200 preceding and current row) sx,
sum(ticks*ticks) over (partition by tdate,symbol order by ticks
range between 3200 preceding and current row) sxx,
sum(price) over (partition by tdate,symbol order by ticks
range between 3200 preceding and current row) sy,
sum(ticks*price) over (partition by tdate,symbol order by ticks
range between 3200 preceding and current row) sxy,
(sxx - sx*sx/N)/N as var,
(sxy - sx*sy/N)/N as covar,
covar / (case when var=0 then 0.000001 else var end) as slope,
sy/N - slope * sx/N as intercept
from DAILY_PRCNT a
) a
order by 1,2,3
Submit 10 "best" symbol pairs, each of which trades at least ~$10m a day, suitable for pairs trading in December 2013
(yah, I know it's an old date). Along with the pairs, submit their correlation coefficients for previous year,
and the month of December 2013. (assume you were trading $1m worth, and you traded those exact 10 pairs,
how much would you have gained/lost during that period?). Also submit the sql code to get those 10 symbols from the dataset.
1) NMK + NMK-PK
2) OXIS + OXIS-OB
3) MSI + MSI-PK
4) MRO + MRO-OB
5) LMT + LMT-OB
6) FNMA + FNMA-OB
7) CNW + CNW-PK
8) DIS + DIS-PK
9) F + F-OB
10) C + C-OB
Correation Coefficient
1) 0.17
2) 0.5
3) 0.94
4) 0.28
5) 0.87
6) 0.86
7) 0.21
8) 0.13
9) 0.87
10) 0.87
How much would you have gained/ lost during that period?
1) +0.07
2) +7.5
3) +0.44
4) +0.14
5) +1.50
6) +0.37
7) +0.20
8) +0.25
9) +1.37
10) +0.87
Submit the sql code to get those 10 symbols from the dataset.
select *
from (
select tdate,symbol,tim,0 o,price,qty qty,
null qtim,null bid,null bidsiz,
null ofr,null ofrsiz
from test_trades
union all
select tdate,symbol,tim,1 o,null,null,
tim qtim,bid,bidsiz,ofr,ofrsiz
from test_quotes
) a
order by 1,2,3,4;
Database-HW7 by OgboJr Productions, LLC | Request PDF. Available from: https://www.researchgate.net/publication/329642187_Database-HW7_by_OgboJr_Productions_LLC [accessed Dec 16 2018].
Database-HW7 by OgboJr Productions, LLC | Request PDF. Available from: https://www.researchgate.net/publication/329642187_Database-HW7_by_OgboJr_Productions_LLC [accessed Dec 16 2018].
Comments
Post a Comment