Helper function to parse a 'csv' file obtained from the 'PredictIt' website, containing historical 'OHLCV' (Open, High, Low, Close, Volume) data, into an object of class xts.

parse_historical_csv(csv_path, filename = NA)

Arguments

csv_path

Path to a 'csv' file containing historical 'OHLCV' data for a specific contract. Expected format is the same schema as the 'csv' file downloaded from the 'PredictIt' website.

filename

Optional name to give the 'csv' file when the filepath is derived from a temporary directory.

Value

A named list containing the following elements:

data

An S3 object of class xts. Time series containing the 'close' price data for the contract provided.

contract

A character representing the contract name, derived from the input file name. If a filename argument is provided, the contract name will be assigned to that value.

Examples

filename <- "What_will_be_the_balance_of_power_in_Congress_after_the_2020_election.csv"
csv_path <- system.file("extdata", filename, package = "rpredictit")
parse_historical_csv(csv_path)
#> $data
#>            D House, D Senate D House, R Senate R House, R Senate
#> 2019-09-25 "0.33"            "0.52"            "0.01"           
#> 2019-09-26 "0.32"            "0.50"            "0.02"           
#> 2019-09-27 "0.31"            "0.52"            "0.01"           
#> 2019-09-28 "0.33"            "0.52"            "0.02"           
#> 2019-09-29 "0.33"            "0.51"            "0.02"           
#> 2019-09-30 "0.33"            "0.52"            "0.02"           
#> 2019-10-01 "0.33"            "0.52"            "0.02"           
#> 2019-10-02 "0.30"            "0.52"            "0.01"           
#> 2019-10-03 "0.32"            "0.52"            "0.01"           
#> 2019-10-04 "0.30"            "0.51"            "0.01"           
#> 2019-10-05 "0.31"            "0.50"            "0.01"           
#> 2019-10-06 "0.30"            "0.51"            "0.01"           
#> 2019-10-07 "0.30"            "0.50"            "0.01"           
#> 2019-10-08 "0.32"            "0.51"            "0.02"           
#> 2019-10-09 "0.30"            "0.51"            "0.01"           
#> 2019-10-10 "0.32"            "0.50"            "0.01"           
#> 2019-10-11 "0.32"            "0.50"            "0.02"           
#> 2019-10-12 "0.30"            "0.50"            "0.01"           
#> 2019-10-13 "0.30"            "0.50"            "0.01"           
#> 2019-10-14 "0.32"            "0.50"            "0.01"           
#> 2019-10-15 "0.30"            "0.50"            "0.01"           
#> 2019-10-16 "0.30"            "0.49"            "0.01"           
#> 2019-10-17 "0.32"            "0.49"            "0.01"           
#> 2019-10-18 "0.31"            "0.49"            "0.02"           
#> 2019-10-19 "0.31"            "0.48"            "0.02"           
#> 2019-10-20 "0.31"            "0.48"            "0.01"           
#> 2019-10-21 "0.32"            "0.48"            "0.01"           
#> 2019-10-22 "0.31"            "0.47"            "0.01"           
#> 2019-10-23 "0.32"            "0.49"            "0.01"           
#> 2019-10-24 "0.32"            "0.49"            "0.01"           
#> 2019-10-25 "0.32"            "0.48"            "0.02"           
#> 2019-10-26 "0.32"            "0.49"            "0.02"           
#> 2019-10-27 "0.32"            "0.48"            "0.01"           
#> 2019-10-28 "0.32"            "0.49"            "0.02"           
#> 2019-10-29 "0.33"            "0.48"            "0.01"           
#> 2019-10-30 "0.33"            "0.48"            "0.01"           
#> 2019-10-31 "0.32"            "0.48"            "0.02"           
#> 2019-11-01 "0.31"            "0.49"            "0.02"           
#> 2019-11-02 "0.32"            "0.49"            "0.01"           
#> 2019-11-03 "0.31"            "0.49"            "0.02"           
#> 2019-11-04 "0.32"            "0.48"            "0.02"           
#> 2019-11-05 "0.31"            "0.48"            "0.01"           
#> 2019-11-06 "0.31"            "0.49"            "0.01"           
#> 2019-11-07 "0.32"            "0.49"            "0.01"           
#> 2019-11-08 "0.34"            "0.48"            "0.01"           
#> 2019-11-09 "0.32"            "0.48"            "0.01"           
#> 2019-11-10 "0.31"            "0.49"            "0.01"           
#> 2019-11-11 "0.33"            "0.49"            "0.01"           
#> 2019-11-12 "0.32"            "0.48"            "0.01"           
#> 2019-11-13 "0.32"            "0.49"            "0.02"           
#> 2019-11-14 "0.32"            "0.48"            "0.02"           
#> 2019-11-15 "0.33"            "0.46"            "0.02"           
#> 2019-11-16 "0.32"            "0.46"            "0.02"           
#> 2019-11-17 "0.33"            "0.47"            "0.01"           
#> 2019-11-18 "0.33"            "0.47"            "0.01"           
#> 2019-11-19 "0.32"            "0.48"            "0.01"           
#> 2019-11-20 "0.31"            "0.47"            "0.02"           
#> 2019-11-21 "0.31"            "0.47"            "0.01"           
#> 2019-11-22 "0.32"            "0.48"            "0.01"           
#> 2019-11-23 "0.32"            "0.47"            "0.02"           
#> 2019-11-24 "0.31"            "0.48"            "0.01"           
#> 2019-11-25 "0.32"            "0.48"            "0.01"           
#> 2019-11-26 "0.31"            "0.49"            "0.01"           
#> 2019-11-27 "0.31"            "0.49"            "0.01"           
#> 2019-11-28 "0.30"            "0.49"            "0.01"           
#> 2019-11-29 "0.30"            "0.49"            "0.01"           
#> 2019-11-30 "0.31"            "0.49"            "0.01"           
#> 2019-12-01 "0.30"            "0.48"            "0.01"           
#> 2019-12-02 "0.30"            "0.49"            "0.01"           
#> 2019-12-03 "0.30"            "0.48"            "0.01"           
#> 2019-12-04 "0.30"            "0.49"            "0.01"           
#> 2019-12-05 "0.31"            "0.49"            "0.01"           
#> 2019-12-06 "0.30"            "0.49"            "0.01"           
#> 2019-12-07 "0.31"            "0.49"            "0.01"           
#> 2019-12-08 "0.31"            "0.49"            "0.02"           
#> 2019-12-09 "0.31"            "0.49"            "0.02"           
#> 2019-12-10 "0.30"            "0.49"            "0.02"           
#> 2019-12-11 "0.28"            "0.48"            "0.01"           
#> 2019-12-12 "0.27"            "0.50"            "0.02"           
#> 2019-12-13 "0.27"            "0.50"            "0.01"           
#> 2019-12-14 "0.27"            "0.49"            "0.02"           
#> 2019-12-15 "0.25"            "0.51"            "0.02"           
#> 2019-12-16 "0.24"            "0.50"            "0.02"           
#> 2019-12-17 "0.25"            "0.50"            "0.01"           
#> 2019-12-18 "0.26"            "0.51"            "0.01"           
#> 2019-12-19 "0.25"            "0.52"            "0.02"           
#> 2019-12-20 "0.25"            "0.55"            "0.01"           
#> 2019-12-21 "0.24"            "0.55"            "0.01"           
#> 2019-12-22 "0.25"            "0.57"            "0.01"           
#> 2019-12-23 "0.25"            "0.55"            "0.01"           
#>            R House, D Senate
#> 2019-09-25 "0.23"           
#> 2019-09-26 "0.23"           
#> 2019-09-27 "0.23"           
#> 2019-09-28 "0.24"           
#> 2019-09-29 "0.24"           
#> 2019-09-30 "0.24"           
#> 2019-10-01 "0.23"           
#> 2019-10-02 "0.23"           
#> 2019-10-03 "0.23"           
#> 2019-10-04 "0.26"           
#> 2019-10-05 "0.26"           
#> 2019-10-06 "0.25"           
#> 2019-10-07 "0.25"           
#> 2019-10-08 "0.26"           
#> 2019-10-09 "0.25"           
#> 2019-10-10 "0.26"           
#> 2019-10-11 "0.27"           
#> 2019-10-12 "0.27"           
#> 2019-10-13 "0.26"           
#> 2019-10-14 "0.27"           
#> 2019-10-15 "0.28"           
#> 2019-10-16 "0.27"           
#> 2019-10-17 "0.27"           
#> 2019-10-18 "0.28"           
#> 2019-10-19 "0.27"           
#> 2019-10-20 "0.27"           
#> 2019-10-21 "0.27"           
#> 2019-10-22 "0.26"           
#> 2019-10-23 "0.27"           
#> 2019-10-24 "0.26"           
#> 2019-10-25 "0.27"           
#> 2019-10-26 "0.28"           
#> 2019-10-27 "0.28"           
#> 2019-10-28 "0.26"           
#> 2019-10-29 "0.26"           
#> 2019-10-30 "0.26"           
#> 2019-10-31 "0.25"           
#> 2019-11-01 "0.26"           
#> 2019-11-02 "0.27"           
#> 2019-11-03 "0.25"           
#> 2019-11-04 "0.26"           
#> 2019-11-05 "0.25"           
#> 2019-11-06 "0.27"           
#> 2019-11-07 "0.26"           
#> 2019-11-08 "0.26"           
#> 2019-11-09 "0.26"           
#> 2019-11-10 "0.25"           
#> 2019-11-11 "0.25"           
#> 2019-11-12 "0.25"           
#> 2019-11-13 "0.27"           
#> 2019-11-14 "0.27"           
#> 2019-11-15 "0.28"           
#> 2019-11-16 "0.27"           
#> 2019-11-17 "0.25"           
#> 2019-11-18 "0.25"           
#> 2019-11-19 "0.24"           
#> 2019-11-20 "0.25"           
#> 2019-11-21 "0.25"           
#> 2019-11-22 "0.25"           
#> 2019-11-23 "0.25"           
#> 2019-11-24 "0.25"           
#> 2019-11-25 "0.24"           
#> 2019-11-26 "0.25"           
#> 2019-11-27 "0.26"           
#> 2019-11-28 "0.25"           
#> 2019-11-29 "0.25"           
#> 2019-11-30 "0.26"           
#> 2019-12-01 "0.26"           
#> 2019-12-02 "0.26"           
#> 2019-12-03 "0.26"           
#> 2019-12-04 "0.26"           
#> 2019-12-05 "0.27"           
#> 2019-12-06 "0.27"           
#> 2019-12-07 "0.28"           
#> 2019-12-08 "0.26"           
#> 2019-12-09 "0.27"           
#> 2019-12-10 "0.27"           
#> 2019-12-11 "0.27"           
#> 2019-12-12 "0.28"           
#> 2019-12-13 "0.29"           
#> 2019-12-14 "0.28"           
#> 2019-12-15 "0.29"           
#> 2019-12-16 "0.31"           
#> 2019-12-17 "0.31"           
#> 2019-12-18 "0.30"           
#> 2019-12-19 "0.28"           
#> 2019-12-20 "0.28"           
#> 2019-12-21 "0.27"           
#> 2019-12-22 "0.26"           
#> 2019-12-23 "0.27"           
#> 
#> $contract
#> [1] "What will be the balance of power in Congress after the 2020 election"
#>