piecash.core.factories module — Python interface to GnuCash documents 0.15.0 documentation

# piecash.core.factories module

`piecash.core.factories.` `create_stock_accounts`(cdty, broker_account, income_account=None, income_account_types='D/CL/I')

  Create the multiple accounts used to track a single stock, ie:

  - broker_account/stock.mnemonic

  and the following accounts depending on the income_account_types argument

  - D = Income/Dividend Income/stock.mnemonic
  - CL = Income/Cap Gain (Long)/stock.mnemonic
  - CS = Income/Cap Gain (Short)/stock.mnemonic
  - I = Income/Interest Income/stock.mnemonic

  Parameters: | broker_account (`piecash.core.account.Account`) – the broker account where the account holding stock is to be created (the) – income_account (`piecash.core.account.Account`) – the income account where the accounts holding income related to the stock are to be created (the) – income_account_types (str) – “/” separated codes to drive the creation of income accounts
  Returns: | a tuple with the account under the broker_account where the stock is held and the list of income accounts.
  Return type: | `piecash.core.account.Account`

`piecash.core.factories.` `create_currency_from_ISO`(isocode)

  Factory function to create a new currency from its ISO code

  Parameters: | isocode (str) – the ISO code of the currency (e.g. EUR for the euro)
  Returns: | the currency as a commodity object
  Return type: | `Commodity`

`piecash.core.factories.` `create_stock_from_symbol`(symbol, book=None)

  Factory function to create a new stock from its symbol. The ISO code of the quoted currency of the stock is stored in the slot “quoted_currency”.

  Parameters: | symbol (str) – the symbol for the stock (e.g. YHOO for the Yahoo! stock)
  Returns: | the stock as a commodity object
  Return type: | `Commodity`

  Note

  The information is gathered from the yahoo-finance package The default currency in which the quote is traded is stored in a slot ‘quoted_currency’

  Todo

  use ‘select * from yahoo.finance.sectors’ and ‘select * from yahoo.finance.industry where id =”sector_id”’ to retrieve name of stocks and allow therefore the creation of a stock by giving its “stock name” (or part of it). This could also be used to retrieve all symbols related to the same company