Putting data into tables and looping over it

1 vue (au cours des 30 derniers jours)
Or Shem Tov
Or Shem Tov le 4 Mar 2020
Hi guys,
I am trying to run over a set of structured headlines and detect the issuer written in the headline.
I managed to write a code that will detect the issuer using a dictionary, I just need a little help on putting the data together systematically and looping over it efficiently.
Here's the code:
Import text to match an issuer to
document1 = "Analyst Actions: Citigroup Cuts Fiverr International's Price Target to $22 From $31, Reiterates Neutral Rating"
document2 = "Analyst Actions: JPMorgan Downgrades Beyond Meat to Neutral From Overweight, Cuts Price Target to $134 From $138"
document3 = "Analyst Actions: Credit Suisse Raises Beyond Meat's Price Target to $125 From $115; Keeps Neutral Rating"
document4 = "Analyst Actions: Oppenheimer Initiates Coverage on Beyond Meat With Perform Rating"
document5 = "Analyst Actions: Morgan Stanley Trims GoPro's Price Target to $3.50 From $4.50, Maintains Underweight Rating"
document6 = "GoPro downgraded by Zacks Investment Research to strong sell. $3.75 PT. (NASDAQ:GPRO)"
data = table(document1,document2,document3,document4,document5,document6)
data(:,2) % reference the 2nd column of data
data{:,2} % takes the content of the 2nd column of data
List of issuers
issuer = ["JPMorgan";
"Citigroup";
"Credit Suisse";
"Oppenheimer";
"Morgan Stanley";
"Zacks";
"UBS"]
Loop to find the issuer
for i = 1:size(issuer)
if (contains(document6,issuer(i)))
x = issuer(i)
else
nomatch = "No match."
end
end
I basically would want to put the data in a table and instead of document6 in the loop replace it with the corresponding document (headline) to scan.
In the end I need to collect the write answers (x) and put it next to the original headline as final data.
Would appreciate your help.
Thank you!

Réponses (1)

kgrunden
kgrunden le 4 Nov 2020
If the table is reoriented to have the documents in a single row, instead each in a column, it possible to iterate the table and place the answer another column.
doc = {document1, document2, document3, document4, document5, document6}';
data = table(doc);
for j = 1:size(doc)
for i = 1:size(issuer)
if (contains(doc{j}, issuer(i)))
issuerCol(j) = issuer(i);
break;
else
issuerCol(j) = "No match.";
end
end
end
data.issuer = issuerCol'
Executing the code then gives:
data =
6×2 table
doc issuer
______________________________________________________________________________________________________________________ ________________
{["Analyst Actions: Citigroup Cuts Fiverr International's Price Target to $22 From $31, Reiterates Neutral Rating" ]} "Citigroup"
{["Analyst Actions: JPMorgan Downgrades Beyond Meat to Neutral From Overweight, Cuts Price Target to $134 From $138"]} "JPMorgan"
{["Analyst Actions: Credit Suisse Raises Beyond Meat's Price Target to $125 From $115; Keeps Neutral Rating" ]} "Credit Suisse"
{["Analyst Actions: Oppenheimer Initiates Coverage on Beyond Meat With Perform Rating" ]} "Oppenheimer"
{["Analyst Actions: Morgan Stanley Trims GoPro's Price Target to $3.50 From $4.50, Maintains Underweight Rating" ]} "Morgan Stanley"
{["GoPro downgraded by Zacks Investment Research to strong sell. $3.75 PT. (NASDAQ:GPRO)" ]} "Zacks"
>> data{3,:}
ans =
1×2 string array
"Analyst Actions: Credit Suisse Raises Beyond Meat's Price Tar?" "Credit Suisse"

Catégories

En savoir plus sur Financial Data Analytics dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by