Wednesday, August 11, 2010

Intraday Liquidity Pattern calculation using Ox

/*
* Stefan Binder, Duk Jang, Tai Tran
* This Ox program calculates liquidity pattern from a trading period for a stock
* The intraday pattern assists trading strategies formation
*/

const decl ROWS = 3416;
const decl COLUMNS = 4;
const decl PARCELS = 6;
const decl PRICE = 0;
const decl VOLUME = 1;
const decl DAY = 2;
const decl HOUR = 3;
const decl OPEN = 10;
const decl NUMBEROFPARCELS = 6;
const decl CLOSE = OPEN + NUMBEROFPARCELS - 1;
const decl NUMBEROFDAYS = 5;
const decl FILENAME = "tradedata.csv";
const decl PARCELOUTPUT = "ParcelLiquidity.csv";
const decl DAYOUTPUT = "DayLiquidity.csv";

main()
{
decl m;
decl liquidity=0;
decl parcel;
decl day;
decl parcelPercent;
decl dayPercent;
decl i,j,k;
decl fileParcel,fileDay;

m = new matrix[ROWS][COLUMNS];
m = loadmat(FILENAME);
day = new matrix[1][NUMBEROFDAYS];
dayPercent = new matrix[1][NUMBEROFDAYS];
parcel = new matrix[1][PARCELS];
parcelPercent = new matrix[1][PARCELS];

for (i = 0 ; i < ROWS ; i++)
{
for (j = 0 ; j < NUMBEROFPARCELS ; j++) if (m[i][HOUR] == OPEN+j) parcel[0][j] += m[i][VOLUME];

for (k = 0 ; k < NUMBEROFDAYS ; k++) if (m[i][DAY] == k+1) day[0][k] += m[i][VOLUME];

liquidity += m[i][VOLUME];
}

for (i = 0 ; i < PARCELS ; i++) parcelPercent[0][i] = parcel[0][i] / liquidity;
for (i = 0 ; i < NUMBEROFDAYS ; i++) dayPercent[0][i] = day[0][i] / liquidity;

fileParcel = fopen(PARCELOUTPUT,"w&quot;);
fileDay = fopen(DAYOUTPUT,"w&quot;);

for (i = 0 ; i < NUMBEROFPARCELS ; i++)
{
print("\nLiquidity from ", OPEN+i, " to ", OPEN+i+1, " is ", parcel[0][i], " which is ", parcelPercent[0][i]*100, " percent&quot;);
fprint(fileParcel, "\nLiquidity from ", OPEN+i, " to ", OPEN+i+1, " is ", parcel[0][i], "," ,parcelPercent[0][i]*100);
}

for (i = 0 ; i < NUMBEROFDAYS ; i++)
{
print("\nLiquidity on day ", i+1, " is ", day[0][i], " which is ", dayPercent[0][i]*100, " percent&quot;);
fprint(fileDay, "\nLiquidity on day ", i+1, " is,", day[0][i], "," ,dayPercent[0][i]*100);
}
}



Xem đầy đủ bài viết tại http://feedproxy.google.com/~r/TaiTran/~3/uTOYcLcO-1Q/intraday-liquidity-pattern-calculation-using-ox.html

No comments:

Post a Comment

Popular Posts