フィルターのクリア

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

4 ビュー (過去 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 Center および File ExchangeTransaction Cost Analysis についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by