mirror of
https://github.com/cmallwitz/Financials-Extension.git
synced 2026-08-26 10:04:12 -05:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4e626c272e | ||
|
|
e22dc7448f | ||
|
|
ab34a246e3 | ||
|
|
aa20845ae4 |
@@ -12,16 +12,19 @@ Additionally, starting with version 3 of the extension, it contains all non-stan
|
||||
|
||||
### Feedback requested:
|
||||
|
||||
Please provide feedback about using the extension here: https://github.com/cmallwitz/Financials-Extension/issues/10
|
||||
Please provide feedback about using the extension [here](https://github.com/cmallwitz/Financials-Extension/issues/10)
|
||||
|
||||
### Usage:
|
||||
|
||||
Under 'Releases' on GitHub there is downloadable **Financials-Extension.oxt** file - load it into Calc
|
||||
Under 'Releases' on GitHub [there](https://github.com/cmallwitz/Financials-Extension/releases) is a downloadable **Financials-Extension.oxt** file - load it into Calc
|
||||
under menu item: Tools, Extension Manager...
|
||||
|
||||
Please make sure, not to rename the OXT file when downloading and before installing: LO will mess up the installation otherwise and the extension won't work.
|
||||
|
||||
Getting data should be a simple as having this in a cell:
|
||||
- `=GETREALTIME("IBM",21,"YAHOO")`
|
||||
- `=GETREALTIME("IBM:NYQ",21,"FT")`
|
||||
- `=GETREALTIME("EURUSD","LAST_PRICE","FT")`
|
||||
- `=GETHISTORIC("IBM",90,"2020-12-01","YAHOO")`
|
||||
|
||||
Codes 21 and 90 stand for "last price" and "close" (see below), respectively.
|
||||
@@ -36,6 +39,15 @@ assets in other regions, drop me a line (best to include full URLs and possibly
|
||||
site for comparison). While data for last price is most likely consistent across sites, they may differ for other data
|
||||
points.
|
||||
|
||||
List of example URLs for checking symbols. You can start from these and search for other symbols. If you think some data
|
||||
is available on the website but not from the extension, a good place to start when raising an issue is to include a similar
|
||||
URL to compare results.
|
||||
|
||||
|Website|Symbol|Example URL for Vodafone Group Plc UK |
|
||||
| :--- | :--- | :--- |
|
||||
|YAHOO|VOD.L|https://finance.yahoo.com/quote/VOD.L|
|
||||
|FT|VOD:LSE|https://markets.ft.com/data/equities/tearsheet/summary?s=VOD:LSE|
|
||||
|
||||
### LibreOffice: using , (comma) vs ; (semicolon) to separate arguments in formula
|
||||
|
||||
There is a setting in "Tools" / "Options..." / "LibreOffice Calc" / "Formula" called "Functions". Here the user can specify the character used to separate arguments in formula.
|
||||
@@ -76,6 +88,8 @@ You can either specify numbers or names (lower or upper case) - not all bits are
|
||||
|EX_DIV_DATE|72|Yes|Yes| |yyyy-mm-dd|
|
||||
|PAYOUT_RATIO|73|Yes|No|||
|
||||
|EXPIRY_DATE|74|Yes (on options)|No| |yyyy-mm-dd|
|
||||
|SHARES_OUT|75|Yes|Yes| ||
|
||||
|FREE_FLOAT|76|Yes|Yes| ||
|
||||
|CLOSE|90|No|No|Yes||
|
||||
|ADJ_CLOSE|91|No|No|Yes||
|
||||
|SECTOR|98|Yes|Yes|||
|
||||
@@ -120,6 +134,7 @@ python3 -m unittest discover src
|
||||
### Tested with:
|
||||
- Windows 10 / LibreOffice Calc 7.1.2.2 / Python 3.8.8
|
||||
- Ubuntu 20.04 / LibreOffice Calc 6.4.3.2 / Python 3.8.2
|
||||
- MacOS 10.15.7 / LibeOffice Calc 7.2.0.4 / Python 3.8.10
|
||||
|
||||
(Previous versions)
|
||||
- Debian 10.3 / LibreOffice Calc 6.1.5.2 / Python 3.7.3
|
||||
|
||||
Binary file not shown.
@@ -195,6 +195,7 @@ class BaseClient:
|
||||
tick[Datacode.EXCHANGE] = None
|
||||
tick[Datacode.EXPIRY_DATE] = None
|
||||
tick[Datacode.EX_DIV_DATE] = None
|
||||
tick[Datacode.FREE_FLOAT] = None
|
||||
tick[Datacode.HIGH] = None
|
||||
tick[Datacode.HIGH_52_WEEK] = None
|
||||
tick[Datacode.INDUSTRY] = None
|
||||
@@ -210,6 +211,7 @@ class BaseClient:
|
||||
tick[Datacode.PE_RATIO] = None
|
||||
tick[Datacode.PREV_CLOSE] = None
|
||||
tick[Datacode.SECTOR] = None
|
||||
tick[Datacode.SHARES_OUT] = None
|
||||
tick[Datacode.TICKER] = None
|
||||
tick[Datacode.TIMEZONE] = None
|
||||
tick[Datacode.VOLUME] = None
|
||||
@@ -320,6 +322,12 @@ class BaseClient:
|
||||
else:
|
||||
return data[Datacode.EXPIRY_DATE]
|
||||
|
||||
elif datacode == Datacode.FREE_FLOAT.value and Datacode.FREE_FLOAT in data:
|
||||
return data[Datacode.FREE_FLOAT]
|
||||
|
||||
elif datacode == Datacode.SHARES_OUT.value and Datacode.SHARES_OUT in data:
|
||||
return data[Datacode.SHARES_OUT]
|
||||
|
||||
elif datacode == Datacode.CLOSE.value and Datacode.CLOSE in data:
|
||||
return data[Datacode.CLOSE]
|
||||
|
||||
|
||||
@@ -44,6 +44,8 @@ class Datacode(Enum):
|
||||
EX_DIV_DATE = 72
|
||||
PAYOUT_RATIO = 73
|
||||
EXPIRY_DATE = 74
|
||||
SHARES_OUT = 75
|
||||
FREE_FLOAT = 76
|
||||
|
||||
CLOSE = 90
|
||||
ADJ_CLOSE = 91
|
||||
|
||||
+13
-1
@@ -14,6 +14,7 @@ import logging
|
||||
import os
|
||||
import pathlib
|
||||
import platform
|
||||
import ssl
|
||||
import sys
|
||||
import time
|
||||
from functools import wraps
|
||||
@@ -60,6 +61,16 @@ import financials_ft as ft
|
||||
implementation_name = "com.financials.getinfo.python.FinancialsImpl" # as defined in Financials.xcu
|
||||
implementation_services = ("com.sun.star.sheet.AddIn",)
|
||||
|
||||
# Disabling SSL certificate validation as Python setup on MacOS seems to be broken
|
||||
# Only reading public data so this should be safe
|
||||
|
||||
try:
|
||||
_create_unverified_https_context = ssl._create_unverified_context
|
||||
except AttributeError:
|
||||
pass
|
||||
else:
|
||||
ssl._create_default_https_context = _create_unverified_https_context
|
||||
|
||||
|
||||
def profile(fn):
|
||||
@wraps(fn)
|
||||
@@ -230,7 +241,7 @@ class FinancialsImpl(unohelper.Base, Financials):
|
||||
if e.tag.endswith('version'):
|
||||
version = e.attrib['value']
|
||||
|
||||
s = 'ctx={}\nid(self)={}\nversion={}\nfile={}\ncwd={}\nhome={}\nuname={}\npid={}\nsys.executable={}\nsys.version={}\nlocale={}\ndefaultlocale={}\ndateutil={}\npytz={}\npyparsing={}\nsix={}'.format(
|
||||
s = 'ctx={}\nid(self)={}\nversion={}\nfile={}\ncwd={}\nhome={}\nuname={}\npid={}\nsys.executable={}\nsys.version={}\nsys.path={}\nlocale={}\ndefaultlocale={}\ndateutil={}\npytz={}\npyparsing={}\nsix={}'.format(
|
||||
self.ctx,
|
||||
id(self),
|
||||
version,
|
||||
@@ -241,6 +252,7 @@ class FinancialsImpl(unohelper.Base, Financials):
|
||||
os.getpid(),
|
||||
sys.executable,
|
||||
sys.version.replace("\n", " "),
|
||||
sys.path,
|
||||
locale.getlocale(),
|
||||
locale.getdefaultlocale(),
|
||||
dateutil.__version__,
|
||||
|
||||
@@ -241,6 +241,18 @@ class FT(BaseClient):
|
||||
tick[Datacode.AVG_DAILY_VOL_3MONTH] = self.save_wrapper(
|
||||
lambda: handle_abbreviations(html.unescape(match.group(1))))
|
||||
|
||||
r = r'<th>\s*Shares outstanding\s*</th><td>\s*([0-9,\.btnmk]+)\s*</td>'
|
||||
match = re.compile(r, flags=re.DOTALL).search(text, start)
|
||||
if match:
|
||||
tick[Datacode.SHARES_OUT] = self.save_wrapper(
|
||||
lambda: handle_abbreviations(html.unescape(match.group(1))))
|
||||
|
||||
r = r'<th>\s*Free float\s*</th><td>\s*([0-9,\.btnmk]+)\s*</td>'
|
||||
match = re.compile(r, flags=re.DOTALL).search(text, start)
|
||||
if match:
|
||||
tick[Datacode.FREE_FLOAT] = self.save_wrapper(
|
||||
lambda: handle_abbreviations(html.unescape(match.group(1))))
|
||||
|
||||
r = r'<th>\s*P/E.*?</th><td>\s*([0-9,\.\-]+)\s*<'
|
||||
match = re.compile(r, flags=re.DOTALL).search(text, start)
|
||||
if match:
|
||||
|
||||
@@ -176,6 +176,7 @@ class Yahoo(BaseClient):
|
||||
price = results['price']
|
||||
quoteType = results['quoteType']
|
||||
summaryDetail = results['summaryDetail']
|
||||
defaultKeyStatistics = results['defaultKeyStatistics'] if 'defaultKeyStatistics' in results else dict()
|
||||
|
||||
if not price:
|
||||
return 'Could not find price for \'{}\''.format(ticker)
|
||||
@@ -203,6 +204,8 @@ class Yahoo(BaseClient):
|
||||
tick[Datacode.DIV_YIELD] = float(raw(summaryDetail, 'dividendYield'))
|
||||
tick[Datacode.EX_DIV_DATE] = self.save_wrapper(
|
||||
lambda: dateutil.parser.parse(str(fmt(summaryDetail, 'exDividendDate')), yearfirst=True, dayfirst=False).date())
|
||||
tick[Datacode.SHARES_OUT] = float(raw(defaultKeyStatistics, 'sharesOutstanding'))
|
||||
tick[Datacode.FREE_FLOAT] = float(raw(defaultKeyStatistics, 'floatShares'))
|
||||
|
||||
tick[Datacode.PAYOUT_RATIO] = float(raw(summaryDetail, 'payoutRatio'))
|
||||
tick[Datacode.LOW_52_WEEK] = float(raw(summaryDetail, 'fiftyTwoWeekLow'))
|
||||
@@ -238,6 +241,10 @@ class Yahoo(BaseClient):
|
||||
if match:
|
||||
tick[Datacode.CURRENCY] = match.group(1)
|
||||
|
||||
# fallback for yield on US mutual funds and ETFs, which is in different field
|
||||
if not tick[Datacode.DIV_YIELD]:
|
||||
tick[Datacode.DIV_YIELD] = float(raw(summaryDetail, 'yield'))
|
||||
|
||||
name = price['longName'] or price['shortName']
|
||||
if name:
|
||||
tick[Datacode.NAME] = html.unescape(str(name))
|
||||
|
||||
@@ -14,7 +14,7 @@ import os
|
||||
cur_dir = os.getcwd()
|
||||
|
||||
addin_id = "com.financials.getinfo"
|
||||
addin_version = "3.0.2"
|
||||
addin_version = "3.0.5"
|
||||
addin_displayname = "Financial Market Extension"
|
||||
addin_publisher_link = "https://github.com/cmallwitz/Financials-Extension"
|
||||
addin_publisher_name = "The Publisher"
|
||||
|
||||
@@ -70,6 +70,12 @@ class Test(unittest.TestCase):
|
||||
s = financials.getRealtime('IBM:NYQ', 'EPS', 'FT')
|
||||
self.assertEqual(float, type(s), 'test_US_equity EPS {}'.format(s))
|
||||
|
||||
s = financials.getRealtime('IBM:NYQ', 'SHARES_OUT', 'FT')
|
||||
self.assertEqual(float, type(s), 'test_US_equity SHARES_OUT {}'.format(s))
|
||||
|
||||
s = financials.getRealtime('IBM:NYQ', 'FREE_FLOAT', 'FT')
|
||||
self.assertEqual(float, type(s), 'test_US_equity FREE_FLOAT {}'.format(s))
|
||||
|
||||
s = financials.getRealtime('IBM:NYQ', 'PE_RATIO', 'FT')
|
||||
self.assertEqual(float, type(s), 'test_US_equity PE_RATIO {}'.format(s))
|
||||
|
||||
@@ -217,6 +223,12 @@ class Test(unittest.TestCase):
|
||||
s = financials.getRealtime('SAPX:GER', 'EPS', 'FT')
|
||||
self.assertEqual(float, type(s), 'test_DE_equity EPS {}'.format(s))
|
||||
|
||||
s = financials.getRealtime('SAPX:GER', 'SHARES_OUT', 'FT')
|
||||
self.assertEqual(float, type(s), 'test_DE_equity SHARES_OUT {}'.format(s))
|
||||
|
||||
s = financials.getRealtime('SAPX:GER', 'FREE_FLOAT', 'FT')
|
||||
self.assertEqual(float, type(s), 'test_DE_equity FREE_FLOAT {}'.format(s))
|
||||
|
||||
s = financials.getRealtime('SAPX:GER', 'PE_RATIO', 'FT')
|
||||
self.assertEqual(float, type(s), 'test_DE_equity PE_RATIO {}'.format(s))
|
||||
|
||||
|
||||
+10
-1
@@ -106,6 +106,12 @@ class Test(unittest.TestCase):
|
||||
s = financials.getRealtime('IBM', Datacode.PAYOUT_RATIO.value, 'YAHOO')
|
||||
self.assertTrue(testutils.is_positive_float(s), 'test_realtime_US_equity PAYOUT_RATIO {}'.format(s))
|
||||
|
||||
s = financials.getRealtime('IBM', Datacode.SHARES_OUT.value, 'YAHOO')
|
||||
self.assertTrue(testutils.is_positive_float(s), 'test_realtime_US_equity SHARES_OUT {}'.format(s))
|
||||
|
||||
s = financials.getRealtime('IBM', Datacode.FREE_FLOAT.value, 'YAHOO')
|
||||
self.assertTrue(testutils.is_positive_float(s), 'test_realtime_US_equity FREE_FLOAT {}'.format(s))
|
||||
|
||||
s = financials.getRealtime('IBM', Datacode.EXCHANGE.value, 'YAHOO')
|
||||
self.assertEqual(s, 'NYQ', 'test_realtime_US_equity EXCHANGE')
|
||||
|
||||
@@ -123,6 +129,9 @@ class Test(unittest.TestCase):
|
||||
s = financials.getRealtime('VFIAX', Datacode.LAST_PRICE_TIME.value, 'YAHOO')
|
||||
self.assertEqual(str, type(s), 'test_realtime_US_mutuals LAST_PRICE_TIME {}'.format(s))
|
||||
|
||||
s = financials.getRealtime('VFIAX', Datacode.DIV_YIELD.value, 'YAHOO')
|
||||
self.assertTrue(testutils.is_positive_float(s), 'test_realtime_US_mutuals DIV_YIELD {}'.format(s))
|
||||
|
||||
def test_realtime_US_options(self):
|
||||
|
||||
# symbol from https://finance.yahoo.com/quote/IBM/options?p=IBM
|
||||
@@ -272,7 +281,7 @@ class Test(unittest.TestCase):
|
||||
|
||||
# Note: quarterly dividend and splits will change past adjusted prices - will fail after the next dividend
|
||||
s = financials.getHistoric('IBM', Datacode.ADJ_CLOSE.value, '2017-01-03', 'YAHOO')
|
||||
self.assertEqual(136.249847, s, 'test_historic_US_equity ADJ_CLOSE {}'.format(s))
|
||||
self.assertEqual(134.699081, s, 'test_historic_US_equity ADJ_CLOSE {}'.format(s))
|
||||
|
||||
def test_historic_UK_ETF(self):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user