Message Boards Message Boards

Stock allocation spreadsheet using EmbedCode

Posted 10 years ago

Let's assume that we have a spreadsheet that has the various stocks and number of shares of each stock that we own. I want to make a pie chart that shows how my wealth is distributed amongst my stocks. To do this, I will make use of an embedded api functions that calls the WolframCloud to get current stock prices.

First, we'll deploy an APIFunction that returns the price of the stocks.

 co = CloudDeploy[APIFunction["comp" -> "Company", FinancialData[#comp] &], Permissions -> "Public"]

Let's make sure that this works in Mathematica using URLExecute with a selected company name:

In[23]:= URLExecute[co, {"comp" -> "aapl"}]

Out[23]= 116.64

That looks correct. Next, call EmbedCode with option "Googledocs" to get a function that can be called within our spreadsheet

EmbedCode[co, "GoogleDocs"]

Copy the returned code to the "script editor" of your google spreadsheet. The default name of the function is wolframCloudCall, which I don't change. Now, to get a result, I need to type =wolframCloudCall(-cell with company name-) into a cell, and the result will be returned to that cell.

enter image description here

I have created a Google Spreadsheet that has several stocks that I'm pretending to own. The spreadsheet with pie chart (created using columns A and B) now look like this, where column C contains the function calls to WolframCloud. enter image description here

POSTED BY: Chad Knutson
5 Replies
POSTED BY: Chad Knutson
POSTED BY: Chad Knutson

Hello Chad, nice example thanks, In the Mathematica help "GoogleDocs" is not mentioned yet. Only when I use $EmbedCodeEnvironments it is mentioned.

One of the things I am searching for is how make just one cloud function call, get a list of lists returned and then show every value in its own cell.

The questions is how to show a matrix type result in each in its own spreadsheet cell. This would speed up the results since the communication overhead per cloud call is quite high.

Do you know how to do this in a Google spreadsheet or in a XL spreadsheet.

Hi Pieter,

I'm sure this can be done, but right now I don't know how. I'll post a solution when I have it.

Returning values in across multiple cells can be done in a google spreadsheet using arrayformula (e.g., =arrayformula(a1:a2) will return the values of cells a1 and a2 in 2 different cells). Surely excel has something similar.

Now to tie this all together....

POSTED BY: Chad Knutson
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