-
Notifications
You must be signed in to change notification settings - Fork 72
PACTA erroneously incuding short positions #463
Description
After running PACTA with the current code I found that some results on portfolio level showed negative values in plan_alloc_wt_tech_prod & plan_emission_factor. As I am using port_weight, this can only happen (in theory) if the underlying ALD has negative production values (rather unrealistic but you never know) or that we are including short positions (negative values for market_value / value_usd) in the analysis. I think the latter is the case.
This would be a bug in my opinion, as we dont want to include short positions as this would distort the analysis.
Here is a reprex comparing results from two projects, one of which used an older version (from early autumn last year) of the code and one the current version
library(r2dii.utils)
library(dplyr)
# results with old pacta code
bonds_results_old <- read_rds(
fs::path(path_dropbox_2dii(),"/PortCheck_v2/10_Projects/mfm_v7/40_Results/Bonds_results_company.rda")
) %>%
filter(port_weight < 0) %>%
filter(year == 2020, scenario == "B2DS")
equity_results_old <- read_rds(
fs::path(path_dropbox_2dii(),"/PortCheck_v2/10_Projects/mfm_v7/40_Results/Equity_results_company.rda")
) %>%
filter(port_weight < 0) %>%
filter(year == 2020, scenario == "B2DS")
bonds_results_old %>%
as_tibble() %>%
select(portfolio_name, company_name, port_weight, allocation_weight, ald_sector, technology ,plan_tech_prod, plan_alloc_wt_tech_prod) %>%
distinct()
equity_results_old %>%
as_tibble() %>%
select(portfolio_name, company_name, port_weight, allocation_weight, ald_sector, technology ,plan_tech_prod, plan_alloc_wt_tech_prod) %>%
distinct()
# results with new pacta code
bonds_results_new <- read_rds(
fs::path(path_dropbox_2dii(),"/PortCheck_v2/10_Projects/mfm_v8/40_Results/Bonds_results_company.rda")
) %>%
filter(port_weight < 0) %>%
filter(year == 2020, scenario == "B2DS")
equity_results_new <- read_rds(
fs::path(path_dropbox_2dii(),"/PortCheck_v2/10_Projects/mfm_v8/40_Results/Equity_results_company.rda")
) %>%
filter(port_weight < 0) %>%
filter(year == 2020, scenario == "B2DS")
bonds_results_new %>%
as_tibble() %>%
select(portfolio_name, company_name, port_weight, allocation_weight, ald_sector, technology ,plan_tech_prod, plan_alloc_wt_tech_prod) %>%
distinct()
equity_results_new %>%
as_tibble() %>%
select(portfolio_name, company_name, port_weight, allocation_weight, ald_sector, technology ,plan_tech_prod, plan_alloc_wt_tech_prod) %>%
distinct()When comparing the two versions of the code (I still have a copy of it) I think I found the commit since when we are analysing short positions: 7e125aa
More specific, this line was deleted in 3_run_analysis.R : port_eq <- port_eq %>% filter(port_weight > 1e-6)
I dont know the motivation why we had this filter in the first place, but it lead to the fact that we kicked out short positions from port_eq, as negative values are below 1e-6. Without this filter we include short positions since this commit.
This raises a couple of questions from my end:
- Do we intend kickout short positions at a different part of the code?
- If not, how should we kickout short positions in the investor code?
- Why do we only excluded short position in
port_eqand not also inport_cb? It is possible to have negative bonds as well.