trade sign(buy or sell) for a stock based on simple trade data

1 visualización (últimos 30 días)
Zlatan Sacic
Zlatan Sacic el 16 de Mayo de 2022
Editada: Zlatan Sacic el 7 de Jun. de 2022
Hello,
I need help to write a simple "loop" or "if" function or a combination of both to identify what trade classification a stock transaction is: "buy", "sell" and possibly "not classifiable".

Respuestas (1)

Sailesh Kalyanapu
Sailesh Kalyanapu el 19 de Mayo de 2022
It is my understanding that you are trying to identify what trade classification a stock transaction is based on the two rules mentioned above in the question.
% Assuming you have the data loaded as a Table in a variable named data_sub
% The logic would look something like this
Total_buy_trades = 0;
Total_sell_trades = 0;
Total_not_classifiable_trades = 0;
for i = 1:height(data_sub)
% Extracting information about oen instance from the table
Ask = data_sub.prevailing_ask(i);
Bid = data_sub.prevailing_bid(i);
price = data_sub.price(i);
mid_quote = (Ask+Bid)/2;
% Quote Rule
if price > mid_quote
Total_buy_trades = Total_buy_trades + 1;
elseif price < mid_quote
Total_sell_trades = Total_sell_trades + 1;
else
% Tick Rule
% Finding Last_trade_price
Last_traded_price = price; %Initially assigning to the current value
for j = i:-1:1
if data_sub.price(j) ~= price
Last_traded_price = data_sub.price(j);
break;
end
end
if price > Last_traded_price
Total_buy_trades = Total_buy_trades + 1;
elseif price < Last_traded_price
Total_sell_trades = Total_sell_trades + 1;
end
end
end
  1 comentario
Sailesh Kalyanapu
Sailesh Kalyanapu el 20 de Mayo de 2022
Hey Zlatan! Can you check if the Tick rule code you mentioned in the above comment is correct? Because it is increasing the Sell count in both the cases, i.e. when price(x)>price(y) and price(x)<price(y)

Iniciar sesión para comentar.

Categorías

Más información sobre Transaction Cost Analysis en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by