Skip to content
This repository has been archived by the owner on Dec 14, 2023. It is now read-only.

Commit

Permalink
Merge pull request #78 from jacobvjk/bics_sector_bridge
Browse files Browse the repository at this point in the history
Bics sector bridge
  • Loading branch information
Clare2D authored Sep 14, 2020
2 parents b4b4bb2 + 18ac014 commit d7c1a8f
Show file tree
Hide file tree
Showing 7 changed files with 8,974 additions and 6,479 deletions.
Binary file modified .DS_Store
Binary file not shown.
62 changes: 31 additions & 31 deletions 0_portfolio_input_check_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ get_and_clean_fin_data <- function(fund_data){
# Checks to ensure all finds are classified as such
fin_data <- classify_all_funds(fin_data)

# fin_data <- add_bics_sector(fin_data)
fin_data <- add_bics_sector(fin_data)

# Select relevant columns
fin_data <- fin_data %>%
Expand All @@ -935,7 +935,7 @@ get_and_clean_fin_data <- function(fund_data){
isin,
unit_share_price, exchange_rate_usd,
asset_type, security_type,
security_mapped_sector, security_icb_subsector, security_bics_subgroup, # bclass4,
security_mapped_sector, security_icb_subsector, security_bics_subgroup, bics_sector, # bclass4,
maturity_date, coupon_value, amount_issued, current_shares_outstanding_all_classes, unit_share_price,
sector_override,
is_sb
Expand All @@ -954,14 +954,14 @@ get_and_clean_fin_data <- function(fund_data){

}

# add_bics_sector <- function(fin_data){
#
# bics_bridge <- read_csv("data/bics_bridge.csv")
#
# fin_data_ <- left_join(fin_data, bics_bridge, by = c("security_bics_subgroup" = "bics_subsector"))
#
#
# }
add_bics_sector <- function(fin_data){

bics_bridge <- read_csv("data/bics_bridge.csv")

fin_data_ <- left_join(fin_data, bics_bridge, by = c("security_bics_subgroup" = "bics_subgroup"))


}

get_and_clean_revenue_data <- function(){

Expand Down Expand Up @@ -1531,24 +1531,24 @@ add_other_to_sector_classifications <- function(audit){
audit
}

add_bics_sector <- function(portfolio, comp_fin_data, debt_fin_data){
#join in bics sectors for EQ and CB
portfolio_eq <- portfolio %>% filter(asset_type == "Equity") %>%
left_join(comp_fin_data %>% select(company_id, bics_sector), by = c("company_id"))
portfolio_cb <- portfolio %>% filter(asset_type == "Bonds") %>%
left_join(debt_fin_data %>% select(corporate_bond_ticker, bics_sector), by = c("corporate_bond_ticker"))
#separate out other asset_types to handle new variable
portfolio_other <- portfolio %>% filter(!asset_type %in% c("Equity", "Bonds"))
#if other asset_types has pos. number of entries, add bics_sector with NA value, otherwise add column name
if (data_check(portfolio_other)){
portfolio_other <- portfolio_other %>% mutate(bics_sector = NA_character_)
}else{
portfolio_other <- portfolio_other %>% add_column("bics_sector")

}
#bind the diff asset types back together
portfolio <- rbind(portfolio_eq, portfolio_cb, portfolio_other)

return(portfolio)

}
# add_bics_sector <- function(portfolio, comp_fin_data, debt_fin_data){
# #join in bics sectors for EQ and CB
# portfolio_eq <- portfolio %>% filter(asset_type == "Equity") %>%
# left_join(comp_fin_data %>% select(company_id, bics_sector), by = c("company_id"))
# portfolio_cb <- portfolio %>% filter(asset_type == "Bonds") %>%
# left_join(debt_fin_data %>% select(corporate_bond_ticker, bics_sector), by = c("corporate_bond_ticker"))
# #separate out other asset_types to handle new variable
# portfolio_other <- portfolio %>% filter(!asset_type %in% c("Equity", "Bonds"))
# #if other asset_types has pos. number of entries, add bics_sector with NA value, otherwise add column name
# if (data_check(portfolio_other)){
# portfolio_other <- portfolio_other %>% mutate(bics_sector = NA_character_)
# }else{
# portfolio_other <- portfolio_other %>% add_column("bics_sector")
#
# }
# #bind the diff asset types back together
# portfolio <- rbind(portfolio_eq, portfolio_cb, portfolio_other)
#
# return(portfolio)
#
# }
2 changes: 1 addition & 1 deletion 2_project_input_analysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ portfolio <- add_revenue_split(has_revenue, portfolio, revenue_data)

portfolio <- create_ald_flag(portfolio, comp_fin_data, debt_fin_data)

portfolio <- add_bics_sector(portfolio, comp_fin_data, debt_fin_data)
# portfolio <- add_bics_sector(portfolio, comp_fin_data, debt_fin_data)

eq_portfolio <- create_portfolio_subset(portfolio,
"Equity",
Expand Down
79 changes: 78 additions & 1 deletion data/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,78 @@
isins_missing_bbg_data.csv
### MacOS specific ###
# Folder view configuration files
.DS_Store
Desktop.ini

# Thumbnail cache files
._*
Thumbs.db

# Files that might appear on external disks
.Spotlight-V100
.Trashes

# Compiled Python files
*.pyc

# Compiled C++ files
*.out

# Application specific files
venv
node_modules
.sass_cache

### R ###
# History files
.Rhistory
.Rapp.history

# Session Data files
.RData

# User-specific files
.Ruserdata

# Example code in package build process
*-Ex.R

# Output files from R CMD build
/*.tar.gz

# Output files from R CMD check
/*.Rcheck/

# RStudio files
.Rproj.user/

# produced vignettes
vignettes/*.html
vignettes/*.pdf

# OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3
.httr-oauth

# knitr and R markdown default cache directories
*_cache/
/cache/

# Temporary files created by R markdown
*.utf8.md
*.knit.md

# R Environment Variables
.Renviron

### R.Bookdown Stack ###
# R package: bookdown caching files
/*_files/

# End of https://www.toptal.com/developers/gitignore/api/r

# user data
.Ruserdata

### Project specific ###
/outputs/
/r2dii_data/
web_folders
80 changes: 80 additions & 0 deletions data/bics_bridge.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
bics_sector,bics_subgroup
Communications,Advertising & Marketing
Industrials,Aerospace & Defense
Consumer Discretionary,Airlines
Consumer Discretionary,Apparel & Textile Products
Consumer Discretionary,Auto Parts Manufacturing
Consumer Discretionary,Automobiles Manufacturing
Financials,Banks
Health Care,Biotechnology
Communications,Cable & Satellite
Consumer Discretionary,Casinos & Gaming
Materials,Chemicals
Energy,Coal Operations
Financials,Commercial Finance
Technology,Communications Equipment
Materials,Construction Materials Manufacturing
Financials,Consumer Finance
Consumer Staples,Consumer Products
Consumer Discretionary,Consumer Services
Materials,Containers & Packaging
Consumer Discretionary,Department Stores
Technology,"Design, Manufacturing & Distribution"
Consumer Discretionary,Distributors - Consumer Discretionary
Financials,Diversified Banks
Consumer Discretionary,Educational Services
Industrials,Electrical Equipment Manufacturing
Communications,Entertainment Content
Consumer Discretionary,Entertainment Resources
Energy,Exploration & Production
Financials,Financial Services
Consumer Staples,Food & Beverage
Materials,Forest & Paper Products Manufacturing
Unclassifiable,Funds & Trusts
Unclassifiable,Government Agencies
Unclassifiable,Government Development Banks
Unclassifiable,Government Regional
Technology,Hardware
Health Care,Health Care Facilities & Services
Consumer Discretionary,Home & Office Products Manufacturing
Consumer Discretionary,Home Improvement
Consumer Discretionary,Homebuilders
Industrials,Industrial Other
Energy,Integrated Oils
Communications,Internet Media
Consumer Discretionary,Leisure Products Manufacturing
Financials,Life Insurance
Industrials,Machinery Manufacturing
Health Care,Managed Care
Industrials,Manufactured Goods
Consumer Staples,Mass Merchants
Health Care,Medical Equipment & Devices Manufacturing
Materials,Metals & Mining
Unclassifiable,No Mapping Available
Energy,Oil & Gas Services & Equipment
Health Care,Pharmaceuticals
Energy,Pipeline
Utilities,Power Generation
Financials,Property & Casualty Insurance
Communications,Publishing & Broadcasting
Industrials,Railroad
Financials,Real Estate
Energy,Refining & Marketing
Energy,Renewable Energy
Consumer Discretionary,Restaurants
Consumer Discretionary,Retail - Consumer Discretionary
Consumer Staples,Retail - Consumer Staples
Technology,Semiconductors
Technology,Software & Services
Unclassifiable,Sovereigns
Consumer Staples,Supermarkets & Pharmacies
Unclassifiable,Supranationals
Consumer Staples,Tobacco
Industrials,Transportation & Logistics
Consumer Discretionary,Travel & Lodging
Utilities,Utilities
Industrials,Waste & Environment Services & Equipment
Unclassifiable,Winding Up Agencies
Unclassifiable,Wireless Telecommunications Services
Unclassifiable,Wireline Telecommunications Services
Unclassifiable,NA
Loading

0 comments on commit d7c1a8f

Please sign in to comment.