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

조회 수: 1 (최근 30일)
Zlatan Sacic
Zlatan Sacic 2022년 5월 16일
편집: Zlatan Sacic 2022년 6월 7일
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".

답변 (1개)

Sailesh Kalyanapu
Sailesh Kalyanapu 2022년 5월 19일
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
Sailesh Kalyanapu
Sailesh Kalyanapu 2022년 5월 20일
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)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Transaction Cost Analysis에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by