All Projects → stevecondylios → priceR

stevecondylios / priceR

Licence: other
Economics and Pricing in R

Programming Languages

r
7636 projects

Projects that are alternatives of or similar to priceR

Akshare
AKShare is an elegant and simple financial data interface library for Python, built for human beings! 开源财经数据接口库
Stars: ✭ 4,334 (+13443.75%)
Mutual labels:  finance, economics
Dash
Analytical Web Apps for Python, R, Julia, and Jupyter. No JavaScript Required.
Stars: ✭ 15,592 (+48625%)
Mutual labels:  finance, modeling
Fecon235
Notebooks for financial economics. Keywords: Jupyter notebook pandas Federal Reserve FRED Ferbus GDP CPI PCE inflation unemployment wage income debt Case-Shiller housing asset portfolio equities SPX bonds TIPS rates currency FX euro EUR USD JPY yen XAU gold Brent WTI oil Holt-Winters time-series forecasting statistics econometrics
Stars: ✭ 708 (+2112.5%)
Mutual labels:  finance, economics
ARCHModels.jl
A Julia package for estimating ARMA-GARCH models.
Stars: ✭ 63 (+96.88%)
Mutual labels:  finance, econometrics
edgar-crawler
Download financial reports from SEC's EDGAR. Extract clean textual data from specific item sections and bootstrap your financial NLP research. Software from the research paper published in ECONLP 2021.
Stars: ✭ 71 (+121.88%)
Mutual labels:  finance, economics
ESL
​The Economic Simulation Library provides an extensive collection of tools to develop, test, analyse and calibrate economic and financial agent-based models. The library is designed to take advantage of different computer architectures. In order to facilitate rapid iteration during model development the library can use parallel computation. Econ…
Stars: ✭ 36 (+12.5%)
Mutual labels:  finance, economics
Volume approximation
Practical volume computation and sampling in high dimensions
Stars: ✭ 75 (+134.38%)
Mutual labels:  finance, cran
SMC.jl
Sequential Monte Carlo algorithm for approximation of posterior distributions.
Stars: ✭ 53 (+65.63%)
Mutual labels:  economics, econometrics
ose-course-data-science
course on data science for economists
Stars: ✭ 81 (+153.13%)
Mutual labels:  economics, econometrics
Microeconometrics.jl
Microeconometric estimation in Julia
Stars: ✭ 30 (-6.25%)
Mutual labels:  economics, econometrics
akshare
AKShare is an elegant and simple financial data interface library for Python, built for human beings! 开源财经数据接口库
Stars: ✭ 5,155 (+16009.38%)
Mutual labels:  finance, economics
mxfactorial
a payment application intended for deployment by the united states treasury
Stars: ✭ 36 (+12.5%)
Mutual labels:  finance, economics
Arsenal
An Arsenal of 'R' Functions for Large-Scale Statistical Summaries
Stars: ✭ 171 (+434.38%)
Mutual labels:  cran, modeling
ctv-finance
CRAN Task View: Empirical Finance
Stars: ✭ 51 (+59.38%)
Mutual labels:  finance, cran
Appelpy
Applied Econometrics Library for Python
Stars: ✭ 136 (+325%)
Mutual labels:  modeling, economics
Fecon236
Tools for financial economics. Curated wrapper over Python ecosystem. Source code for fecon235 Jupyter notebooks.
Stars: ✭ 72 (+125%)
Mutual labels:  finance, economics
Econ-Data-Science
Articles/ Journals and Videos related to Economics📈 and Data Science 📊
Stars: ✭ 102 (+218.75%)
Mutual labels:  economics, econometrics
econ5170
Econ5170@CUHK: Computational Methods in Economics (2020 Spring).
Stars: ✭ 127 (+296.88%)
Mutual labels:  economics, econometrics
Dash.jl
Dash for Julia - A Julia interface to the Dash ecosystem for creating analytic web applications in Julia. No JavaScript required.
Stars: ✭ 248 (+675%)
Mutual labels:  finance, modeling
BeaData.jl
A Julia interface for retrieving data from the Bureau of Economic Analysis (BEA).
Stars: ✭ 17 (-46.87%)
Mutual labels:  economics, econometrics

priceR

CRAN status R build status

priceR contains 4 types of capabilties:

  • Exchange Rates - easily retrieve exchange rates for immediate use
  • Inflation - easily inflate past (nominal) values into present day (real) prices
  • Regular Expressions - easily extract common pricing patterns from free text
  • Formatting - easily handle currencies in written work, including Rmarkdown documents

Installation

Installation via CRAN install.packages("priceR")

library(priceR)
library(tidyverse)
options(scipen = 100); options(digits = 6)

Exchange rates

Current exchange rates

View the current exchange rates for 170 currencies (see them all by running currencies()):

exchange_rate_latest("USD") %>% 
  head(10)
## Daily USD exchange rate as at end of day 2022-07-23 GMT

##    currency one_usd_is_equivalent_to
## 1       AED                  3.67181
## 2       AFN                 89.99649
## 3       ALL                114.75591
## 4       AMD                410.82630
## 5       ANG                  1.80343
## 6       AOA                431.79941
## 7       ARS                129.64170
## 8       AUD                  1.44352
## 9       AWG                  1.79355
## 10      AZN                  1.69931

Historical exchange rates

Here’s an example of how to get exchange rates for some currency pairs:

# Retieve AUD to USD exchange rates
au <- historical_exchange_rates("AUD", to = "USD",
                          start_date = "2010-01-01", end_date = "2020-06-30")

# Retieve AUD to EUR exchange rates
ae <- historical_exchange_rates("AUD", to = "EUR",
                          start_date = "2010-01-01", end_date = "2020-06-30")

# Combine
cur <- au %>% left_join(ae, by = "date")

head(cur)
##         date one_AUD_equivalent_to_x_USD one_AUD_equivalent_to_x_EUR
## 1 2010-01-01                    0.898084                    0.624103
## 2 2010-01-02                    0.898084                    0.624103
## 3 2010-01-03                    0.898084                    0.624103
## 4 2010-01-04                    0.912623                    0.632711
## 5 2010-01-05                    0.912011                    0.634840
## 6 2010-01-06                    0.920736                    0.639223

And to plot the exchange rate data:

library(ggplot2)
library(ggthemes)
library(ggrepel)

cur %>% 
  rename(aud_to_usd = one_AUD_equivalent_to_x_USD,
         aud_to_eur = one_AUD_equivalent_to_x_EUR) %>% 
  pivot_longer(c("aud_to_usd", "aud_to_eur")) %>% 
  mutate(date = as.Date(date)) %>% 
  ggplot(aes(x=date, y = value, colour=name)) +
  geom_line(size=1) + 
  scale_color_manual(
    breaks = c("aud_to_usd", "aud_to_eur"), # Sets order in legend
    labels = c( "AUD to USD", "AUD to EUR"), # Pretty names in legend
    values = c("#02506A", "#03A5DC") # Sets line/legend colours
    ) + 
  scale_x_date(date_labels = "%b %Y", date_breaks = "6 month") +
  scale_y_continuous(
    expand = c(0, 0), 
    limits = c(0, 1.5)
    ) +
  labs(
    title = "AUD to USD and EUR 2010 to 2020",
    subtitle = "Plotting the Australian Dollar against the USD and Euro",
    y = "Exchange Rate"
    ) +
  theme_economist() + 
  theme(
    plot.title = element_text(size = 18, margin=margin(0,0,8,0)),
    axis.title.x = element_blank(),
    axis.ticks.x = element_blank(),
    axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1),
    axis.title.y = element_text(vjust = 3.5),
    legend.position="bottom",
    legend.title = element_blank()
    ) 

cur %>% 
  tail(200) %>% 
  rename(aud_to_usd = one_AUD_equivalent_to_x_USD,
         aud_to_eur = one_AUD_equivalent_to_x_EUR) %>%  
  mutate(date = as.Date(date)) %>% 
  ggplot(aes(x = date, y = aud_to_usd, group = 1)) +
  geom_line(colour = "#F15B40") +
  geom_smooth(method = 'loess', colour="#03A5DC") + 
  scale_x_date(date_labels = "%b %Y", date_breaks = "1 month") +
  labs(
    title = "AUD to USD over last 200 days",
    subtitle = "AUD to USD Exchange Rate; Polynomial regression trendline",
    y = "Exchange Rate"
    ) +
  theme_economist() + 
  theme(
    plot.title = element_text(size = 18, margin=margin(0,0,8,0)),
    axis.title.x = element_blank(),
    axis.ticks.x = element_blank(),
    axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1),
    axis.title.y = element_text(vjust = 3.5),
    legend.position="bottom",
    legend.title = element_blank()
    ) 

cur %>% 
  tail(365 * 8) %>% 
  rename(aud_to_usd = one_AUD_equivalent_to_x_USD,
         aud_to_eur = one_AUD_equivalent_to_x_EUR) %>% 
  mutate(date = as.Date(date)) %>% 
  ggplot(aes(x = date, y = aud_to_eur, group = 1)) +
  geom_line() +
  geom_smooth(method = 'loess', se = TRUE) + 
  geom_line(colour = "#02506A") +
  geom_smooth(method = 'loess', colour="#03A5DC") + 
  scale_x_date(date_labels = "%Y", date_breaks = "1 year") +
  labs(
    title = "AUD to EUR over last 8 years",
    subtitle = "AUD to EUR Exchange Rate; Polynomial regression trendline",
    y = "Exchange Rate"
    ) +
  theme_economist() + 
  theme(
    plot.title = element_text(size = 18, margin=margin(0,0,8,0)),
    axis.title.x = element_blank(),
    axis.ticks.x = element_blank(),
    axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1),
    axis.title.y = element_text(vjust = 3.5),
    legend.position="bottom",
    legend.title = element_blank()
    ) 

Inflation

Adjust prices for inflation

adjust_for_inflation() automatically converts between nominal and real dollars, or in/deflates prices from one year’s prices to another’s.

It works for 304 countries / areas (see them with all by running show_countries()).

set.seed(123)
nominal_prices <- rnorm(10, mean=10, sd=3)
years <- round(rnorm(10, mean=2006, sd=5))
df <- data.frame(years, nominal_prices)

df$in_2008_dollars <- adjust_for_inflation(nominal_prices, years, "US", to_date = 2008)
## Generating URL to request all 299 results
## Retrieving inflation data for US 
## Generating URL to request all 62 results
df
##    years nominal_prices in_2008_dollars
## 1   2012        8.31857         7.66782
## 2   2008        9.30947         9.30947
## 3   2008       14.67612        14.67612
## 4   2007       10.21153        10.60356
## 5   2003       10.38786        12.15782
## 6   2015       15.14519        13.26473
## 7   2008       11.38275        11.38275
## 8   1996        6.20482         8.51713
## 9   2010        7.93944         7.67319
## 10  2004        8.66301         9.87471

Extraction helpers

These helpers let you extract useful numeric data from messy free text (character) data.

Extract salary from free text

extract_salary() extracts salaries as useful numeric data from non-standard free text

messy_salary_data <- c(
  "$90000 - $120000 per annum",
  "$90k - $110k p.a.",
  "$110k - $120k p.a. + super + bonus + benefits",
  "$140K-$160K + Super + Bonus/Equity",
  "$200,000 - $250,000 package",
  "c$200K Package Neg",
  "$700 p/d",                                       # daily
  "$120 - $140 (Inc. Super) per hour",              # hourly
  "Competitive"                                     # nothing useful (will return NA)
)

messy_salary_data %>%
  extract_salary(include_periodicity = TRUE, 
                 salary_range_handling = "average")
##   salary periodicity
## 1 105000      Annual
## 2 100000      Annual
## 3 115000      Annual
## 4 150000      Annual
## 5 225000      Annual
## 6 200000      Annual
## 7 175000       Daily
## 8 260000      Hourly
## 9     NA      Annual

Formatting helpers

Neatly format currencies

format_currency() makes nicely formats numeric data:

format_currency("22500000", "¥")
## [1] "¥22,500,000"

format_dollars() is the same but exclusively for dollars:

format_dollars(c("445.50", "199.99"), digits = 2)
## [1] "$445.50" "$199.99"

More about priceR

Research and academia

Curran-Groome, W., Hino, M., BenDor, T. and Salvesen, D., 2022. Complexities and costs of floodplain buyout implementation, Land Use Policy, Volume 118, July 2022.

Thomas, C., Shae, W., Koestler, D., DeFor, T., Bahr, N. and Alpern, J., 2022. Antifungal drug price increases in the United States 2000–2019, Mycoses, Online Ahead of Print, June 2022.

Petitbon, A. and Hitchcock, D., 2022. What Kind of Music Do You Like? A Statistical Analysis of Music Genre Popularity Over Time, Journal of Data Science, Volume 20 (2), April 2022.

Widdicombe, J., Basáñez, M., Entezami, M., Jackson, D., Larrieu, E. and Prada, J., 2022. The economic evaluation of Cystic echinococcosis control strategies focused on zoonotic hosts: A scoping review, PLoS Neglected Tropical Diseases, Volume 16 (7), July 2022.

Guides and tutorials

How to Convert Between Currencies Using priceR by Bryan Shalloway

Contributing to priceR

If your research, guide or tutorial uses priceR, please contact the priceR maintainer (or create an issue) so your work can be included here.

Issues and Feature Requests

When reporting an issue, please include:

  • Example code that reproduces the observed behavior.
  • An explanation of what the expected behavior is.
  • A specific url you’re attempting to retrieve R code from (if that’s what your issue concerns)

For feature requests, raise an issue with the following:

  • The desired functionality
  • Example inputs and desired output

Pull Requests

Pull requests are welcomed. Before doing so, please create an issue or email me with your idea.

Any new functions should follow the conventions established by the the package’s existing functions. Please ensure

  • Functions are sensibly named
  • The intent of the contribution is clear
  • At least one example is provided in the documentation
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].