TAQ Trade Shift

The relative position between returns and trade signs directly impact the result of the response functions. Shifting the values to the right or to the left either in trade time scale or physical time scale have approximately the same effect.

To run this part of the code is necessary to have the results from the module TAQ Responses Trade.

Modules

The code is divided in four parts:
  • Tools: some functions for repetitive actions.
  • Analysis: code to analyze the data.
  • Plot: code to plot the data.
  • Main: code to run the implementation.

Tools

TAQ data tools module.

The functions in the module do small repetitive tasks, that are used along the whole implementation. These tools improve the way the tasks are standardized in the modules that use them.

This script requires the following modules:
  • matplotlib
  • os
  • pandas
  • pickle
The module contains the following functions:
  • taq_save_data - saves computed data.
  • taq_save_plot - saves figures.
  • taq_function_header_print_data - prints info about the function running.
  • taq_function_header_print_plot - prints info about the plot.
  • taq_start_folders - creates folders to save data and plots.
  • taq_initial_message - prints the initial message with basic information.
  • taq_business_days - creates a list of week days for a year.
  • main - the main function of the script.
taq_data_tools_trade_shift.main()[source]

The main function of the script.

The main function is used to test the functions in the script.

Returns:None.
taq_data_tools_trade_shift.taq_bussiness_days(year)[source]

Generates a list with the dates of the bussiness days in a year

Parameters:year – string of the year to be analyzed (i.e ‘2008’).
Returns:list.
taq_data_tools_trade_shift.taq_function_header_print_data(function_name, ticker_i, ticker_j, year, month, day)[source]

Prints a header of a function that generates data when it is running.

Parameters:
  • function_name – name of the function that generates the data.
  • ticker_i – string of the abbreviation of the stock to be analyzed (i.e. ‘AAPL’).
  • ticker_j – string of the abbreviation of the stock to be analyzed (i.e. ‘AAPL’).
  • year – string of the year to be analyzed (i.e ‘2016’).
  • month – string of the month to be analyzed (i.e ‘07’).
  • day – string of the day to be analyzed (i.e ‘07’).
Returns:

None – The function prints a message and does not return a value.

taq_data_tools_trade_shift.taq_function_header_print_plot(function_name, ticker_i, ticker_j, year, month, day)[source]

Prints a header of a function that generates a plot when it is running.

Parameters:
  • function_name – name of the function that generates the plot.
  • ticker_i – string of the abbreviation of the stock to be analyzed (i.e. ‘AAPL’).
  • ticker_j – string of the abbreviation of the stock to be analyzed (i.e. ‘AAPL’).
  • year – string of the year to be analyzed (i.e ‘2016’).
  • month – string of the month to be analyzed (i.e ‘07’).
  • day – string of the day to be analyzed (i.e ‘07’).
Returns:

None – The function prints a message and does not return a value.

taq_data_tools_trade_shift.taq_initial_message()[source]

Prints the initial message with basic information.

Returns:None – The function prints a message and does not return a value.
taq_data_tools_trade_shift.taq_save_data(function_name, data, ticker_i, ticker_j, year, month, day)[source]

Saves computed data in pickle files.

Saves the data generated in the functions of the taq_data_analysis_trade_shift module in pickle files.

Parameters:
  • function_name – name of the function that generates the data.
  • data – data to be saved. The data can be of different types.
  • ticker_i – string of the abbreviation of the stock to be analyzed (i.e. ‘AAPL’).
  • ticker_j – string of the abbreviation of the stock to be analyzed (i.e. ‘AAPL’).
  • year – string of the year to be analyzed (i.e ‘2016’).
  • month – string of the month to be analyzed (i.e ‘07’).
  • day – string of the day to be analyzed (i.e ‘07’).
Returns:

None – The function saves the data in a file and does not return a value.

taq_data_tools_trade_shift.taq_save_plot(function_name, figure, ticker_i, ticker_j, year, month)[source]

Saves plot in png files.

Saves the plot generated in the functions of the taq_data_plot_trade_shift module in png files.

Parameters:
  • function_name – name of the function that generates the plot.
  • figure – figure object that is going to be save.
  • ticker_i – string of the abbreviation of the stock to be analyzed (i.e. ‘AAPL’).
  • ticker_j – string of the abbreviation of the stock to be analyzed (i.e. ‘AAPL’).
  • year – string of the year to be analyzed (i.e ‘2016’).
  • month – string of the month to be analyzed (i.e ‘07’).
Returns:

None – The function save the plot in a file and does not return a value.

taq_data_tools_trade_shift.taq_start_folders(year)[source]

Creates the initial folders to save the data and plots.

Parameters:year – string of the year to be analyzed (i.e ‘2016’).
Returns:None – The function creates folders and does not return a value.

Analysis

TAQ data analysis module.

The functions in the module analyze the data from the NASDAQ stock market, computing the self- and cross-response functions.

This script requires the following modules:
  • itertools
  • multiprocessing
  • numpy
  • pandas
  • tickle
  • taq_data_tools_trade_shift
The module contains the following functions:
  • taq_self_response_day_trade_shift_data - computes the self response of a day.
  • taq_self_response_year_trade_shift_data - computes the self response of a year.
  • taq_cross_response_day_trade_shift_data - computes the cross response of a day.
  • taq_cross_response_year_trade_shift_data - computes the cross response of a year.
taq_data_analysis_trade_shift.main()[source]

The main function of the script.

The main function is used to test the functions in the script.

Returns:None.
taq_data_analysis_trade_shift.taq_cross_response_day_trade_shift_data(ticker_i, ticker_j, date, tau)[source]

Computes the cross-response of a day.

Using the midpoint price of ticker i and trade signs of ticker j computes the cross-response during different trade shifts for a day. There is a constant \(\tau\) that most be set in the parameters.

Parameters:
  • ticker_i – string of the abbreviation of the stock to be analyzed (i.e. ‘AAPL’).
  • ticker_j – string of the abbreviation of the stock to be analyzed (i.e. ‘AAPL’).
  • date – string with the date of the data to be extracted (i.e. ‘2008-01-02’).
  • tau – integer great than zero (i.e. 50).
Returns:

tuple – The function returns a tuple with numpy arrays.

taq_data_analysis_trade_shift.taq_cross_response_year_trade_shift_data(ticker_i, ticker_j, year, tau)[source]

Computes the cross response of a year.

Using the taq_cross_response_day_trade_shift_data function computes the cross-response function for a year.

Parameters:
  • ticker_i – string of the abbreviation of the stock to be analyzed (i.e. ‘AAPL’).
  • ticker_j – string of the abbreviation of the stock to be analyzed (i.e. ‘AAPL’).
  • year – string of the year to be analyzed (i.e ‘2016’).
  • tau – integer great than zero (i.e. 50).
Returns:

tuple – The function returns a tuple with numpy arrays.

taq_data_analysis_trade_shift.taq_self_response_day_trade_shift_data(ticker, date, tau)[source]

Computes the self-response of a day.

Using the midpoint price and trade signs of a ticker computes the self- response during different trade shifts for a day. There is a constant \(\tau\) that most be set in the parameters.

Parameters:
  • ticker – string of the abbreviation of the stock to be analyzed (i.e. ‘AAPL’).
  • date – string with the date of the data to be extracted (i.e. ‘2008-01-02’).
  • tau – integer great than zero (i.e. 50).
Returns:

tuple – The function returns a tuple with numpy arrays.

taq_data_analysis_trade_shift.taq_self_response_year_trade_shift_data(ticker, year, tau)[source]

Computes the self response of a year.

Using the taq_self_response_day_trade_shift_data function computes the self-response function for a year.

Parameters:
  • ticker – string of the abbreviation of stock to be analyzed (i.e. ‘AAPL’).
  • year – string of the year to be analyzed (i.e ‘2016’).
  • tau – integer great than zero (i.e. 50).
Returns:

tuple – The function returns a tuple with numpy arrays.

Plot

TAQ data plot module.

The functions in the module plot the data obtained in the taq_data_analysis_trade_shift module.

This script requires the following modules:
  • matplotlib
  • numpy
  • pickle
  • taq_data_tools_trade_shift
The module contains the following functions:
  • taq_self_response_year_avg_trade_shift_plot - plots the self-response average for a year.
  • taq_cross_response_year_avg_trade_shift_plot - plots the cross-response average for a year.
  • main - the main function of the script.
taq_data_plot_trade_shift.main()[source]

The main function of the script.

The main function is used to test the functions in the script.

Returns:None.
taq_data_plot_trade_shift.taq_cross_response_year_avg_trade_shift_plot(ticker_i, ticker_j, year, taus)[source]

Plots the cross-response average for a year.

Parameters:
  • ticker_i – string of the abbreviation of the stock to be analyzed (i.e. ‘AAPL’)
  • ticker_j – string of the abbreviation of the stock to be analyzed (i.e. ‘AAPL’)
  • year – string of the year to be analyzed (i.e ‘2008’)
  • taus – list of integers greater than zero (i.e. [1, 10, 50]).
Returns:

None – The function saves the plot in a file and does not return a value.

taq_data_plot_trade_shift.taq_self_response_year_avg_trade_shift_plot(ticker, year, taus)[source]

Plots the self-response average for a year.

Parameters:
  • ticker – string of the abbreviation of the stock to be analyzed (i.e. ‘AAPL’).
  • year – string of the year to be analyzed (i.e ‘2008’).
  • taus – list of integers greater than zero (i.e. [1, 10, 50]).
Returns:

None – The function saves the plot in a file and does not return a value.

Main

TAQ data main module.

The functions in the module run the complete analysis and plot of the TAQ data for the trade shift between returns and trade signs. To run this module it is necessary to have the files of the midpoint prices for trade time scale from the TAQ Responses Physical module and the trade signs for trade time scale from the TAQ Responses Trade module.

This script requires the following modules:
  • itertools
  • multiprocessing
  • pandas
  • taq_data_analysis_trade_shift
  • taq_data_plot_trade_shift
  • taq_data_tools_trade_shift
The module contains the following functions:
  • taq_data_plot_generator - generates all the analysis and plots from the TAQ data.
  • main - the main function of the script.
taq_data_main_trade_shift.main()[source]

The main function of the script.

The main function is used to test the functions in the script.

Returns:None.
taq_data_main_trade_shift.taq_data_plot_generator(tickers, year, taus)[source]

Generates all the analysis and plots from the TAQ data.

Parameters:
  • tickers – list of the string abbreviation of the stocks to be analyzed (i.e. [‘AAPL’, ‘MSFT’]).
  • year – string of the year to be analyzed (i.e ‘2016’).
  • taus – list of integers greater than zero (i.e. [1, 10, 50]).
Returns:

None – The function saves the data in a file and does not return a value.