Pull historical secutities price from ISIN - python

How can one pull historical securities (stocks & ETF's) price data in python from just the exchange and ISIN?
All the methods I've seen to do this first map it to the American system of using a code for the exchange and a ticker symbol for the security. There are two problems with that, some securities don't have American ticker symbols and others have the ticker symbol, but there isn't always a code to specify the exchange.
Currently, I am pulling tables from websites such as
https://www.boerse-online.de/etf/boersenplaetze/ishares-uk-property-etf-IE00B1TXLS18
&
https://www.finanzen100.de/zertifikate/sonstige/sonstiges-zertifikat-auf-bloomberg-brent-crude-subindex-total-return-wkn-a1n49p_H1225544336_49507519/
and then looking up the exchange in the table. But there are some issues with this too.
I cannot concatenate a website with the ISIN to get the webpage of the security as the security name is also in the URL, and so I must manually get the URL for each security.
For different securities, sometimes the formatting is different on the same website, so I must have different code for different securities.
Neither website has all exchanges for all securities, so I must manually find the security online first.
These websites don't give historical data as a table, only current price and some additional information.
As ISIN's are the internationally recognized way to identify a security and using it and the exchange seems to be the most obvious, simplest and, in many cases, the only way to specify a security on a particular exchange, I was surprised I couldn't find tools to do this.

Related

How can I dynamically split the text based on multiple sub-titles in a given text for every new text?

I have an original text that looks like this:
We are AMS. We are a global total workforce solutions firm; we enable organisations to thrive in an age of constant change by building, re-shaping, and optimising workforces. Our Contingent Workforce Solutions (CWS) is one of our service offerings; we act as an extension of our clients' recruitment team and provide professional interim and temporary resources.
We are currently working with our client, Royal London.
Royal London is a financial services company with a difference. As the UK's largest mutual life, pensions and investment company, we're owned by our members and work for their benefit, not for shareholder profits. We've grown rapidly and have been recognised as one of the UK's top-rated places to work.
Today, Royal London has over £114 billion of funds under management, and around 3,500 employees working in six offices across the UK and Ireland. We've worked hard to become experts in our specialist markets, building a trusted brand - and our teams have plenty of awards to show for it. Whatever team you're interested in joining and whatever role you play; we'll help you to make a difference.
We are looking for a Business Analyst for a 6-month contract based in London.
Purpose of the Role:
You will be working with the internal data squad looking at new functionality within the business and associated reporting. Part of project will involve system upgrades
As the Business Analyst, you will be responsible for:
Looking at data sets, extracting the information and be able to look at SQL scripts, write report sequences, analyse data. Be able to understand and deliver data, ask questions and challenge requirements, understand the data journey/mapping documents.
The skills, attributes and capabilities we are seeking from you include:
Strong communication both verbal and written
Strong teamworking within the scrum team and with other BAs and directly with business users
Significant asset management experience
Working knowledge of the key data sets that are used by an asset manager
Experience of Master Data Management tools, ideally IHS Markit EDM
Agile working experience
Ability to write user stories to detail the requirements that both the development team and the * QA team will use
Strong SQL skills, ideally using Microsoft SQL Server
Experience of managing data interface mapping documentation
Familiarity with data modelling concepts
Project experience based on ETL and Data Warehousing advantageous
Technical (development) background advantageous
Have an asset management background.
Thinkfolio and Murex would be ideal, EDM platform knowledge would be desirable.
This client will only accept workers operating via a engagement model.
If you are interested in applying for this position and meet the criteria outlined above, please click the link to apply and speak to one of our sourcing specialists now.
AMS, a Recruitment Process Outsourcing Company, may in the delivery of some of its services be deemed to operate as an Employment Agency or an Employment Business
I have used the below to split and extract text based on the sub-titles from their original html using beautiful soup. Basically, the aim is to:
Separate the html extract by bold text.
From this list of bold texts, extract those that are both bold and have ':' in them to represent it being a legitimate sub-title
Then find out the positions of the first and last legitimate sub-titles from the list of bold texts. This will help to split the text if there are other bold texts that lack the ':' within them below the last sub-title's text.
Conduct a split based on the condition that the last sub-title truly is the last element in the list of bold texts, if not then split the text further to separate the sub-title's texts from other texts.
The code below demonstrates this:
from fake_useragent import UserAgent
import requests
def headers():
ua = UserAgent()
chrome_header = ua.chrome
headers = {'User-Agent': chrome_header}
return headers
headers = headers()
r5 = requests.get("https://www.reed.co.uk/jobs/business-analyst/46819093?source=searchResults&filter=%2fjobs%2fbusiness-jobs-in-london%3fagency%3dTrue%26direct%3dTrue", headers=headers, timeout=20)
soup_description = BS(r5.text, 'html.parser')
j_description = soup_description.find('span', {'itemprop':'description'})
j_description_subtitles = [j.text for j in j_description.find_all('strong')]
sub_titles_in_description = [el for el in j_description_subtitles if ":" in el]
total_length_of_sub_titles = len(sub_titles_in_description)
total_length_of_strong_tags = len(j_description_subtitles)
Position_of_first_sub_title = j_description_subtitles.index(sub_titles_in_description[0])
Position_of_last_sub_title = j_description_subtitles.index(sub_titles_in_description[-1])
# If the position of the last subtitle text does not equal the total number of strong tags, then split the final output by the next indexed position in the list.
if Position_of_last_sub_title != total_length_of_strong_tags:
text_after_sub_t= re.split(f'{sub_titles_in_description[0]}|{sub_titles_in_description[1]}|{sub_titles_in_description[-1]}| {j_description_subtitles[Position_of_last_sub_title+1]}',j_description.text)[1:Position_of_last_sub_title]
else:
text_after_sub_t= re.split(f'{sub_titles_in_description[0]}|{sub_titles_in_description[1]}|{sub_titles_in_description[-1]}',j_description.text)[1:]
final_dict_with_sub_t_n_prec_txt= {
sub_titles_in_description[0]: text_after_sub_t[0],
sub_titles_in_description[1]: text_after_sub_t[1],
sub_titles_in_description[2]: text_after_sub_t[2]
}
The problem is the splitting of text based on the sub-title. Its too manual and have tried other methods to no avail to make this dynamic. How would I go about making this part dynamic because in future texts, the number of sub-titles will differ.
You could simplify or make it more generic by using css selectors for selecting your elements e.g. p:has(strong:-soup-contains(":")) would select all <p> that has a child <strong> with an :. Getting the additional information use find_next_sibling():
dict((e.text,e.find_next_sibling().get_text('|',strip=True)) for e in soup.select('[itemprop="description"] p:has(strong:-soup-contains(":"))'))
Note: Added | as seperator to get_text(), so in this case you are able to split the list elements later. You can also replace it with whitespace get_text(' ',strip=True)
Example
import requests
from bs4 import BeautifulSoup
headers = {'User-Agent': 'Mozilla/5.0'}
r = requests.get("https://www.reed.co.uk/jobs/business-analyst/46819093?source=searchResults&filter=%2fjobs%2fbusiness-jobs-in-london%3fagency%3dTrue%26direct%3dTrue", headers=headers, timeout=20)
soup = BeautifulSoup(r.text, 'html.parser')
data = dict((e.text,e.find_next_sibling().get_text('|',strip=True)) for e in soup.select('[itemprop="description"] p:has(strong:-soup-contains(":"))'))
print(data)
Output
{'Purpose of the Role:': 'You will be working with the internal data squad looking at new functionality within the business and associated reporting. Part of project will involve system upgrades',
'As the Business Analyst, you will be responsible for:': 'Looking at data sets, extracting the information and be able to look at SQL scripts, write report sequences, analyse data. Be able to understand and deliver data, ask questions and challenge requirements, understand the data journey/mapping documents.',
'The skills, attributes and capabilities we are seeking from you include:': 'Strong communication both verbal and written|Strong teamworking within the scrum team and with other BAs and directly with business users|Significant asset management experience|Working knowledge of the key data sets that are used by an asset manager|Experience of Master Data Management tools, ideally IHS Markit EDM|Agile working experience|Ability to write user stories to detail the requirements that both the development team and the QA team will use|Strong SQL skills, ideally using Microsoft SQL Server|Experience of managing data interface mapping documentation|Familiarity with data modelling concepts|Project experience based on ETL and Data Warehousing advantageous|Technical (development) background advantageous|Have an asset management background.|Thinkfolio and Murex would be ideal, EDM platform knowledge would be desirable.'}

LinkedIn Marketing API Creative names

I am trying to use the marketing developer platform api to pull reports for my campaigns.
I want to be able to break down my reports by campaign and then by creative name.
In the LinkedIn documentation (https://learn.microsoft.com/en-gb/linkedin/marketing/integrations/ads-reporting/ads-reporting#statistics-finder) they give examples of the statistics finder and say that it can pull up to 3 pivots.
This is the example they give:
GET https://api.linkedin.com/v2/adAnalyticsV2?q=statistics&pivots[0]=CAMPAIGN&dateRange.start.day=1&dateRange.start.month=1&dateRange.start.year=2017&timeGranularity=DAILY&campaigns[0]=urn:li:sponsoredCampaign:1234567
I can't seem to get it to work for more than 1 pivot.
Another issue that I am facing is that I am not sure how to pull creative names - I can only seem to get creative ids in my api calls.
I am using the examples from to get campaign name:
https://learn.microsoft.com/en-gb/linkedin/shared/references/v2/ads/adcampaigns?context=linkedin/marketing/context
Looking at the creative name equivalent:
https://learn.microsoft.com/en-gb/linkedin/shared/references/v2/ads/adcreatives?context=linkedin/marketing/context
I cannot seem to find name for creatives here. Am I looking in the wrong place?
The magic sequence to get multiple pivots is:
...q=statistics&pivots[0]=ACCOUNT&pivots[1]=CAMPAIGN&pivots[2]=CREATIVE&...
As for creative names, they do not 'simply' exist. There are different fields (variables/data) for each type of creative, and what you would see in the UI depends on the type of campaign/creative displayed. For a simple Text Ad, it would be variables.data.title and variables.data.text. For the rest, you need to use projection to get specific fields from the urn's referenced.

Is there a good way to extract only today' stock market date data from the Alpha Vantage API?

I'm using the Alpha Vantage API to fetch stock market data. However, this API seems to be geared towards only providing series of data which is also implied in its aptly named functions like TimeSeries. That means that if I request a quote from the API I get a series of different dates, times and so forth.
What I'm after is to get only data from a specific date and nothing else. I could get todays date and then use the "is in" if loop to check for it, but that does not seem like a good solution and it would waste quite a bit of resources, so I'm looking to see if there is another better solution available. I have not seen any mention of getting a single entry from their API and tring to get a slice of the dict returned does not seem to work good as the dict is unsorted.
Does someone know about a good way of fetching only stock market data from a single date from the TimeSeries class ?
I came across this problem and this question, and after looking into the documentation I saw this Quote Endpoint that returns just the latest info. Here is the description:
A lightweight alternative to the time series APIs, this service returns the latest price and volume information for a security of your choice.
Example from the documentation:
https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=MSFT&apikey=demo
If you need data from another day in the past you can download all historical data once and cache it.

Integrate XBRLware to Python 3

I am at the absolutely basic level on Python 3 (everything i currently know is from TheMonkeyLords) and my main focus is to integrate Python 3 with XBRLware so that i can extract financial information from the SEC EDGAR database with accuracy and reliability.
How can i use the xbrlware frame with Python 3? I have absolutely no idea how you can use a frame with Python 3....
Any suggestions on what should I learn or code for me to study, clues etc would be great help!
Thank you
Don't do it. Based on personal experience, it is very difficult to extract useful financial data from XBRL. XBRLWare does work, but there is a lot of work to do afterwards to extract the data into something useful.
XBRL has over 100 definitions of "revenue". Each industry reports differently. Each company makes 100s of filings and you have to string together data from different reports. It's an incredibly frustrating process.
I have used XBRLWare as a Ruby Gem on Windows. (It is no longer supported.) It does "work". It downloads and formats the reports nicely, but it operates as a viewer. Most filings contain two quarters of data. (Probably not the quarters you want either.)
You can use the XBRL viewer on the SEC's website to accomplish the same thing. Or you can go to the company's 10-Qs.
Also, XBRL uses CIK codes for the companies. As far as I know, the SEC doesn't have a central database to match CIK codes to ticker symbols (if you can believe that!). So it can be frustrating to find the companies you want to download.
If you want to download all the XBRL filings, I've been told its like 6TB a month.
You can't pull historical financial data from XBRL either. You have to string two quarters at a time together. So, pull every IBM filing (XBRL is 3 yrs old) and string together all the 10-Qs. XBRL is only three years old for the large accelerated filers, so historical data is limited.
There is a reason why Wall Street still charges $25k/year for financial data. XBRL is very difficult to use and difficult to extract data from.
You could try: XBRLcloud.com or findynamics.com

Calculate (or look up) fundamental financial quantities for stocks

I've seen a number of ways to script code (for example, in python: ystockquote) that returns the stock price (or the historical closing prices) of a particular stock. Is there a way of scripting the information for calculating various fundamental quantities: Enterprise Value, EBITDA (I know this is included in that python link), Free-cash-flow...etc.
I'm asking whether there is a command-line tool that can be pinged to return this kind of information (or enough of the relevant information to do the calculation oneself)? Something like a repository for earnings statements/debt/cash flow/taxes.
Thanks in advance for any suggestions!
JBW,
You can do this in multiple steps but you will have to invest some time to use the API and identify the financial data from the companies.
1) Identify company's CIK
2) Download XBRL file from SEC FTP
3) Use the numbers provided to compute the metric you are looking for
3*) Some companies will already contain those values in the XML
FTP Info : http://www.sec.gov/edgar/searchedgar/ftpusers.htm
XBRL Spec: http://www.sec.gov/info/edgar/nsarxml1_d.htm
I hope this helps.
Vladimir

Categories

Resources