Message Boards Message Boards

0
|
4052 Views
|
4 Replies
|
2 Total Likes
View groups...
Share
Share this post:

How to convert a variable to a string with quote marks around it

Posted 2 years ago
POSTED BY: Raymond Low
4 Replies

To my extreme annoyment, in StandardForm the quote marks are invisible, but they are there:

lisVol = {AA, AAL, AAPL, ABNB};
Map[ToString, lisVol] // InputForm

To my further annoyment, when copying and pasting strings, sometimes the invisible quotes are copied, sometimes not.

POSTED BY: Gianluca Gorni
Posted 2 years ago
POSTED BY: Rohit Namjoshi
Posted 2 years ago

Hi Gianluca,

Yes, it is annoying, I have learned to live with it. There is an option ShowStringCharacters that can be changed from the options inspector but it changes the behavior for Input cells, not Output cells.

POSTED BY: Rohit Namjoshi
Posted 2 years ago

Thank you Gianluca -- your solution worked visually, but not in FinancialData[] . I used FinancialData[] to download a group of stock tickers. A list appears with tickers with invisible quotation marks. I triple click a ticker with the invisible quotation marks and paste it and the quotation marks appear where pasted. The paste works in FinancialData[] getting the stock price and the list of tickers with invisible quotation marks works equally well.

list ={"NASDAQ:ASTC", "NASDAQ:ATRO", "NASDAQ:AVAV", "NASDAQ:AXON", \ "NASDAQ:BYRN", "NASDAQ:CODA", "NASDAQ:EH", "NASDAQ:ESLT", \ "NASDAQ:ISSC", "NASDAQ:IVAC", "NASDAQ:KTOS", "NASDAQ:MRCY", \ "NASDAQ:POWW", "NASDAQ:POWWP", "NASDAQ:RADA", "NASDAQ:SWBI", \ "NASDAQ:TATT", "NASDAQ:VSEC", "NASDAQ:VTSI", "NASDAQ:WWD", \ "NYSE:AIR", "NYSE:AIRI", "NYSE:AJRD", "NYSE:BA", "NYSE:BWXT", \ "NYSE:CAE", "NYSE:CVU", "NYSE:DCO", "NYSE:ERJ", "NYSE:FLY", \ "NYSE:GD", "NYSE:HEI", "NYSE:HEI-A", "NYSE:HII", "NYSE:HXL", \ "NYSE:KAMN", "NYSE:LHX", "NYSE:LMT", "NYSE:MOG-A", "NYSE:MOG-B", \ "NYSE:NOC", "NYSE:NPK", "NYSE:PKE", "NYSE:RGR", "NYSE:RTX", \ "NYSE:SIF", "NYSE:SPCE", "NYSE:SPR", "NYSE:TDG", "NYSE:TGI", \ "NYSE:TXT", "NYSE:UAVS", "NYSE:VEC"}

Copy -> Paste the invisible quotation mark appear here, but not in the workbook. I will try three lists. List1 -- WL see as symbols and only errors in FinancialData[], List2 -- using your code, WL see as strings only if I copy the quotation marks, if I double the ticker, the quotation marks are not captured. If I triple click the ticker, the whole line is highlighted. If I copy the ticker and quotation marks into FinancialData I get the stock price, but if I input the list of tickers, FinancialData does not recognize the list as tickers. List3 -- if I manually type quotation marks around each and every ticker without error, than FinancialData will recognize the list as tickers and I get their current price.

In[66]:= list1 = {AA, AAL, AAPL, ABNB, ABUS, ADI, AEO, AFRM, AMC, AMD, AMZN, ANY}

Out[66]= {AA, AAL, AAPL, ABNB, ABUS, ADI, AEO, AFRM, AMC, AMD, AMZN, ANY}

In[67]:= FinancialData[list1]

During evaluation of In[67]:= FinancialData::notent: AA is not a known entity, class, or tag for FinancialData. Use FinancialData[] for a list of entities.

During evaluation of In[67]:= FinancialData::notent: AAL is not a known entity, class, or tag for FinancialData. Use FinancialData[] for a list of entities.

During evaluation of In[67]:= FinancialData::notent: AAPL is not a known entity, class, or tag for FinancialData. Use FinancialData[] for a list of entities.

During evaluation of In[67]:= General::stop: Further output of FinancialData::notent will be suppressed during this calculation.

Out[67]= {Missing["NotAvailable"], Missing["NotAvailable"], Missing["NotAvailable"], 
 Missing["NotAvailable"], Missing["NotAvailable"], Missing["NotAvailable"], 
 Missing["NotAvailable"], Missing["NotAvailable"], Missing["NotAvailable"], 
 Missing["NotAvailable"], Missing["NotAvailable"], Missing["NotAvailable"]}

In[68]:= list2 = Map[ToString, list1] // InputForm

Out[68]//InputForm=
{"AA", "AAL", "AAPL", "ABNB", "ABUS", "ADI", "AEO", "AFRM", "AMC", "AMD", 
 "AMZN", "ANY"}

In[69]:= FinancialData[list2]

During evaluation of In[69]:= FinancialData::notent: {"AA", "AAL", "AAPL", "ABNB", "ABUS", "ADI", "AEO", "AFRM", "AMC", "AMD", <<2>>} is not a known entity, class, or tag for FinancialData. Use FinancialData[] for a list of entities.

Out[69]= Missing["NotAvailable"]

In[70]:= list3 = {"AA", "AAL", "AAPL", "ABNB", "ABUS", "ADI", "AEO", "AFRM", "AMC", 
  "AMD", "AMZN", "ANY"}

Out[70]= {"AA", "AAL", "AAPL", "ABNB", "ABUS", "ADI", "AEO", "AFRM", "AMC", "AMD", \
"AMZN", "ANY"}

In[71]:= FinancialData[list3]

Out[71]= {Quantity[47.5099983215332, "USDollars"], 
 Quantity[20.200000762939453`, "USDollars"], 
 Quantity[154.07000732421875`, "USDollars"], Quantity[166., "USDollars"], 
 Quantity[3.869999885559082, "USDollars"], 
 Quantity[168.80999755859375`, "USDollars"], 
 Quantity[26.899999618530273`, "USDollars"], 
 Quantity[92.05999755859375, "USDollars"], 
 Quantity[48.52000045776367, "USDollars"], 
 Quantity[106.1500015258789, "USDollars"], 
 Quantity[3484.159912109375, "USDollars"], 
 Quantity[7.190000057220459, "USDollars"]}

How would I code in the invisible quotation marks that FinancialData will recognize as tickers????

POSTED BY: Raymond Low
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract