%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% IDENTIFICATION OF THE RE-USE OF COLLATERAL BASED ON TRANSACTION DATA

% Algorithm described in: 
% - Lucas Marc Fuhrer, Basil Guggenheim and Silvio Schumacher: Re-use of collateral in the repo market, Journal of Money, Credit and Banking.
% - Lucas Marc Fuhrer, Basil Guggenheim and Silvio Schumacher (2015): Re-use of collateral in the repo market, SNB Working Paper 2015-2.

% Authors: Lucas Marc Fuhrer, Basil Guggenheim and Silvio Schumacher

% MATLAB Version 2014a

% Name of file: "StartFile.m"
% Additional functions:
% - "a_matching.m"
% - "b_preparation.m"
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


% 1. Prepare the dataset
% The transaction data needs to contain the following variables, all saved in double format:
% 1: Repo ID 
% 2: Unique ID for ISIN
% 3: Purchase Date
% 4: Repurchase Date  
% 5: Cash Taker ID 
% 6: Cash Provider ID
% 7: Cash Amount in CHF 
% 8: Duration of transaction (in days)
% 9: Rating of ISIN (ID)
% 10: Repo rate in per cent

% 2. Insert the data in a matrix named "Qdata" (double format)

% 3. Save the data in a Matlab mat-file (e.g. "filename.mat")

% 4. Insert the following parameters in "StartFile.m":
% - Name: serves as suffix for the data to save and as filename of input data (e.g. "filename.mat")
% - Working Directory (where all functions are saved)
% - Directory to save the data


% 5. Run the start file 
% The message 'Calculation has been successful' should occur after a successfull job

% 6. Retrieve the output data in the matrix named "QdataEx" (double format), which contains the following variables:
% 1: Repo ID 
% 2: Unique ID for ISIN
% 3: Purchase Date
% 4: Repurchase Date  
% 5: Cash Taker ID 
% 6: Cash Provider ID
% 7: Cash Amount in CHF 
% 8: Duration of transaction (in days)
% 9: Rating of ISIN (ID)
% 10: Repo rate in per cent
% 11: Value of re-use in transaction i
% 12: Sum of total re-use which is based on initial transaction i 
% 13: Dummy, if there is a re-use of collateral in transaction i 
% 14: Count of re-used transactions per initial transaction i 
% (the data is saved in "b_preparation.mat")

% 7. That's it.



