Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
R0bL authored Apr 16, 2024
1 parent 7a1f2bb commit 9f7c46d
Showing 1 changed file with 0 additions and 68 deletions.
68 changes: 0 additions & 68 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,74 +86,6 @@ A link to the API can be found here: [Norges Bank Investment Management API](htt

I used this code to get all companies listed in their database:

```
api_key = " Insert Your API Key Here"
def fetch_company_details(api_key, company_name):
detail_url = f"https://vd.a.nbim.no/v1/query/company/{requests.utils.quote(company_name)}"
headers = {"x-api-key": api_key}
response = requests.get(detail_url, headers=headers)
if response.status_code == 200:
return response.json()
elif response.status_code == 429:
print("Rate limit exceeded. Sleeping...")
time.sleep(900) # Sleep time might need adjustment
return fetch_company_details(api_key, company_name)
else:
print(f"Failed to fetch details for company {company_name}: {response.status_code}")
return {}
def build_companies_dataframe(api_key, companies_list, save_path):
detailed_companies = []
start_from_index = get_last_processed_index(companies_list, save_path)
for i, company in enumerate(tqdm(companies_list[start_from_index:], desc="Fetching company details"), start=start_from_index):
company_name = company['n']
company_details = fetch_company_details(api_key, company_name)
if 'companies' in company_details:
for detail in company_details['companies']:
detailed_companies.append({
'Company Name': company_name,
'Ticker': detail.get('Ticker', 'N/A'),
'Country': detail.get('country', 'N/A')
})
if (i + 1 - start_from_index) % 5 == 0 or i == len(companies_list) - 1:
pd.DataFrame(detailed_companies).to_csv(save_path, mode='a', header=not os.path.exists(save_path), index=False)
detailed_companies = [] # Reset to avoid re-saving data
time.sleep(1) # Consider dynamic adjustment based on API's rate limiting response
if os.path.exists(save_path):
return pd.read_csv(save_path)
else:
return pd.DataFrame()
```

If API times out, restart at index:

```
def get_last_processed_index(companies_list, save_path):
try:
df = pd.read_csv(save_path)
# Correct column name to 'Company Name'
last_processed_company = df.iloc[-1]['11 88 0 Solutions AG']
for index, company in enumerate(companies_list):
if company['n'] == last_processed_company:
return index + 1 # Resume from the next company
except (pd.errors.EmptyDataError, FileNotFoundError):
print("CSV file is empty or does not exist.")
return 0
```

### Step 1B: Cross refrence data with yfinance

The data being evaluated are SEC filings of 1260 Equities held by the Norwegain Wealth Fund, downloaded from the SEC's Electronic Data Gathering, Analysis and Retrieval (EDGAR) website.

Cross refrenced data pulled with y_finance [yfinance](https://pypi.org/project/yfinance/) - Norwegain Wealth Fund Database did not have the correct industry tags:

```


# Step 2: Use sec-api.io to pull 10-K by ticker:
Expand Down

0 comments on commit 9f7c46d

Please sign in to comment.