9.6. Setting Share Price

The value of a commodity, such as a stock, must be explicitly set. The stock accounts track the quantity of stocks you own, but the value of the stock is stored in the Price Database. The values set in the Price Database can be updated manually or automatically.

9.6.1. Initial Price Database Setup

To use the Price Database to track a stock value, you must initially insert the stock. To do so, open the Price Database (ToolsPrice Database) and click on Add button. The first time a Commodity/Stock is entered this window will be blank except for the control buttons on the bottom. Select the appropriate Commodity you want to insert into the Price Database. At this point, you can input the price of the commodity manually. There are 6 fields in the New Commodity window:

Namespace

The exchange market where the security/commodity is traded (in this example NASDAQ.)

Security

The name of the commodity, must be chosen from the Select... list.

Currency

The currency in which the Price is expressed.

Date

Date that the price is valid.

Type

One of: Bid (the market buying price), Ask (the market selling price), Last (the last transaction price), Net Asset Value (mutual fund price per share, NAV for short), or Unknown. Stocks and currencies will usually give their quotes as one of bid, ask or last. Mutual funds are often given as net asset value. For other commodities, simply choose Unknown. This option is for informational purposes only, it is not used by GnuCash.

Price

The price of one unit of this commodity.

As an example of adding the AMZN commodity to the price database, with an initial value of $40.50 per share.

Price Database

Adding the AMZN commodity to the price database, with an initial value of $40.50 per share.

Click OK when finished. Once you have performed this initial placement of the commodity into the Price Database, you will not have to do it again, even if you use the same commodity in another account.

Note

If you have online retrieval of quotes activated (see Section 9.6.3, “Configuring for Automatic Retrieval of Quotes”), you can initialize a commodity without manually making an entry. When you initially add the security in the Security Editor, check Get Online Quotes and save the security. Then, in the Price Database, click Get Quotes, and the new security will be inserted into the price list with the retrieved price.

9.6.2. Setting Stock Price Manually

If the value of the commodity (stock) changes, you can adjust the value by entering the Price Database, selecting the commodity, clicking on Edit and entering the new price.

Price Database

The main price database window, showing the list of all known commodities.

9.6.3. Configuring for Automatic Retrieval of Quotes

If you have more than a couple of commodities, you will tire of having to update their prices constantly. GnuCash has the ability to automatically download the most recent price for your commodities using the Internet. This is accomplished through the Perl module Finance::Quote, which must be installed in order to activate this feature.

To determine if the Perl module Finance::Quote is already installed on your system, type perldoc Finance::Quote in a terminal window and check to see if there is any documentation available. If you see the documentation, then the module is installed, if you do not see the documentation, then it has not been installed.

9.6.3.1. Installing Finance::Quote

The process of installing Finance::Quote depends on the system.

Procedure 9.1. Installing Finance::Quote on Linux

  1. Close GnuCash.

  2. Run the command which gnc-fq-update to check gnc-fq-update program is in your PATH environment variable.[2]

    1. If gnc-fq-update is not in your PATH, search the folder where GnuCash is installed.

  3. Run the command sudo gnc-fq-update or su -c gnc-fq-update in order to run it with root privilege. It depends on your distribution. If gnc-fq-update is not in your PATH, specify full path of gnc-fq-update instead, which is found by Step 2.a.

    This will launch a Perl CPAN[3] module internally. When you launch the CPAN module for the first time, you must setup and configure it. However, on the most systems if you accept the default settings or answer the first question Are you ready for manual configuration? [yes] with no, you will be able to install Finance::Quote successfully.

  4. Run gnc-fq-dump to check Finance::Quote works properly.

Procedure 9.2. Installing Finance::Quote on macOS

  1. Close GnuCash.

  2. Install Xcode if it is not installed.

    XCode is an optional item from your macOS distribution DVD.

  3. Run the Update Finance Quote app in the GnuCash dmg.

    You can run it from the dmg or copy it to the same folder to which you copied GnuCash. It will open a Terminal window and run a script for you which will ask lots of questions. Accept the default for each unless you know what you’re doing.

Procedure 9.3. Installing Finance::Quote on Windows

  1. Close GnuCash.

  2. Run StartGnuCashInstall Online Price Retrieval.

Note

If you feel uncomfortable about performing any of these steps, please either email the GnuCash-user mailing list () for help or come to the GnuCash IRC channel on irc.gnome.org. You can also leave out this step and manually update your stock prices.

9.6.3.2. Configuring Securities for Online Quotes

With Finance::Quote installed and functioning correctly, you must configure your GnuCash securities to use this feature to obtain updated price information automatically. Whether creating new securities or modifying securities that have already been setup, use the ToolsSecurity Editor, to edit the security and check the Get Online Quotes box. You will now be able to modify the radio buttons for Type of quote source, the pull-down menus to specify the specific source(s) and The timezone for these quotes. When finished editing, Close the Security Editor to return to the Price Database and click on the Get Quotes button to update your stock prices on the Internet.

The command gnucash-cli --quotes get ${HOME}/gnucash-filename[4] can be used to fetch the current prices of your stocks. The file specified ${HOME}/gnucash-filename will depend on the name and location of your data file. This can be determined by the name displayed in the top frame of the GnuCash window, before the -. The file name can also be found under File in the recently opened file list; the first item, numbered 1, is the name of the currently open file.

9.6.3.3. Configuring for Getting Online Quotes Periodically

You have to register the gnucash-cli with a scheduler in order to get Online Quotes automatically and periodically. The method depends on your OS. For example, suppose you want to update your file on 16:00 on every Friday.

Procedure 9.4. Register gnucash-cli with cron on Linux and macOS

  1. Run crontab -e.

  2. Add the following line to your crontab:

    0 16 * * 5 gnucash-cli --quotes get ${HOME}/gnucash-filename > /dev/null 2>&1

Procedure 9.5. Register gnucash-cli with Task Scheduler on Windows

  1. Select StartWindows Administrative ToolsTask Scheduler.

  2. Select Create Task.

  3. Enter the appropirate items on Create Task Window.

See GnuCash Help Manual and Online Quotes Page on GnuCash Wiki for more details.

Remember that Mutual Fund prices are really Net Asset Value and require several hours after the exchange closes before being available. If NAVs are downloaded before the current days NAVs are determined, yesterday’s NAVs are retrieved.

9.6.4. Displaying Share Value

The main account window, by default, only shows the quantity of each commodity that you own, under the column heading Total. In the case of stocks, this commodity is the number of shares. Often, however, you will want to see the value of your stocks expressed in terms of some monetary unit. This is easily accomplished by entering the main window, selecting the Accounts tab, by clicking on the Titlebar Options button (the small down pointing arrow on the right side of the main account window titles bar), and selecting the option to display the account total field Total (USD). You will see a new column in the main window entitled Total (USD) that will express the value of all commodities in the report currency.

Viewing Stock Value

Viewing the value of a stock commodity in the main window using the Total in Report Currency option.

9.6.5. The Price Source in Reports

Most GnuCash reports have options to set/modify a number of parameters for the report. The Options dialog box is displayed by selecting the report tab, then ether clicking on the Options icon in the Menubar or selecting EditReport Options. Price Source determines how accounts denominated in commodities different from the report currency are converted to the report currency. Depending on the report the selector may appear in either the General, the Commodities, or the Display tab of the Report Options dialog box.

Note

In the example the report can be customized using the ReportsAssets & LiabilitiesAverage Balance menu.

Determining Stock Price/Currency Exchange Rate Source in Reports

Determining the value of a stock commodity or a currency other than the report currency in a report by setting the Price Source option.

Weighted Average

Calculates the price by summing the absolute value of the amount and the absolute value of every split in every account denominated in the commodity, excluding those splits with a zero amount, and dividing the sum of values by the sum of amounts to obtain a price. For example, if you had a buy transaction for 200 shares of XYZ for a total of 2000 and a sell of 100 for 1300 the weighted average would be 3300/300 or 11/share.

Note

Gain/Loss splits have an amount of 0 and are not included in this calculation.

Average Cost

Calculates the price by summing the amounts and values of every split in every account denominated in the commodity, including the zero amount splits. In the example above, with an additional split (either part of the sale transaction or in a separate transaction) booking the gain at 0 shares and a 300 gain, the average cost is 1000/100 (2000 original cost − 1300 proceeds from the sale + 300 gain)/(200 − 100) shares or 10/share.

Note
  • Gain/Loss splits are included in this calculation.
  • This is the only Price Source that will balance the Trial Balance Report and in order for it to balance you must correctly book your gains and losses.

Most Recent

Uses the latest price from the price database.

Nearest in time

Uses the price nearest in time to the report date—the datum date for time series reports like Assets Over Time—from the price database.

Note

The nearest date isn’t necessarily before the date in question.

An Asset Barchart Report based on the Nearest in time Price Source.

Tracking what value your stocks would’ve had on the stock exchanges.



[2] If you’ve installed GnuCash packages provided by your distribution, gnc-fq-update must be on your PATH.

[4] The Online Quotes Retrieval command has been changed from GnuCash 4.0. The old command gnucash --add-price-quotes ${HOME}/gnucash-filename is still available, but it is deprecated and will be removed in the future release. If you've upgraded from GnuCash 3.11 or previous version, it is recommended to use the new command gnucash-cli.