Filter löschen
Filter löschen

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

4 Ansichten (letzte 30 Tage)
Zlatan Sacic
Zlatan Sacic am 16 Mai 2022
Bearbeitet: Zlatan Sacic am 7 Jun. 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".

Antworten (1)

Sailesh Kalyanapu
Sailesh Kalyanapu am 19 Mai 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 Kommentar
Sailesh Kalyanapu
Sailesh Kalyanapu am 20 Mai 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)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Transaction Cost Analysis finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by