marcozanotti/dispositionEffect

Disposition Effect-portfolio compute function

Closed this issue · 6 comments

Am new in R and am running a test for disposition effect using the data for a single investor before i slot in my data to see how the code runs. However, i get errors when i compute the gains and lossess using portfolio compute function. The line of the code is as below>>
p_res <- portfolio_compute(portfolio_transactions = trx_QZ621, market_prices = mkt_QZ621)
head(p_res)[, -5]

The error is as below>>
Error in check_values(names(portfolio_transactions), trg) :
could not find function "check_values"

head(p_res)[, -5]
Error in head(p_res) : object 'p_res' not found

Please assist

Hi,
it is difficult to help you without a reproducible example and without knowing any system information.
Did you install the package correctly (from the master branch)? Did you load the package into your R session?

Hi,
please find below a reproducible example and where i got the ifnormation from.
i will be very happy to get guidance with links on where i need to install this package from if what i did was not correct.

i installed the package from CRAN
install.packages("dispositionEffect"). This was taken from this link
https://github.com/marcozanotti/dispositionEffect/

I then went on to install
install.packages("ggplot2")
install.packages("ggridges")
install.packages("gghalves")
install.packages("skimr")

call packages

library(dispositionEffect)
library(dplyr)
library(tidyr)
library(lubridate)
library(skimr)
library(ggplot2)
library(ggridges)
library(gghalves)

my initial task is to understand how the code runs, before i use my data set. so i use the codes provided on the same link as below and they run all the way until i get errors. I notice that certain functions have to be taken from somewhere. see example below, which i run..

help("DEanalysis")
trx <- DEanalysis$transactions # transactions
head(trx)
skimr::skim(trx)

unique(trx$type)

number of transactions of each investor over years

trx %>%
dplyr::mutate(year = lubridate::year(datetime)) %>%
dplyr::count(investor, year) %>%
dplyr::arrange(year) %>%
tidyr::pivot_wider(names_from = year, values_from = n) %>%
dplyr::left_join(dplyr::count(trx, investor), by = "investor")

##market prices
mkt <- DEanalysis$marketprices # mkt prices
head(mkt)
skimr::skim(mkt)
mkt %>%
dplyr::mutate(year = lubridate::year(datetime)) %>%
dplyr::count(asset, year) %>%
dplyr::arrange(year) %>%
tidyr::pivot_wider(names_from = year, values_from = n) %>%
head(10)

Investor QZ621

trx_QZ621 <- dplyr::filter(trx, investor == "QZ621") # transactions
mkt_QZ621 <- dplyr::filter(mkt, asset %in% unique(trx_QZ621$asset)) # market prices

Portfoli compute is one that gives errors. It appears i have to load the function from elsewhere.

portfolio_compute <- function(
portfolio_transactions,
market_prices,
method = "count",
allow_short = TRUE,
time_threshold = "0 mins",
exact_market_prices = TRUE,
portfolio_driven_DE = FALSE,
time_series_DE = FALSE,
assets_time_series_DE = NULL,
verbose = c(0, 0),
progress = FALSE
)

Unfortunately, it is impossible that you installed the package from CRAN because it has not been released yet.
Please, follow the steps you find here to install the package reading carefully
https://github.com/marcozanotti/dispositionEffect/

Moreover, to understand how everything works, there are 2 vignettes that explain you everything
https://marcozanotti.github.io/dispositionEffect/articles/getting-started.html
https://marcozanotti.github.io/dispositionEffect/articles/de-analysis.html

The errors you are getting are related to your specific session, hence it is difficult to help without session information.
Try remove the installation of the package you already have, then follow the installing instructions carefully to install it from GitHub through devtools or remotes.

Thank you for your guidance. I will follow your guidance. Didi you notice that the link that i have been using is actually the one you have provided from github?. The code is from the same link without any changes. But i will do this step by step again and will revert if i get errors. Many thanks.

Yes, off-course I noticed that, but if you read it carefully you will notice that it is not possible to use install.packages() at the moment.
So you need to use install_github() from devtools or remotes packages (sometimes devtools may not work properly).

Let me know if you will have any trouble.

Sure i will. Disposition Effect analysis is a project i want to deal with. Many thanks.