Chang-López, R. (2024). R package RchangActuarial: Comprehensive Financial and Actuarial Package in R | Paquete Financiero y Actuarial Integral en R: RchangActuarial.
Includes essential functions for calculating Net Present Value (NPV),
Internal Rate of Return (IRR), and Modified Internal Rate of Return
(MIRR).
Incluye funciones esenciales para calcular el Valor Presente Neto (VPN),
la Tasa Interna de Retorno (TIR) y la Tasa Interna de Retorno Modificada
(TIRM).
Tools for optimizing portfolio composition based on risk and return
metrics, ensuring efficient investment strategies.
Herramientas para optimizar la composición de carteras basadas en
métricas de riesgo y rendimiento, asegurando estrategias de inversión
eficientes.
Generates detailed tables for loan amortization and asset
depreciation, facilitating financial planning and analysis.
Genera tablas detalladas para la amortización de préstamos y la
depreciación de activos, facilitando la planificación y análisis
financiero.
Dedicated functions for calculating bond and stock prices and yields,
providing crucial information for investment decision-making.
Funciones dedicadas para el cálculo de precios y rendimientos de bonos y
acciones, proporcionando información crucial para la toma de decisiones
de inversión.
Performs advanced portfolio analysis and visualizes results with
interactive charts, enhancing understanding of investment
performance.
Realiza análisis avanzados de carteras y visualiza resultados con
gráficos interactivos, mejorando la comprensión del rendimiento de las
inversiones.
Retrieves and visualizes stock market data, including candlestick
charts, for in-depth market analysis.
Obtiene y visualiza datos del mercado de valores, incluyendo gráficos de
velas, para análisis profundos del mercado.
Easy installation and comprehensive documentation in English and
Spanish, accessible to users worldwide.
Instalación sencilla y documentación completa en inglés y español,
accesible para usuarios a nivel mundial
Examples and User Manual Manual download
Ejemplos y Manual de Usuario Descargar manual aquí
#devtools::install_github("rchang-1/RchangActuarialF")
rchang@unah.edu.hn / rchang@unitec.edu
Professor of Doctoral and Master’s Programs in Systems, Economics, and Statistics for Scientific Research
Profesor de Doctorado y Maestría en Sistemas, Economía y Estadística para la Investigación Científica
#Installation
Installation in R Studio 1. Install and load the devtools library, then run:
#2. devtools::install_github("rchang-1/RchangActuarialF")
Installation in Google Colab To work in Google Colab, it is suggested to run the following lines before executing the previous line: install.packages(“plotly”) install.packages(“htmltools”) install.packages(“devtools”) install.packages(“TTR”) install.packages(“textshaping”) install.packages(“quantmod”) install.packages(“xts”)
Then load the libraries
library(“plotly”) library(“TTR”) library(“textshaping”) library(“quantmod”) library(“xts”) library(“htmltools”) library(“devtools”)
#Finally, execute: devtools::install_github(“rchang-1/RchangActuarialF”)
#Instalación
Instalación en R Studio 1. Instalar y cargar la librería devtools, luego ejecutar:
#2. devtools::install_github("rchang-1/RchangActuarialF")
#Enter one or more numbers, or an empty line to skip updates #Puedes Darle enter, Skip updates (Salta los updates)
Instalación en Google Colab
Para trabajar en google colab to.R se sugiere antes de correr la línea anterior, ejecutar las siguientes: install.packages(“plotly”) install.packages(“htmltools”) install.packages(“devtools”) install.packages(“TTR”) install.packages(“textshaping”) install.packages(“quantmod”) install.packages(“xts”) Luego cargar las librerias library(“plotly”) library(“TTR”) library(“textshaping”) library(“quantmod”) library(“xts”) library(“htmltools”) library(“devtools”)
#Por último ejecutar: devtools::install_github(“rchang-1/RchangActuarialF”)
library(RchangActuarialF)
## Warning: replacing previous import 'ggplot2::last_plot' by 'plotly::last_plot'
## when loading 'RchangActuarialF'
returns <- matrix(rnorm(100 * 4, mean = 0.01, sd = 0.02), nrow = 100, ncol = 4)
colnames(returns) <- c("AMZN", "MSFT", "TSLA", "AAPL")
cov_matrix <- cov(returns)
frontier <- efficient_frontier(returns, cov_matrix)
plot_efficient_frontier_A(frontier)
## Loading required package: ggplot2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
bond_yield_plotly(1000, 950, 0.05, 10)
## A line object has been specified, but lines is not in the mode
## Adding lines to the mode...
set.seed(123)
weights <- c(0.5, 0.3, 0.2)
asset_returns <- matrix(rnorm(100 * length(weights), mean = 0.01, sd = 0.02), nrow = 100, ncol = length(weights))
colnames(asset_returns) <- paste0("Activo_", 1:length(weights))
#' #' # Plot portfolio return
#' #' # Graficar el rendimiento del portafolio
plot_portfolio_return(weights, asset_returns)
## A marker object has been specified, but markers is not in the mode
## Adding markers to the mode...
returns <- matrix(c(0.1, 0.2, 0.15, 0.05, 0.1, 0.12), ncol = 2)
covariance_matrix <- matrix(c(0.005, -0.010, -0.010, 0.040), ncol = 2)
portfolio_optimization(returns, covariance_matrix)
## [1] 0.7692308 0.2307692
#’ @title Función de Retorno del Portafolio #’ @description Calcula el retorno de un portafolio dados los pesos y los retornos de #los activos. #’ @param pesos Un vector numérico con los pesos del portafolio (proporciones). #’ @param retornos Un vector numérico o una matriz de retornos de los activos. #’ @return El retorno del portafolio.
weights <- c(0.5, 0.3, 0.2)
asset_returns <- c(0.1, 0.05, 0.08)
portfolio_return(weights, asset_returns)
## [1] 0.081
sum_of_years_digits_depreciation(10000, 2000, 5)
## Year Depreciation Book_Value
## 1 1 2666.6667 7333.333
## 2 2 2133.3333 5200.000
## 3 3 1600.0000 3600.000
## 4 4 1066.6667 2533.333
## 5 5 533.3333 2000.000
#Obtener Data Financiera diaria
get.ohlc.yahoo(symbol="AAPL", start="2023-01-01", end="2024-07-01", freq="d")
## Loading required package: quantmod
## Loading required package: xts
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
## Loading required package: TTR
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
## Date Open High Low Close Volume Adjusted
## 1 2023-01-03 130.2800 130.9000 124.1700 125.070 112117471 123.8853
## 2 2023-01-04 126.8900 128.6557 125.0800 126.360 89113633 125.1631
## 3 2023-01-05 127.1300 127.7700 124.7600 125.020 80962708 123.8357
## 4 2023-01-06 126.0100 130.2900 124.8900 129.620 87754715 128.3922
## 5 2023-01-09 130.4650 133.4100 129.8900 130.150 70790813 128.9171
## 6 2023-01-10 130.2600 131.2636 128.1200 130.730 63896155 129.4916
## 7 2023-01-11 131.2500 133.5100 130.4600 133.490 69458949 132.2255
## 8 2023-01-12 133.8800 134.2600 131.4400 133.410 71379648 132.1463
## 9 2023-01-13 132.0300 134.9200 131.6600 134.760 57809719 133.4835
## 10 2023-01-17 134.8300 137.2900 134.1300 135.940 63646627 134.6523
## 11 2023-01-18 136.8150 138.6100 135.0300 135.210 69672800 133.9292
## 12 2023-01-19 134.0800 136.2500 133.7700 135.270 58280413 133.9887
## 13 2023-01-20 135.2800 138.0200 134.2200 137.870 80223626 136.5640
## 14 2023-01-23 138.1200 143.3150 137.9000 141.110 81760313 139.7733
## 15 2023-01-24 140.3050 143.1600 140.3000 142.530 66435142 141.1799
## 16 2023-01-25 140.8900 142.4300 138.8100 141.860 65799349 140.5162
## 17 2023-01-26 143.1700 144.2500 141.9000 143.960 54105068 142.5963
## 18 2023-01-27 143.1550 147.2300 143.0800 145.930 70555843 144.5477
## 19 2023-01-30 144.9550 145.5500 142.8500 143.000 64015274 141.6454
## 20 2023-01-31 142.7000 144.3400 142.2800 144.290 65874459 142.9232
## 21 2023-02-01 143.9700 146.6100 141.3200 145.430 77663633 144.0524
## 22 2023-02-02 148.9000 151.1800 148.1700 150.820 118338980 149.3914
## 23 2023-02-03 148.0300 157.3800 147.8300 154.500 154357337 153.0365
## 24 2023-02-06 152.5750 153.1000 150.7800 151.730 69858306 150.2927
## 25 2023-02-07 150.6400 155.2300 150.6400 154.650 83322551 153.1851
## 26 2023-02-08 153.8800 154.5800 151.1680 151.920 64120079 150.4809
## 27 2023-02-09 153.7750 154.3300 150.4200 150.870 56007143 149.4409
## 28 2023-02-10 149.4600 151.3401 149.2200 151.010 57450708 149.8079
## 29 2023-02-13 150.9520 154.2600 150.9200 153.850 62199013 152.6253
## 30 2023-02-14 152.1200 153.7700 150.8600 153.200 61707573 151.9805
## 31 2023-02-15 153.1100 155.5000 152.8800 155.330 65669252 154.0936
## 32 2023-02-16 153.5100 156.3300 153.3475 153.710 68167942 152.4865
## 33 2023-02-17 152.3500 153.0000 150.8500 152.550 59144118 151.3357
## 34 2023-02-21 150.2000 151.3000 148.4050 148.480 58867230 147.2981
## 35 2023-02-22 148.8700 149.9500 147.1600 148.910 51011305 147.7247
## 36 2023-02-23 150.0900 150.3400 147.2400 149.400 48394249 148.2108
## 37 2023-02-24 147.1100 147.1900 145.7202 146.710 55469606 145.5422
## 38 2023-02-27 147.7100 149.1700 147.4500 147.920 44998470 146.7425
## 39 2023-02-28 147.0500 149.0800 146.8300 147.410 50546998 146.2366
## 40 2023-03-01 146.8300 147.2285 145.0100 145.310 55478991 144.1533
## 41 2023-03-02 144.3800 146.7100 143.9000 145.910 52279761 144.7486
## 42 2023-03-03 148.0450 151.1100 147.3300 151.030 70732297 149.8278
## 43 2023-03-06 153.7850 156.3000 153.4600 153.830 87558028 152.6055
## 44 2023-03-07 153.7000 154.0299 151.1300 151.600 56182028 150.3932
## 45 2023-03-08 152.8100 153.4700 151.8300 152.870 47204791 151.6531
## 46 2023-03-09 153.5590 154.5350 150.2250 150.590 53833582 149.3913
## 47 2023-03-10 150.2100 150.9400 147.6096 148.500 68572400 147.3179
## 48 2023-03-13 147.8050 153.1400 147.7000 150.470 84457122 149.2722
## 49 2023-03-14 151.2800 153.4000 150.1000 152.590 73695893 151.3754
## 50 2023-03-15 151.1900 153.2450 149.9200 152.990 77167866 151.7722
## 51 2023-03-16 152.1600 156.4600 151.6400 155.850 76254419 154.6094
## 52 2023-03-17 156.0800 156.7400 154.2800 155.000 98944633 153.7662
## 53 2023-03-20 155.0700 157.8200 154.1500 157.400 73641415 156.1470
## 54 2023-03-21 157.3200 159.4000 156.5400 159.280 73938285 158.0121
## 55 2023-03-22 159.3000 162.1400 157.8100 157.830 75701811 156.5737
## 56 2023-03-23 158.8300 161.5501 157.6800 158.930 67969123 157.6649
## 57 2023-03-24 158.8600 160.3400 157.8500 160.250 59256343 158.9744
## 58 2023-03-27 159.9400 160.7700 157.8700 158.280 52390266 157.0201
## 59 2023-03-28 157.9700 158.4900 155.9800 157.650 45992152 156.3951
## 60 2023-03-29 159.3700 161.0500 159.3500 160.770 51305691 159.4902
## 61 2023-03-30 161.5300 162.4700 161.2710 162.360 49501689 161.0676
## 62 2023-03-31 162.4400 165.0000 161.9100 164.900 68749792 163.5874
## 63 2023-04-03 164.2700 166.2900 164.2200 166.170 56976187 164.8473
## 64 2023-04-04 166.5950 166.8400 165.1100 165.630 46278295 164.3116
## 65 2023-04-05 164.7400 165.0500 161.8000 163.760 51511744 162.4565
## 66 2023-04-06 162.4300 164.9584 162.0000 164.660 45390123 163.3493
## 67 2023-04-10 161.4200 162.0300 160.0800 162.030 47716882 160.7402
## 68 2023-04-11 162.3500 162.3600 160.5100 160.800 47644217 159.5200
## 69 2023-04-12 161.2200 162.0600 159.7800 160.100 50133062 158.8256
## 70 2023-04-13 161.6300 165.8000 161.4200 165.560 68445649 164.2421
## 71 2023-04-14 164.5900 166.3200 163.8200 165.210 49386480 163.8949
## 72 2023-04-17 165.0900 165.3900 164.0300 165.230 41516217 163.9147
## 73 2023-04-18 166.1000 167.4100 165.6500 166.470 49923008 165.1449
## 74 2023-04-19 165.8000 168.1600 165.5400 167.630 47720166 166.2957
## 75 2023-04-20 166.0900 167.8700 165.5600 166.650 52456377 165.3234
## 76 2023-04-21 165.0500 166.4521 164.4900 165.020 58337341 163.7064
## 77 2023-04-24 165.0000 165.6000 163.8900 165.330 41949581 164.0139
## 78 2023-04-25 165.1900 166.3050 163.7300 163.770 48714063 162.4664
## 79 2023-04-26 163.0550 165.2800 162.8000 163.760 45498796 162.4565
## 80 2023-04-27 165.1900 168.5600 165.1900 168.410 64902329 167.0694
## 81 2023-04-28 168.4900 169.8500 167.8801 169.680 55275851 168.3293
## 82 2023-05-01 169.2800 170.4500 168.6400 169.590 52472936 168.2400
## 83 2023-05-02 170.0900 170.3500 167.5400 168.540 48425696 167.1984
## 84 2023-05-03 169.5000 170.9200 167.1600 167.450 65136018 166.1171
## 85 2023-05-04 164.8900 167.0400 164.3100 165.790 81235427 164.4703
## 86 2023-05-05 170.9750 174.3000 170.7600 173.570 113453171 172.1884
## 87 2023-05-08 172.4800 173.8500 172.1100 173.500 55962793 172.1189
## 88 2023-05-09 173.0500 173.5400 171.6000 171.770 45326874 170.4027
## 89 2023-05-10 173.0200 174.0300 171.9000 173.555 53724501 172.1735
## 90 2023-05-11 173.8500 174.5900 172.1700 173.750 49514676 172.3669
## 91 2023-05-12 173.6200 174.0600 171.0000 172.570 45533138 171.4331
## 92 2023-05-15 173.1600 173.2100 171.4700 172.070 37266659 170.9364
## 93 2023-05-16 171.9900 173.1383 171.7991 172.070 42110293 170.9364
## 94 2023-05-17 171.7100 172.9250 170.4201 172.690 57951604 171.5523
## 95 2023-05-18 173.0000 175.2400 172.5800 175.050 65496657 173.8968
## 96 2023-05-19 176.3900 176.3900 174.9400 175.160 55809475 174.0060
## 97 2023-05-22 173.9800 174.7100 173.4500 174.200 43570932 173.0524
## 98 2023-05-23 173.1300 173.3794 171.2750 171.560 50747263 170.4297
## 99 2023-05-24 171.0900 172.4183 170.5200 171.840 45143488 170.7079
## 100 2023-05-25 172.4100 173.8950 171.6900 172.990 56058258 171.8503
## 101 2023-05-26 173.3200 175.7700 173.1100 175.430 54834975 174.2742
## 102 2023-05-30 176.9600 178.9900 176.5700 177.300 55964401 176.1319
## 103 2023-05-31 177.3250 179.3500 176.7600 177.250 99625288 176.0823
## 104 2023-06-01 177.7000 180.1200 176.9306 180.090 68901809 178.9036
## 105 2023-06-02 181.0300 181.7800 179.2600 180.950 61996913 179.7579
## 106 2023-06-05 182.6300 184.9510 178.0350 179.580 121946497 178.3969
## 107 2023-06-06 179.9650 180.1200 177.4300 179.210 64848374 178.0294
## 108 2023-06-07 178.4400 181.2100 177.3200 177.820 61944615 176.6485
## 109 2023-06-08 177.8950 180.8400 177.4600 180.570 50214881 179.3804
## 110 2023-06-09 181.5000 182.2300 180.6300 180.960 48899973 179.7678
## 111 2023-06-12 181.2700 183.8900 180.9700 183.790 54754995 182.5792
## 112 2023-06-13 182.8000 184.1500 182.4400 183.310 54929129 182.1023
## 113 2023-06-14 183.3700 184.3900 182.0200 183.950 57462882 182.7381
## 114 2023-06-15 183.9600 186.5200 183.7800 186.010 65433166 184.7846
## 115 2023-06-16 186.7300 186.9900 184.2700 184.920 101256225 183.7018
## 116 2023-06-20 184.4100 186.1000 184.4100 185.010 49799092 183.7911
## 117 2023-06-21 184.9000 185.4100 182.5901 183.960 49515697 182.7481
## 118 2023-06-22 183.7400 187.0450 183.6700 187.000 51245327 185.7680
## 119 2023-06-23 185.5500 187.5600 185.0100 186.680 53116996 185.4501
## 120 2023-06-26 187.3219 188.0500 185.2300 185.270 48088661 184.0495
## 121 2023-06-27 185.8900 188.3900 185.6700 188.060 50730846 186.8211
## 122 2023-06-28 187.9300 189.9000 187.6000 189.250 51216801 188.0032
## 123 2023-06-29 189.0800 190.0700 188.9400 189.590 46347308 188.3410
## 124 2023-06-30 191.6300 194.4800 191.2600 193.970 85213216 192.6921
## 125 2023-07-03 193.7800 193.8800 191.7600 192.460 31458198 191.1921
## 126 2023-07-05 191.5650 192.9800 190.6200 191.330 46920261 190.0695
## 127 2023-07-06 189.8400 192.0200 189.2000 191.810 45156009 190.5463
## 128 2023-07-07 191.4100 192.6700 190.2400 190.680 46814998 189.4238
## 129 2023-07-10 189.2600 189.9900 187.0350 188.610 59922163 187.3674
## 130 2023-07-11 189.1600 189.3000 186.6000 188.080 46638119 186.8409
## 131 2023-07-12 189.6800 191.7000 188.4700 189.770 60750248 188.5198
## 132 2023-07-13 190.5000 191.1900 189.7800 190.540 41342338 189.2847
## 133 2023-07-14 190.2300 191.1799 189.6300 190.690 41616242 189.4337
## 134 2023-07-17 191.9000 194.3200 191.8100 193.990 50520159 192.7120
## 135 2023-07-18 193.3500 194.3300 192.4150 193.730 48353774 192.4537
## 136 2023-07-19 193.1000 198.2300 192.6500 195.100 80507323 193.8147
## 137 2023-07-20 195.0900 196.4700 192.4950 193.130 59581196 191.8577
## 138 2023-07-21 194.1000 194.9700 191.2300 191.940 71951683 190.6755
## 139 2023-07-24 193.4100 194.9100 192.2500 192.750 45505097 191.4802
## 140 2023-07-25 193.3300 194.4400 192.9150 193.620 37283201 192.3444
## 141 2023-07-26 193.6700 195.6400 193.3200 194.500 47471868 193.2186
## 142 2023-07-27 196.0200 197.2000 192.5500 193.220 47460180 191.9471
## 143 2023-07-28 194.6700 196.6260 194.1400 195.830 48291443 194.5399
## 144 2023-07-31 196.0600 196.4900 195.2600 196.450 38824113 195.1558
## 145 2023-08-01 196.2350 196.7300 195.2800 195.605 35281426 194.3163
## 146 2023-08-02 195.0400 195.1800 191.8507 192.580 50389327 191.3113
## 147 2023-08-03 191.5700 192.3700 190.6900 191.170 62243282 189.9106
## 148 2023-08-04 185.5200 187.3800 181.9200 181.990 115956841 180.7910
## 149 2023-08-07 182.1300 183.1300 177.3500 178.850 97576069 177.6717
## 150 2023-08-08 179.6900 180.2700 177.5800 179.800 67823003 178.6155
## 151 2023-08-09 180.8700 180.9300 177.0100 178.190 60378492 177.0161
## 152 2023-08-10 179.4800 180.7500 177.6000 177.970 54686851 176.7976
## 153 2023-08-11 177.3200 178.6200 176.5500 177.790 52036672 176.8572
## 154 2023-08-14 177.9700 179.6900 177.3050 179.460 43675627 178.5185
## 155 2023-08-15 178.8800 179.4800 177.0500 177.450 43622593 176.5190
## 156 2023-08-16 177.1300 178.5400 176.5000 176.570 46964857 175.6436
## 157 2023-08-17 177.1400 177.5054 173.4800 174.000 66062882 173.0871
## 158 2023-08-18 172.3000 175.1000 171.9600 174.490 61172150 173.5746
## 159 2023-08-21 175.0700 176.1300 173.7350 175.840 46311879 174.9174
## 160 2023-08-22 177.0600 177.6800 176.2500 177.230 42084245 176.3001
## 161 2023-08-23 178.5200 181.5500 178.3250 181.120 52722752 180.1698
## 162 2023-08-24 180.6740 181.1040 176.0100 176.380 54945798 175.4546
## 163 2023-08-25 177.3800 179.1500 175.8200 178.610 51449594 177.6729
## 164 2023-08-28 180.0900 180.5900 178.5450 180.190 43820697 179.2446
## 165 2023-08-29 179.6950 184.9000 179.5000 184.120 53003948 183.1540
## 166 2023-08-30 184.9400 187.8500 184.7400 187.650 60813888 186.6655
## 167 2023-08-31 187.8400 189.1200 187.4800 187.870 60794467 186.8843
## 168 2023-09-01 189.4850 189.9200 188.2800 189.460 45766503 188.4660
## 169 2023-09-05 188.2800 189.9800 187.6100 189.700 45280027 188.7047
## 170 2023-09-06 188.4000 188.8500 181.4700 182.910 81755816 181.9503
## 171 2023-09-07 175.1800 178.2100 173.5400 177.560 112488803 176.6284
## 172 2023-09-08 178.3500 180.2390 177.7900 178.180 65602066 177.2452
## 173 2023-09-11 180.0700 180.3000 177.3400 179.360 58953052 178.4190
## 174 2023-09-12 179.4900 180.1300 174.8200 176.300 90370192 175.3750
## 175 2023-09-13 176.5100 177.3000 173.9800 174.210 84267928 173.2960
## 176 2023-09-14 174.0000 176.1000 173.5800 175.740 60895757 174.8180
## 177 2023-09-15 176.4800 176.4950 173.8200 175.010 109259461 174.0918
## 178 2023-09-18 176.4800 179.3800 176.1700 177.970 67257573 177.0363
## 179 2023-09-19 177.5200 179.6300 177.1300 179.070 51826941 178.1305
## 180 2023-09-20 179.2600 179.6950 175.4000 175.490 58436181 174.5693
## 181 2023-09-21 174.5500 176.3000 173.8600 173.930 63149116 173.0175
## 182 2023-09-22 174.6700 177.0790 174.0500 174.790 56725385 173.8730
## 183 2023-09-25 174.2000 176.9700 174.1500 176.080 46172740 175.1562
## 184 2023-09-26 174.8200 175.2000 171.6600 171.960 64588945 171.0578
## 185 2023-09-27 172.6200 173.0400 169.0500 170.430 66921808 169.5358
## 186 2023-09-28 169.3400 172.0300 167.6200 170.690 56294419 169.7945
## 187 2023-09-29 172.0200 173.0700 170.3410 171.210 51861083 170.3117
## 188 2023-10-02 171.2200 174.3000 170.9300 173.750 52164535 172.8384
## 189 2023-10-03 172.2550 173.6300 170.8200 172.400 49594613 171.4955
## 190 2023-10-04 171.0900 174.2100 170.9700 173.660 53020286 172.7489
## 191 2023-10-05 173.7900 175.4500 172.6800 174.910 48527918 173.9923
## 192 2023-10-06 173.8000 177.9900 173.1800 177.490 57266675 176.5588
## 193 2023-10-09 176.8100 179.0500 175.8000 178.990 42390772 178.0509
## 194 2023-10-10 178.1000 179.7200 177.9500 178.390 43698019 177.4541
## 195 2023-10-11 178.2000 179.8500 177.6000 179.800 47551098 178.8567
## 196 2023-10-12 180.0700 182.3400 179.0400 180.710 56743119 179.7619
## 197 2023-10-13 181.4200 181.9300 178.1400 178.850 51456082 177.9117
## 198 2023-10-16 176.7500 179.0750 176.5100 178.720 52516984 177.7823
## 199 2023-10-17 176.6450 178.4200 174.8000 177.150 57549350 176.2206
## 200 2023-10-18 175.5800 177.5750 175.1100 175.840 54764375 174.9174
## 201 2023-10-19 176.0400 177.8400 175.1900 175.460 59302863 174.5394
## 202 2023-10-20 175.3100 175.4200 172.6400 172.880 64244028 171.9730
## 203 2023-10-23 170.9100 174.0100 169.9300 173.000 55980109 172.0924
## 204 2023-10-24 173.0500 173.6700 171.4500 173.440 43816644 172.5300
## 205 2023-10-25 171.8800 173.0600 170.6500 171.100 57156962 170.2023
## 206 2023-10-26 170.3700 171.3775 165.6700 166.890 70625258 166.0144
## 207 2023-10-27 166.9100 168.9600 166.8300 168.220 58499129 167.3374
## 208 2023-10-30 169.0200 171.1700 168.8700 170.290 51130955 169.3966
## 209 2023-10-31 169.3500 170.9000 167.9000 170.770 44846017 169.8741
## 210 2023-11-01 171.0000 174.2300 170.1200 173.970 56934906 173.0573
## 211 2023-11-02 175.5200 177.7800 175.4600 177.570 77334752 176.6384
## 212 2023-11-03 174.2400 176.8200 173.3500 176.650 79829246 175.7232
## 213 2023-11-06 176.3800 179.4300 176.2100 179.230 63841310 178.2896
## 214 2023-11-07 179.1800 182.4400 178.9700 181.820 70529966 180.8661
## 215 2023-11-08 182.3500 183.4500 181.5900 182.890 49340282 181.9305
## 216 2023-11-09 182.9600 184.1200 181.8100 182.410 53763540 181.6914
## 217 2023-11-10 183.9700 186.5650 183.5300 186.400 66177922 185.9103
## 218 2023-11-13 185.8200 186.0300 184.2100 184.800 43627519 184.3145
## 219 2023-11-14 187.7000 188.1100 186.3000 187.440 60108378 186.9476
## 220 2023-11-15 187.8450 189.5000 187.7800 188.010 53790499 187.5161
## 221 2023-11-16 189.5700 190.9600 188.6500 189.710 54412915 189.2116
## 222 2023-11-17 190.2500 190.3800 188.5700 189.690 50941404 189.1917
## 223 2023-11-20 189.8900 191.9050 189.8800 191.450 46538614 190.9470
## 224 2023-11-21 191.4100 191.5200 189.7400 190.640 38134485 190.1392
## 225 2023-11-22 191.4900 192.9300 190.8250 191.310 39630011 190.8074
## 226 2023-11-24 190.8700 190.9000 189.2500 189.970 24048344 189.4709
## 227 2023-11-27 189.9200 190.6700 188.9000 189.790 40552609 189.2914
## 228 2023-11-28 189.7800 191.0800 189.4000 190.400 38415419 189.8998
## 229 2023-11-29 190.9000 192.0900 188.9700 189.370 43014224 188.8725
## 230 2023-11-30 189.8400 190.3200 188.1900 189.950 48794366 189.4510
## 231 2023-12-01 190.3300 191.5600 189.2300 191.240 45704823 190.7376
## 232 2023-12-04 189.9800 190.0500 187.4511 189.430 43389519 188.9323
## 233 2023-12-05 190.2100 194.4000 190.1800 193.420 66628398 192.9118
## 234 2023-12-06 194.4500 194.7600 192.1100 192.320 41089737 191.8148
## 235 2023-12-07 193.6300 195.0000 193.5900 194.270 47477655 193.7596
## 236 2023-12-08 194.2000 195.9900 193.6700 195.710 53406358 195.1958
## 237 2023-12-11 193.1100 193.4900 191.4200 193.180 60943699 192.6725
## 238 2023-12-12 193.0800 194.7200 191.7210 194.710 52696900 194.1985
## 239 2023-12-13 195.0900 198.0000 194.8500 197.960 70404183 197.4399
## 240 2023-12-14 198.0200 199.6200 196.1600 198.110 66831572 197.5895
## 241 2023-12-15 197.5300 198.3999 197.0000 197.570 128538401 197.0509
## 242 2023-12-18 196.0900 196.6300 194.3900 195.890 55751861 195.3754
## 243 2023-12-19 196.1600 196.9500 195.8900 196.940 40714051 196.4226
## 244 2023-12-20 196.9000 197.6800 194.8300 194.830 52242815 194.3181
## 245 2023-12-21 196.1000 197.0800 193.5000 194.680 46482549 194.1685
## 246 2023-12-22 195.1800 195.4100 192.9700 193.600 37149570 193.0914
## 247 2023-12-26 193.6100 193.8900 192.8300 193.050 28919310 192.5428
## 248 2023-12-27 192.4900 193.5000 191.0900 193.150 48087681 192.6425
## 249 2023-12-28 194.1400 194.6600 193.1700 193.580 34049898 193.0714
## 250 2023-12-29 193.9000 194.4000 191.7250 192.530 42672148 192.0242
## 251 2024-01-02 187.1500 188.4400 183.8850 185.640 82488674 185.1523
## 252 2024-01-03 184.2200 185.8800 183.4300 184.250 58414460 183.7659
## 253 2024-01-04 182.1500 183.0872 180.8800 181.910 71983570 181.4321
## 254 2024-01-05 181.9900 182.7600 180.1700 181.180 62379661 180.7040
## 255 2024-01-08 182.0850 185.6000 181.5000 185.560 59144470 185.0725
## 256 2024-01-09 183.9200 185.1500 182.7300 185.140 42841809 184.6536
## 257 2024-01-10 184.3500 186.4000 183.9200 186.190 46792908 185.7008
## 258 2024-01-11 186.5400 187.0500 183.6200 185.590 49128408 185.1024
## 259 2024-01-12 186.0600 186.7400 185.1900 185.920 40477782 185.4315
## 260 2024-01-16 182.1600 184.2600 180.9340 183.630 65603041 183.1476
## 261 2024-01-17 181.2700 182.9300 180.3000 182.680 47317433 182.2001
## 262 2024-01-18 186.0900 189.1400 185.8300 188.630 78005754 188.1344
## 263 2024-01-19 189.3300 191.9500 188.8200 191.560 68902985 191.0567
## 264 2024-01-22 192.3000 195.3300 192.2600 193.890 60133852 193.3806
## 265 2024-01-23 195.0200 195.7500 193.8299 195.180 42355590 194.6672
## 266 2024-01-24 195.4200 196.3800 194.3400 194.500 53631316 193.9890
## 267 2024-01-25 195.2200 196.2675 193.1125 194.170 54822126 193.6599
## 268 2024-01-26 194.2700 194.7600 191.9400 192.420 44594011 191.9145
## 269 2024-01-29 192.0100 192.2000 189.5800 191.730 47145622 191.2263
## 270 2024-01-30 190.9400 191.8000 187.4700 188.040 55859370 187.5460
## 271 2024-01-31 187.0400 187.0950 184.3500 184.400 55467803 183.9155
## 272 2024-02-01 183.9850 186.9500 183.8200 186.860 64885408 186.3691
## 273 2024-02-02 179.8600 187.3300 179.2500 185.850 102551680 185.3617
## 274 2024-02-05 188.1500 189.2500 185.8400 187.680 69668820 187.1869
## 275 2024-02-06 186.8600 189.3100 186.7695 189.300 43490759 188.8027
## 276 2024-02-07 190.6400 191.0500 188.6100 189.410 53438955 188.9124
## 277 2024-02-08 189.3850 189.5350 187.3500 188.320 40962046 187.8253
## 278 2024-02-09 188.6500 189.9900 188.0000 188.850 45155216 188.5942
## 279 2024-02-12 188.4150 188.6700 186.7900 187.150 41781934 186.8965
## 280 2024-02-13 185.7700 186.2100 183.5128 185.040 56529529 184.7894
## 281 2024-02-14 185.3200 185.5300 182.4400 184.150 54630517 183.9006
## 282 2024-02-15 183.5500 184.4900 181.3500 183.860 65434496 183.6110
## 283 2024-02-16 183.4200 184.8500 181.6650 182.310 49752465 182.0630
## 284 2024-02-20 181.7900 182.4300 180.0000 181.560 53665553 181.3141
## 285 2024-02-21 181.9400 182.8888 180.6600 182.320 41529674 182.0731
## 286 2024-02-22 183.4800 184.9550 182.4600 184.370 52292208 184.1203
## 287 2024-02-23 185.0100 185.0400 182.2300 182.520 45119677 182.2728
## 288 2024-02-26 182.2400 182.7600 180.6500 181.160 40867421 180.9146
## 289 2024-02-27 181.1000 183.9225 179.5600 182.630 54318851 182.3826
## 290 2024-02-28 182.5100 183.1200 180.1300 181.420 48953939 181.1743
## 291 2024-02-29 181.2700 182.5700 179.5300 180.750 136682597 180.5052
## 292 2024-03-01 179.5500 180.5300 177.3800 179.660 73563082 179.4167
## 293 2024-03-04 176.1500 176.9000 173.7900 175.100 81510101 174.8628
## 294 2024-03-05 170.7600 172.0400 169.6200 170.120 95132355 169.8896
## 295 2024-03-06 171.0600 171.2400 168.6800 169.120 68587707 168.8909
## 296 2024-03-07 169.1500 170.7300 168.4900 169.000 71765061 168.7711
## 297 2024-03-08 169.0000 173.7000 168.9400 170.730 76267041 170.4987
## 298 2024-03-11 172.9400 174.3800 172.0500 172.750 60139473 172.5160
## 299 2024-03-12 173.1500 174.0300 171.0100 173.230 59825372 172.9953
## 300 2024-03-13 172.7700 173.1850 170.7600 171.130 52488692 170.8982
## 301 2024-03-14 172.9100 174.3078 172.0500 173.000 72913507 172.7657
## 302 2024-03-15 171.1700 172.6200 170.2850 172.620 121752699 172.3862
## 303 2024-03-18 175.5700 177.7100 173.5200 173.720 75604184 173.4847
## 304 2024-03-19 174.3400 176.6050 173.0300 176.080 55215244 175.8415
## 305 2024-03-20 175.7200 178.6700 175.0900 178.670 53423102 178.4280
## 306 2024-03-21 177.0500 177.4900 170.8400 171.370 106181270 171.1379
## 307 2024-03-22 171.7600 173.0500 170.0600 172.280 71160138 172.0466
## 308 2024-03-25 170.5650 171.9400 169.4500 170.850 54288328 170.6186
## 309 2024-03-26 170.0000 171.4200 169.5800 169.710 57388449 169.4801
## 310 2024-03-27 170.4100 173.6000 170.1100 173.310 60273265 173.0752
## 311 2024-03-28 171.7500 172.2300 170.5100 171.480 65672690 171.2477
## 312 2024-04-01 171.1900 171.2500 169.4750 170.030 46240500 169.7997
## 313 2024-04-02 169.0800 169.3400 168.2302 168.840 49329481 168.6113
## 314 2024-04-03 168.7900 170.6800 168.5800 169.650 47691715 169.4202
## 315 2024-04-04 170.2900 171.9200 168.8200 168.820 53704386 168.5913
## 316 2024-04-05 169.5900 170.3900 168.9500 169.580 42104826 169.3503
## 317 2024-04-08 169.0300 169.2000 168.2400 168.450 37425513 168.2218
## 318 2024-04-09 168.7000 170.0800 168.3500 169.670 42451209 169.4402
## 319 2024-04-10 168.8000 169.0900 167.1100 167.780 49709336 167.5527
## 320 2024-04-11 168.3400 175.4600 168.1600 175.040 91070275 174.8029
## 321 2024-04-12 174.2600 178.3600 174.2100 176.550 101670886 176.3109
## 322 2024-04-15 175.3600 176.6300 172.5000 172.690 73531773 172.4561
## 323 2024-04-16 171.7500 173.7600 168.2700 169.380 73711235 169.1506
## 324 2024-04-17 169.6100 170.6500 168.0000 168.000 50901210 167.7724
## 325 2024-04-18 168.0300 168.6400 166.5500 167.040 43122903 166.8137
## 326 2024-04-19 166.2100 166.4000 164.0750 165.000 68149377 164.7765
## 327 2024-04-22 165.5150 167.2600 164.7700 165.840 48116443 165.6154
## 328 2024-04-23 165.3500 167.0500 164.9200 166.900 49537761 166.6739
## 329 2024-04-24 166.5400 169.3000 166.2100 169.020 48251835 168.7911
## 330 2024-04-25 169.5250 170.6100 168.1511 169.890 50558329 169.6599
## 331 2024-04-26 169.8800 171.3400 169.1800 169.300 44838354 169.0707
## 332 2024-04-29 173.3700 176.0300 173.1000 173.500 68169419 173.2650
## 333 2024-04-30 173.3300 174.9900 170.0000 170.330 65934776 170.0993
## 334 2024-05-01 169.5800 172.7050 169.1100 169.300 50383147 169.0707
## 335 2024-05-02 172.5100 173.4150 170.8900 173.030 94214915 172.7956
## 336 2024-05-03 186.6450 187.0000 182.6600 183.380 163224109 183.1316
## 337 2024-05-06 182.3540 184.2000 180.4200 181.710 78569667 181.4639
## 338 2024-05-07 183.4500 184.9000 181.3200 182.400 77305771 182.1529
## 339 2024-05-08 182.8500 183.0700 181.4500 182.740 45057087 182.4925
## 340 2024-05-09 182.5600 184.6600 182.1100 184.570 48982972 184.3200
## 341 2024-05-10 184.9000 185.0900 182.1300 183.050 50759496 183.0500
## 342 2024-05-13 185.4350 187.1000 184.6200 186.280 72044809 186.2800
## 343 2024-05-14 187.5100 188.3000 186.2900 187.430 52393619 187.4300
## 344 2024-05-15 187.9100 190.6500 187.3700 189.720 70399988 189.7200
## 345 2024-05-16 190.4700 191.0950 189.6601 189.840 52845230 189.8400
## 346 2024-05-17 189.5100 190.8100 189.1800 189.870 41282925 189.8700
## 347 2024-05-20 189.3500 191.9199 189.0100 191.040 44361275 191.0400
## 348 2024-05-21 191.0900 192.7300 190.9201 192.350 42309401 192.3500
## 349 2024-05-22 192.2650 192.8231 190.2700 190.900 34648547 190.9000
## 350 2024-05-23 190.9800 191.0000 186.6250 186.880 51005924 186.8800
## 351 2024-05-24 188.8200 190.5800 188.0404 189.980 36326975 189.9800
## 352 2024-05-28 191.5100 193.0000 189.1000 189.990 52280051 189.9900
## 353 2024-05-29 189.6100 192.2470 189.5100 190.290 53068016 190.2900
## 354 2024-05-30 190.7600 192.1800 190.6300 191.290 49947941 191.2900
## 355 2024-05-31 191.4400 192.5700 189.9100 192.250 75158277 192.2500
## 356 2024-06-03 192.9000 194.9900 192.5200 194.030 50080539 194.0300
## 357 2024-06-04 194.6350 195.3200 193.0342 194.350 47471445 194.3500
## 358 2024-06-05 195.4000 196.9000 194.8700 195.870 54156785 195.8700
## 359 2024-06-06 195.6850 196.5000 194.1700 194.480 41181753 194.4800
## 360 2024-06-07 194.6500 196.9400 194.1400 196.890 53103912 196.8900
## 361 2024-06-10 196.9000 197.3000 192.1500 193.120 97262077 193.1200
## 362 2024-06-11 193.6500 207.1600 193.6300 207.150 172373296 207.1500
## 363 2024-06-12 207.3700 220.2000 206.9000 213.070 198134293 213.0700
## 364 2024-06-13 214.7400 216.7500 211.6000 214.240 97862729 214.2400
## 365 2024-06-14 213.8500 215.1700 211.3000 212.490 70122748 212.4900
## 366 2024-06-17 213.3700 218.9500 212.7200 216.670 93728300 216.6700
## 367 2024-06-18 217.5900 218.6300 213.0000 214.290 79943254 214.2900
## 368 2024-06-20 213.9300 214.2400 208.8500 209.680 86172451 209.6800
## 369 2024-06-21 210.3900 211.8900 207.1100 207.490 246421353 207.4900
## 370 2024-06-24 207.7200 212.7000 206.5900 208.140 80727006 208.1400
## 371 2024-06-25 209.1500 211.3800 208.6100 209.070 56713868 209.0700
## 372 2024-06-26 211.5000 214.8600 210.6400 213.250 66213186 213.2500
## 373 2024-06-27 214.6900 215.7395 212.3500 214.100 49772707 214.1000
## 374 2024-06-28 215.7700 216.0700 210.3000 210.620 82542718 210.6200
irr_plot(c(-100, 50, 75, 200))
returns <- as.matrix(scale(EuStockMarkets[, c("CAC", "DAX", "FTSE", "SMI")]))
cov_matrix <- cov(returns)
frontier <- efficient_frontier(returns, cov_matrix)
plot_efficient_frontier(frontier)
#' # Ejemplo de uso:
returns <- matrix(c(0.1, 0.2, 0.15, 0.05, 0.1, 0.12), ncol = 2)
covariance_matrix <- matrix(c(0.005, -0.010, -0.010, 0.040), ncol = 2)
plot_portfolio_optimization(returns, covariance_matrix)
weights <- c(0.3, 0.5, 0.2)
asset_names <- c("Stock A", "Stock B", "Stock C")
portfolio_composition(weights, asset_names)
returns <- matrix(c(0.1, 0.2, 0.15, 0.05, 0.1, 0.12), ncol = 2)
covariance_matrix <- matrix(c(0.005, -0.010, -0.010, 0.040), ncol = 2)
optimal_weights <- portfolio_optimization(returns, covariance_matrix)
print(optimal_weights)
## [1] 0.7692308 0.2307692
earnings_per_share <- 3.5
pe_ratio <- 15
pre_ratio(earnings_per_share, pe_ratio)
## [1] 52.5
pv.uneven(r=0.1, cf=c(-1000, -500, 0, 4000, 3500, 2000))
## [1] 5183.103
pv(0.1, 100, 1)
## [1] 90.90909
quick.ratio(cash=3000, ms=2000, rc=1000, cl=2000)
## [1] 3
# 1. Convertir una tasa nominal del 3% compuesta 4 veces al año a una tasa compuesta continuamente.
r.continuous(0.03, 4)
## [1] 0.02988806
# 1. Convertir una tasa compuesta continuamente del 3% a una tasa nominal compuesta 1 vez al año.
r.norminal(0.03, 1)
## [1] 0.03045453
# 1. Calcular la tasa de retorno para una perpetuidad con un pago de $4.5 por periodo y un valor presente de -$75.
r.perpetuity(pmt=4.5, pv=-75)
## [1] 0.06
#' # Example usage:
#' # Ejemplo de uso:
residual_cash_flows <- c(5, 5.5, 6, 6.5, 7)
discount_rate <- 0.1
rcf(residual_cash_flows, discount_rate)
## [1] 22.38483
#' # Example usage:
#' # Ejemplo de uso:
residual_incomes <- c(5, 5.5, 6, 6.5, 7)
discount_rate <- 0.1
rim(residual_incomes, discount_rate)
## [1] 22.38483
# 1. Calcular el ratio de seguridad de Roy con un retorno del portafolio del 9%, un retorno del nivel de umbral del 3%, y una desviación estándar de los retornos del portafolio del 12%.
SFRatio(rp=0.09, rl=0.03, sd=0.12)
## [1] 0.5
# Ejemplos Aplicados:
# 1. Calcular el Ratio de Sharpe con un retorno del portafolio del 3.8%, un retorno libre de riesgo del 1.5%, y una desviación estándar de los retornos del portafolio del 7%.
Sharpe.ratio(rp=0.038, rf=0.015, sd=0.07)
## [1] 0.3285714
# 1. Calcular el gasto anual de depreciación para un activo con un costo de $1200, un valor residual de $200, y una vida útil de 5 años.
slde(cost=1200, rv=200, t=5)
## [1] 200
#' # Ejemplo de uso:
straight_line_depreciation(10000, 2000, 5)
## Year Depreciation Book_Value
## 1 1 1600 8400
## 2 2 1600 6800
## 3 3 1600 5200
## 4 4 1600 3600
## 5 5 1600 2000
sum_of_years_digits_depreciation (10000, 2000, 5)
## Year Depreciation Book_Value
## 1 1 2666.6667 7333.333
## 2 2 2133.3333 5200.000
## 3 3 1600.0000 3600.000
## 4 4 1066.6667 2533.333
## 5 5 533.3333 2000.000
tasa_en_dolares <- 0.06 # Tasa de interés en dólares del 6%
devaluacion_anual <- 0.05 # Tasa de devaluación anual del Lempira del 5%
tasa_indiferencia_lempiras(tasa_en_dolares, devaluacion_anual)
## [1] 0.113
#' # Ejemplo de uso:
units_of_production_depreciation(10000, 2000, 50000, c(10000, 12000, 8000, 15000, 5000))
## Year Depreciation Book_Value
## 1 1 1600 8400
## 2 2 1920 6480
## 3 3 1280 5200
## 4 4 2400 2800
## 5 5 800 2000
data <- data.frame(
Date = as.Date('2020-01-01') + 0:9,
Volume = c(100, 200, 150, 300, 250, 400, 350, 450, 500, 550))
volumeChart(data, main = "Volume Chart Example")
# 1. Calcular el promedio ponderado de acciones comunes con 10000 acciones durante 12 meses y 2000 acciones durante 6 meses.
s <- c(10000, 2000)
m <- c(12, 6)
was(ns = s, nm = m)
## [1] 7333.333