Convert Excel macros to run with LibreOffice Calc?
I would like to bulk download historical stock data, for example for the constituents of the FTSE100 - 100 different stocks. There are a great many webpages that suggest ways of doing bulk downloads, but Yahoo and Google keep changing and updating things, so only the most recent are likely to work, and they also require a lot of knowledge of Matlab or Python for example, so would be very difficult to use for someone unfamiliar with those languages.
However the Excel spreadsheet on the webpage below has been updated recently, so should work: http://investexcel.net/multiple-stoc...der-for-excel/ Except that the macros give an error message when the spreadsheet is run in LibreOffice Calc 5. Does anyone know how to get it working please? Incidently, LibreOffice Calc 5 will not or cannot allow me to save the spreadsheet with macros. Thanks. ps. I would be willing to pay a smallish amount to bulk download historical stock data for British stocks with a capital value down to say £50million if anyone knows of a company that offers such a service. That would be many hundreds of stocks I expect. |
looks like libreoffice can't understand those macros. Would be nice to post that error message. At least.
|
The error message is the same in both spreadsheets. After doing nothing except clicking on the "bulk download" button on the spreadsheet, I get an error message saying -
"LibreOffice 5.0.3.2. BASIC runtime error. '423' TintAndShade" in the code, ".TintAndShade = 0" is highlighted. It seems like something merely cosmetic, which I do not care about. Looking through the code I see that it refers to the "crumb" thing, so with Excel it probably works. Edit: So would it work if I just deleted every reference to "TintAndShade"? I would be happy to just have some bare-bones BASIC code without any spreadsheet that saved the .csv files to HD, but do not know what to cut away to get this. The "crumb" problem is the difficult thing. Thanks. |
as i recall libreoffice's calc can use BASIC , whereas MS's excel uses "Microsoft Visual BASIC "
the two are not the same language you will need to port the MS visual basic macros |
The Open/LibreOffice API is a development which aims at providing functionality in these office-packages similar to the Microsoft®-suites. I am not aware of any incompatibilities between OpenOffice and LibreOffice, so the current API-descriptions and tutorials should be okay: http://www.pitonyak.org/oo.php, for example. But there is more.
Do not expect something which is not Microsoft® to work like what is Microsoft®, OLE, COM or other stuff which does not exist in Linux! Edit: Something else, I just found: https://wiki.openoffice.org/wiki/Doc...on/BASIC_Guide Edit II: For munging stock data in an Excel-sheet.., would not XSLT be a solution? Which file-types are you trying to manipulate? |
I would be happy to download the data in any format. Once it is safe and secure on my HD, then I can convert it to any other format at my leisure.
I wish someone published a CD or DVD of historic (British) stock prices. Thanks. |
There is an open-source program called Yloader that I hope is up to date. The source code in C++ is freely available.
http://yloader.com/ I tried running both the 32bit and 64bit .exe programs with Wine, but after installation nothing happened and I could not see the installed programs on the menu anywhere, including not under Wine. I see that the Windows .exe files are actually compressed files consisting of various things such as dlls. How difficult would it be to compile the C++ code under Linux? I imagine it may need some tweaking for Linux. I am not a programmer. Thanks. |
Just googled
libre office run time error 423 and came up with https://ask.libreoffice.org/en/quest...e-error-codes/ (a forum) which has got a list of error codes in a reply of which https://opengrok.libreoffice.org/xre...classes/sb.cxx Quote:
OK |
1 Attachment(s)
pandas-datareader is a python module for reading historical data from Yahoo, Google etc.
However, there's reports that Yahoo and others have changed their API and according to this, google did too recently Quote:
So other older tools that may of depended on similar methods may be broken (possibly including this excel script) EDIT: It seems yahoo may be working. I wrote up something but I'm not sure if the output is what you're looking for? STOCK ABB 2017-2018 with Date / High / Low / Open / Close / Volume / Adj Close https://i.imgur.com/x0IwHFz.png |
Thanks, the output is exactly what I would want.
I am principally interested in British stocks. There are designated for example as TSCO.L for Yahoo Finance, and LON:TSCO for Google Finance. MRW.L and LON:MRW are two other examples. It seems that Google are no longer providing historical stock data (or with great regret any stock screening), but the British Yahoo webpage for historical data for TSCO.L is https://uk.finance.yahoo.com/quote/T...y&frequency=1d It may be possible to copy the URL for the .csv file and replace the details. The "crumb" at the end might not be a problem if you are already viewing the webpage and hence have the cookie that it apparently checks for. The tinkering I have done so far with the .csv file URL indicates that the period1 and period2 numbers are in seconds with a start date of the first of January 1970. I tried replacing the period1 number with 864000, which corresponds to the 11th. of January 1970, and it did successfully download a csv file starting from the earliest dates it had available. I have begun trying to learn Python, but do not know how to use URLS within it yet. Edit/update: The bare-bones program I have in mind would involve going to a webpage like the link above, copying the link for the .csv file download, and then entering this URL string into the program. The program then replaces the period1 number with 0 and then replaces the stock code with a list I have in a text file, saving the downloaded .csv files to hard-disk. It does this slowly, to avoid upsetting the server. |
Doing this "correctly" might not be worth the effort in python due to the frequent changes of the api. Unless you use pandas-datareader
Here's a "hack" you can try. On the finanical page with the "download csv" buttom, hit F12 for web developer tools (Firefox) Go to the network tab, then click on download csv on the actual website Right click on the top request which should have a "200" (valid) response on it in the web developer tools. Copy the request as a curl command and copy it in a similar fashion to the below script. The \ and newlines before every -H isn't needed, but helps with readability. Copy and paste all on one line in fine for the curl command. Code:
#!/bin/bash Code:
./download_stock.sh AAPL WHATEVER Code:
cat AAPL.csv |
Thank you greatly, Field95, very good of you to write the code.
I have not tried it yet, and know nothing about Bash nor have I ever used it. What book that would provide just enough knowledge to use the code above would anyone recommend? Thanks. |
Quote:
There's very little actual bash code here so I'll break it down This tells the file that it is a bash script so that you can run it like "./file" instead of "bash file" Code:
#!/bin/bash If you were to run a program like ./file a b c the $@ would contain "a b c" and the for loop would iterate like Code:
./file a b c Code:
for stock in "$@"; A few changes are made, where it will output (instead of to the screen), usage of "$stock" for the for loop so that you can quickly download each one. Note I didn't write this part. It was just copied from the browser Code:
curl --output "$stock".csv 'https://query1.finance.yahoo.com/v7/finance/download/'"$stock"'?period1=583714800&period2=1537570800&interval=1d&events=history&crumb=dsOmzbl9M5J' -H 'Host: query1.finance.yahoo.com' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:56.0) Gecko/20100101 Firefox/56.0' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Referer: https://finance.yahoo.com/quote/TSCO.L/history?period1=583714800&period2=1537570800&interval=1d&filter=history&frequency=1d' -H 'Cookie: B=ad1nsepd1dv3q&b=4&d=pTj4IhNpYEJI_8oxA.IfZwx6A9c-&s=1f&i=91HWTY69RuHT.aKjFJv_; F=d=So0FgyM9vK_KxdqVQRqM78ZadlGZ677d1rWGiBuahi4kKkAbog--; PH=l=en-US; AO=u=1; ucs=fs=1&lnct=1513112013&bnpt=1522210361&eup=2; GUC=AQABAQFbp4Fci0IhagTA&s=AQAAAFE7YSOB&g=W6Y76Q; PRF=t%3DTSCO.L' -H 'Connection: keep-alive' -H 'Upgrade-Insecure-Requests: 1' Even if you don't fully understand, you can follow these steps to solve your current problem Code:
wget 'https://pastebin.com/raw/Wd6pwruC' -O download_stock.sh Code:
./download_stock AAPL |
I now see that the main part of it is due to the Curl program, and the Bash part is, as you say, just there to loop through the stock codes.
Thanks. |
All times are GMT -5. The time now is 05:12 PM. |