Re: [GNC] How to "Get Quotes" for a specific day?

2023-01-02 Thread ml enquirer
Hi Michael,

I've faced the same problem. I use the gnucash python bindings and the
following script, to import prices from a text file which has date
(-MM-DD) and price with a new date on each line.

Hope it could be some use. As always, test it before deploying! Best wishes.

```python
import datetime
from gnucash import Session, Account, Split, GncCommodity, GncPrice

url = "personal.gnucash"

# Initialize Gnucash session
session = Session(url, True, False, False)
book = session.book
pdb = book.get_price_db()
comm_table = book.get_table()

# Define commodities
sec_gbp = GncCommodity(book,"Pound Sterling", "CURRENCY", "GBP", "826", 100)
sec_chf = GncCommodity(book,"Swiss Franc", "CURRENCY", "CHF", "756", 100)

def extractFXrateFromFile(filename,book,pdb,sec_base,sec_curr):
  with open(filename) as myFile :
for line in myFile.readlines() :
  splitLine = line.split(' ')
  y,m,d = (int(x) for x in splitLine[0].split("-"))

  price = GncPrice(book)
  price.set_time64( datetime.datetime(y,m,d) )
  value = price.get_value()
  value.denom = int( 1e10 )
  rate = float(splitLine[1])
  value.num = int( rate * 1e10 )
  price.set_value(value)
  price.set_currency( sec_curr )
  price.set_commodity( sec_base )
  pdb.add_price(price)

extractFXrateFromFile("chf_per_gbp.txt", book, pdb, sec_chf, sec_gbp)

session.save()
session.end()
session.destroy()
```

On Fri, Dec 30, 2022 at 5:19 AM  wrote:

> How can I tell GNU Cash to update its "Price Database" for all known
> currencies, stocks, bonds, mutual funds, etc for a *specific* day?
>
> I'm trying trying to prepare a report for a date in the past. I've set the
> `Options` for the report to `nearest in time` so that it will grab the
> prices for the commodities from the Price Database that are closest to the
> date of the report as possible.
>
>  *
> https://gnucash-docs-rst.readthedocs.io/en/latest/guide/C/ch_invest.html?highlight=price%20database#the-price-source-in-reports
>
> Well, I checked the Price Database, and I have gaps in the prices for some
> of my stocks. For many stocks, I don't have any prices defined for the day
> of the report. Therefore, my report may be inaccurate.
>
> I know that I can go to `Tools` -> `Price Database` and click the `Get
> Quotes` button. This will fetch the current quote (price) and add it to the
> Price Database for all defined currencies, stocks, bonds, mutual funds,
> etc. But that will fetch and add the prices for *today's date* only.
>
> How can I do the equivalent of `Get Quotes` but for a specific day in the
> *past*?
>
> (see also
> https://superuser.com/questions/1760157/how-to-get-quotes-for-all-currencies-and-stocks-for-a-specific-day-gnu-cash
> )
> ___
> gnucash-user mailing list
> gnucash-user@gnucash.org
> To update your subscription preferences or to unsubscribe:
> https://lists.gnucash.org/mailman/listinfo/gnucash-user
> -
> Please remember to CC this list on all your replies.
> You can do this by using Reply-To-List or Reply-All.
>
___
gnucash-user mailing list
gnucash-user@gnucash.org
To update your subscription preferences or to unsubscribe:
https://lists.gnucash.org/mailman/listinfo/gnucash-user
-
Please remember to CC this list on all your replies.
You can do this by using Reply-To-List or Reply-All.


Re: [GNC] How to "Get Quotes" for a specific day?

2022-12-29 Thread David T. via gnucash-user
I've used Google sheets to retrieve prices which can be imported into GnuCash. 
In the referenced message, it should be simple to set whatever date you want. 

https://lists.gnucash.org/pipermail/gnucash-user/2018-August/079430.html

⁣David T. ​

On Dec 30, 2022, 7:48 AM, at 7:48 AM, Geoff  wrote:
>No.
>
>As far as I know the Finance::Quote module that GnuCash uses has no 
>provision to fetch historical prices.
>
>If you are into scripting and web scraping, checkout Selenium which has
>
>a nice Python interface.
>
>Good luck!
>
>Geoff
>=
>P.S.  Always include gnucash-user@gnucash.org on all correspondence.
>
>On 30/12/2022 3:23 pm, gnucash_2...@michaelaltfield.net wrote:
>>> 2. Import from a CSV file:-
>>>(File / Import / Import prices from a CSV file)
>> 
>> OK, Is there a way that I can generate this CSV file using
>`gnc-fq-dump` or `gnucash-cli` or similar so that I can script
>something to fetch/generate a CSV file and then import that CSV file
>for all my stocks for a specific date?
>> 
>> On Fri, Dec 30, 2022 at 03:25:02PM +1100, Geoff wrote:
>>> Hi Michael
>>>
>>> You can't do this.
>>>
>>> Alternatives:-
>>> 1. Key the prices directly into the Price Database:-
>>> (Tools / Price Data Database / Add)
>>> 2. Import from a CSV file:-
>>> (File / Import / Import prices from a CSV file)
>>>
>>> Historical prices are available from, inter alia,
>https://finance.yahoo.com/
>>>
>>>
>>> Regards
>>>
>>> Geoff
>>> =
>>>
>>> On 30/12/2022 3:06 pm, gnucash_2...@michaelaltfield.net wrote:
 How can I tell GNU Cash to update its "Price Database" for all
>known currencies, stocks, bonds, mutual funds, etc for a *specific*
>day?

 I'm trying trying to prepare a report for a date in the past. I've
>set the `Options` for the report to `nearest in time` so that it will
>grab the prices for the commodities from the Price Database that are
>closest to the date of the report as possible.

*
>https://gnucash-docs-rst.readthedocs.io/en/latest/guide/C/ch_invest.html?highlight=price%20database#the-price-source-in-reports
 Well, I checked the Price Database, and I have gaps in the prices
>for some of my stocks. For many stocks, I don't have any prices defined
>for the day of the report. Therefore, my report may be inaccurate.

 I know that I can go to `Tools` -> `Price Database` and click the
>`Get Quotes` button. This will fetch the current quote (price) and add
>it to the Price Database for all defined currencies, stocks, bonds,
>mutual funds, etc. But that will fetch and add the prices for *today's
>date* only.

 How can I do the equivalent of `Get Quotes` but for a specific day
>in the *past*?

 (see also
>https://superuser.com/questions/1760157/how-to-get-quotes-for-all-currencies-and-stocks-for-a-specific-day-gnu-cash)
 ___
 gnucash-user mailing list
 gnucash-user@gnucash.org
 To update your subscription preferences or to unsubscribe:
 https://lists.gnucash.org/mailman/listinfo/gnucash-user
 -
 Please remember to CC this list on all your replies.
 You can do this by using Reply-To-List or Reply-All.
>___
>gnucash-user mailing list
>gnucash-user@gnucash.org
>To update your subscription preferences or to unsubscribe:
>https://lists.gnucash.org/mailman/listinfo/gnucash-user
>-
>Please remember to CC this list on all your replies.
>You can do this by using Reply-To-List or Reply-All.
___
gnucash-user mailing list
gnucash-user@gnucash.org
To update your subscription preferences or to unsubscribe:
https://lists.gnucash.org/mailman/listinfo/gnucash-user
-
Please remember to CC this list on all your replies.
You can do this by using Reply-To-List or Reply-All.


Re: [GNC] How to "Get Quotes" for a specific day?

2022-12-29 Thread Geoff

No.

As far as I know the Finance::Quote module that GnuCash uses has no 
provision to fetch historical prices.


If you are into scripting and web scraping, checkout Selenium which has 
a nice Python interface.


Good luck!

Geoff
=
P.S.  Always include gnucash-user@gnucash.org on all correspondence.

On 30/12/2022 3:23 pm, gnucash_2...@michaelaltfield.net wrote:

2. Import from a CSV file:-
   (File / Import / Import prices from a CSV file)


OK, Is there a way that I can generate this CSV file using `gnc-fq-dump` or 
`gnucash-cli` or similar so that I can script something to fetch/generate a CSV 
file and then import that CSV file for all my stocks for a specific date?

On Fri, Dec 30, 2022 at 03:25:02PM +1100, Geoff wrote:

Hi Michael

You can't do this.

Alternatives:-
1. Key the prices directly into the Price Database:-
(Tools / Price Data Database / Add)
2. Import from a CSV file:-
(File / Import / Import prices from a CSV file)

Historical prices are available from, inter alia, https://finance.yahoo.com/


Regards

Geoff
=

On 30/12/2022 3:06 pm, gnucash_2...@michaelaltfield.net wrote:

How can I tell GNU Cash to update its "Price Database" for all known 
currencies, stocks, bonds, mutual funds, etc for a *specific* day?

I'm trying trying to prepare a report for a date in the past. I've set the 
`Options` for the report to `nearest in time` so that it will grab the prices 
for the commodities from the Price Database that are closest to the date of the 
report as possible.

   * 
https://gnucash-docs-rst.readthedocs.io/en/latest/guide/C/ch_invest.html?highlight=price%20database#the-price-source-in-reports
Well, I checked the Price Database, and I have gaps in the prices for some of 
my stocks. For many stocks, I don't have any prices defined for the day of the 
report. Therefore, my report may be inaccurate.

I know that I can go to `Tools` -> `Price Database` and click the `Get Quotes` 
button. This will fetch the current quote (price) and add it to the Price Database 
for all defined currencies, stocks, bonds, mutual funds, etc. But that will fetch 
and add the prices for *today's date* only.

How can I do the equivalent of `Get Quotes` but for a specific day in the 
*past*?

(see also 
https://superuser.com/questions/1760157/how-to-get-quotes-for-all-currencies-and-stocks-for-a-specific-day-gnu-cash)
___
gnucash-user mailing list
gnucash-user@gnucash.org
To update your subscription preferences or to unsubscribe:
https://lists.gnucash.org/mailman/listinfo/gnucash-user
-
Please remember to CC this list on all your replies.
You can do this by using Reply-To-List or Reply-All.

___
gnucash-user mailing list
gnucash-user@gnucash.org
To update your subscription preferences or to unsubscribe:
https://lists.gnucash.org/mailman/listinfo/gnucash-user
-
Please remember to CC this list on all your replies.
You can do this by using Reply-To-List or Reply-All.


Re: [GNC] How to "Get Quotes" for a specific day?

2022-12-29 Thread Geoff

Hi Michael

You can't do this.

Alternatives:-
1. Key the prices directly into the Price Database:-
   (Tools / Price Data Database / Add)
2. Import from a CSV file:-
   (File / Import / Import prices from a CSV file)

Historical prices are available from, inter alia, https://finance.yahoo.com/


Regards

Geoff
=

On 30/12/2022 3:06 pm, gnucash_2...@michaelaltfield.net wrote:

How can I tell GNU Cash to update its "Price Database" for all known 
currencies, stocks, bonds, mutual funds, etc for a *specific* day?

I'm trying trying to prepare a report for a date in the past. I've set the 
`Options` for the report to `nearest in time` so that it will grab the prices 
for the commodities from the Price Database that are closest to the date of the 
report as possible.

  * 
https://gnucash-docs-rst.readthedocs.io/en/latest/guide/C/ch_invest.html?highlight=price%20database#the-price-source-in-reports
  
Well, I checked the Price Database, and I have gaps in the prices for some of my stocks. For many stocks, I don't have any prices defined for the day of the report. Therefore, my report may be inaccurate.


I know that I can go to `Tools` -> `Price Database` and click the `Get Quotes` 
button. This will fetch the current quote (price) and add it to the Price Database 
for all defined currencies, stocks, bonds, mutual funds, etc. But that will fetch 
and add the prices for *today's date* only.

How can I do the equivalent of `Get Quotes` but for a specific day in the 
*past*?

(see also 
https://superuser.com/questions/1760157/how-to-get-quotes-for-all-currencies-and-stocks-for-a-specific-day-gnu-cash)
___
gnucash-user mailing list
gnucash-user@gnucash.org
To update your subscription preferences or to unsubscribe:
https://lists.gnucash.org/mailman/listinfo/gnucash-user
-
Please remember to CC this list on all your replies.
You can do this by using Reply-To-List or Reply-All.

___
gnucash-user mailing list
gnucash-user@gnucash.org
To update your subscription preferences or to unsubscribe:
https://lists.gnucash.org/mailman/listinfo/gnucash-user
-
Please remember to CC this list on all your replies.
You can do this by using Reply-To-List or Reply-All.