library(magrittr)
library(lubridate)
con <- 
  make_contract() %>% 
  add_counterparty("JP Morgan")

con
View(con)
con <- 
  make_contract() %>% 
  add_counterparty(c("JP Morgan", "Goldman Sacs"))

con
View(con)
con <- 
  make_contract() %>% 
  add_counterparty(mtcars)

con
View(con)
con <- make_contract() %>% 
  add_maturity(dmy("01/01/2000")) %>% 
  add_counterparty("JP Morgan")

View(con)
con
translate_period_freq("-monthly")
con <- 
  make_contract() %>% 
  add_counterparty("JP Morgan")

!is.null(con$counterparty)
con <- 
  make_contract() %>% 
  add_counterparty("JP Morgan")

get_counterparty(con)
con <- 
  make_contract() %>% 
  add_counterparty("JP Morgan") %>% 
  add_maturity(dmy("01/01/2018")) %>% 
  starting_from(dmy("01/01/2018")) %>% 
  starting_from(dmy("01/01/2018")) 

View(con)
con$date_terms %>% 
  tibble::add_row(date_type = "mat", date_value = dmy("01/01/2000"))
x <- con[["clauses"]] %>% purrr::map(class) 

#x <- con[["clauses"]] %>% purrr::keep(class(.) == "clause") 

#%>% 
#purrr::keep(x, x != "clause")

x
con %>% 
  purrr::pluck("clauses") %>% 
  purrr::map(class) %>%
  unlist() %>%
  unique() %>% 
  purrr::has_element("clause")
cl <- make_clause(
      subclass = "start_date",
      start_date = dmy("01/01/2000"),
      id = "id",
      unique = "unique"
    )

cl <- class(cl)

purrr::keep(cl, cl!="clause")
cont <- 
  make_contract() %>% 
  starting_from(dmy("01/01/2018")) 

cl <- make_clause(
      subclass = "start_date",
      start_date = dmy("01/01/2000"),
      id = "id",
      unique = "unique")

a_clause_type <- get_clause_type(cl)

has_clause(cont, a_clause_type)
cont <- make_contract() %>% 
  starting_from(dmy("01/01/2018")) %>% 
  starting_from(dmy("01/01/2018"))

View(cont)
has_clause <- function(contract){
  x <- purrr::map(contract[["clauses"]], inherits, "clause_start_date")
  x <- x
  x
}

has_clause(con)
has_clause <- function(contract, clause_type){

  contract[["clauses"]] %>% 
    purrr::some(inherits, clause_type)
}

has_clause(con, "clause_start_date_")
cont <-
  make_contract() %>% 
  #add_counterparty("JP") %>% 
  term_start(dmy("01/01/2000"))

#View(cont)
#unlist(cont$stipulations)
#cont$stipulations
#cont$stipulations
#cont$stipulations[[1]]
#cont$stipulations[[1]]
#as.character(cont$stipulations[[1]])
View(cont)
cont
a_contract <- 
  make_contract() %>% 
  term_start(dmy("01/01/2000")) 

#View(cont)
schedule(a_contract)
cont[["clauses"]][[1]][["start_date"]]


jameslairdsmith/contractr documentation built on May 26, 2019, 9:32 a.m.