Created
October 28, 2010 12:31
-
-
Save mjbommar/651236 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% Initialize | |
clear all; | |
startDate = datenum('2005-08-25'); | |
endDate = datenum('2010-10-20'); | |
dateRange = busdays(startDate, endDate); | |
%% Load SPY data | |
csvFile = fopen('data/SPY.csv', 'r'); | |
csvFields = textscan(csvFile, '%s %f %f %f %f %f %f',-1,'delimiter',',','HeaderLines',1); | |
fclose(csvFile); | |
ftsSPY = fints(datenum(csvFields{1},'yyyy-mm-dd'), [csvFields{2} csvFields{3}, csvFields{4} csvFields{5} csvFields{6} csvFields{7}], {'Open','High','Low','Close','Volume','Adj'}); | |
ftsSPY = ftsSPY(ismember(ftsSPY.dates, dateRange)); | |
%% Load POMO data | |
csvFile = fopen('data/pomo_20050825_20101025.csv', 'r'); | |
pomoData = textscan(csvFile, '%s %s %s %s %s %s %s %f %f %f', -1, 'delimiter', ',', 'HeaderLines', 1); | |
fclose(csvFile); | |
directionVec = strcmpi(pomoData{2}, 'P'); | |
directionVec(directionVec==0) = -1; | |
ftsPOMO = fints(datenum(pomoData{1}), [pomoData{9}, pomoData{10}, directionVec, pomoData{8}], {'Accepted','Submitted','Direction','NumIssues'}); | |
ftsPOMO = ftsPOMO(ismember(ftsPOMO.dates, dateRange)); | |
ftsPOMO = todaily(ftsPOMO); | |
%% Double-check dates | |
if length(ftsSPY) ~= length(ftsPOMO) | |
error('Date vectors do not match in length between SPY and POMO'); | |
else | |
if sum(ftsSPY.dates ~= ftsPOMO.dates) > 0 | |
error('Date vectors do not match in values between SPY and POMO'); | |
end | |
end | |
%% Run the regression on submitted/accepted ratio | |
% Close - open intraday return | |
spyIntraDayReturn = log(fts2mat(ftsSPY.Close)) - log(fts2mat(ftsSPY.Open)); | |
% Log total dollars traded, as approximated by open-close midpoint | |
spyDolVol = log(0.5 * fts2mat(ftsSPY.Volume) .* (fts2mat(ftsSPY.Open) + fts2mat(ftsSPY.Close))); | |
% Submit/accept ratio | |
pomoSubmitAcceptRatio = fts2mat(ftsPOMO.Direction) .* fts2mat(ftsPOMO.Accepted) ./ fts2mat(ftsPOMO.Submitted); | |
pomoTopThird = find(pomoSubmitAcceptRatio > prctile(pomoSubmitAcceptRatio, 66)); | |
pomoBottomThird = find(pomoSubmitAcceptRatio < prctile(pomoSubmitAcceptRatio, 33)); | |
pomoMiddleThird = find((pomoSubmitAcceptRatio >= prctile(pomoSubmitAcceptRatio, 33)) .* (pomoSubmitAcceptRatio <= prctile(pomoSubmitAcceptRatio, 66))); | |
noPomo = find(isnan(pomoSubmitAcceptRatio)); | |
figure; | |
hold all; | |
disp('# Submit/Accept'); | |
scatter(pomoSubmitAcceptRatio(pomoBottomThird), spyIntraDayReturn(pomoBottomThird), 'or'); | |
fprintf('Bottom: %f\n', sum(spyIntraDayReturn(pomoBottomThird))); | |
scatter(pomoSubmitAcceptRatio(pomoMiddleThird), spyIntraDayReturn(pomoMiddleThird), 'xb'); | |
fprintf('Middle: %f\n', sum(spyIntraDayReturn(pomoMiddleThird))); | |
scatter(pomoSubmitAcceptRatio(pomoTopThird), spyIntraDayReturn(pomoTopThird), '.g'); | |
fprintf('Top: %f\n', sum(spyIntraDayReturn(pomoTopThird))); | |
legend({'Bottom Third, A/S', 'Middle Third, A/S', 'Top Third, A/S'}); | |
title('POMO and Return'); | |
ylabel('Return'); | |
xlabel('A/S'); | |
[retB, retD, retS] = glmfit(pomoSubmitAcceptRatio, spyIntraDayReturn); | |
[absretB, absretD, absretS] = glmfit(pomoSubmitAcceptRatio, abs(spyIntraDayReturn)); | |
figure; | |
hold all; | |
disp('# Dollar Volume'); | |
scatter(pomoSubmitAcceptRatio(pomoBottomThird), spyDolVol(pomoBottomThird), 'or'); | |
fprintf('Bottom: %f\n', mean(spyDolVol(pomoBottomThird))); | |
scatter(pomoSubmitAcceptRatio(pomoMiddleThird), spyDolVol(pomoMiddleThird), 'xb'); | |
fprintf('Middle: %f\n', mean(spyDolVol(pomoMiddleThird))); | |
scatter(pomoSubmitAcceptRatio(pomoTopThird), spyDolVol(pomoTopThird), '.g'); | |
fprintf('Top: %f\n', mean(spyDolVol(pomoTopThird))); | |
legend({'Bottom Third, A/S', 'Middle Third, A/S', 'Top Third, A/S'}); | |
title('POMO and Dollar Volume'); | |
ylabel('Dollar Volume'); | |
xlabel('A/S'); | |
[dvB, dvD, dvS] = glmfit(pomoSubmitAcceptRatio, spyDolVol); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment