Skip to content
Snippets Groups Projects
Commit 218683e1 authored by victarr's avatar victarr
Browse files

Replace server.R

parent 5aa01d45
No related branches found
No related tags found
No related merge requests found
......@@ -113,6 +113,7 @@ server <- function(input, output, session) {
A <- names(datos)
A <- gsub("=", ".", A)
str_sub(A, -9) <- ""
val_aux <- A
A <- str_c(A, collapse = " ")
a <- str_c("set A :=\n", A, ";", sep = "")
b <- str_c("param R:\n", A, " :=\n", sep = "")
......@@ -227,6 +228,7 @@ server <- function(input, output, session) {
varianza<- ampl$getVariable("varianza")
x <- ampl$getVariable("x")
cartera <- x$getValues()
cartera$index0 <- val_aux
cartera <- cartera[cartera$x.val > 0.001,]
data_return <- data.frame("activ" = cartera$index0, "porc" = cartera$x.val)
......@@ -253,6 +255,8 @@ server <- function(input, output, session) {
datos <- datos[1:filas,]
save(datos_evaluacion, file = "../../RData/data_eval.RData") # Eliminar en la ventana de inicio de la web
rownames(datos) <- gsub("\\.", "-", unlist(gsub("X", "", rownames(datos))))
# Valores que utilizamos (retornos).
returns <- 1 + Return.calculate(datos)
returns <- returns[-1,]
......@@ -261,6 +265,7 @@ server <- function(input, output, session) {
A <- names(datos)
A <- gsub("=", ".", A)
str_sub(A, -9) <- ""
val_aux <- A
A <- str_c(A, collapse = " ")
a <- str_c("set A :=\n", A, ";", sep = "")
b <- str_c("param R:\n", A, " :=\n", sep = "")
......@@ -292,7 +297,6 @@ server <- function(input, output, session) {
p <- input$discount
h <- str_c("param mean {j in A}:= ( sum{i in T}",p,"^(card(T) - i) * R[i,j])/( sum {i in T}",p,"^(card(T) - i));",collapse = "")
#########
# AMPL
#########
......@@ -378,6 +382,7 @@ server <- function(input, output, session) {
varianza<- ampl$getVariable("varianza")
x <- ampl$getVariable("x")
cartera <- x$getValues()
cartera$index0 <- val_aux
cartera <- cartera[cartera$x.val > 0.001,]
data_return <- data.frame("activ" = cartera$index0, "porc" = cartera$x.val)
......@@ -600,6 +605,7 @@ server <- function(input, output, session) {
A <- names(datos)
A <- gsub("=", ".", A)
str_sub(A, -9) <- ""
val_aux <- A
A <- str_c(A, collapse = " ")
a <- str_c("set A :=\n", A, ";", sep = "")
b <- str_c("param R:\n", A, " :=\n", sep = "")
......@@ -737,6 +743,7 @@ server <- function(input, output, session) {
sharpe <- c(ampl$getVariable("sharpe"))
x <- ampl$getVariable("x")
cartera <- x$getValues()
cartera$index0 <- val_aux
cartera <- cartera[cartera$x.val > 0.001,]
data_return <- data.frame("activ" = cartera$index0, "porc" = cartera$x.val)
data_portfolio <- list(modelo = "markowitz2", cartera = data_return, mu = input$mu)
......@@ -801,7 +808,7 @@ server <- function(input, output, session) {
represent <- data.frame("Activo" = data$activ, "Porcentaje" = round(as.numeric(data$porc), 2),
"Inversión" = round(as.numeric(input$dinero * data$porc), 2))
}
if(input$modelos == "Modelo de miminización del riesgo"){
if(input$modelos == "Modelo de minimización del riesgo"){
data <- Data_min()
represent <- data.frame("Activo" = data$activ, "Porcentaje" = round(as.numeric(data$porc), 2),
"Inversión" = round(as.numeric(input$dinero * data$porc), 2))
......@@ -838,13 +845,14 @@ server <- function(input, output, session) {
(max(data$medias) - (input$sharpe - 1)*100)/sqrt(max(data$varianzas)),
(data_sharpe$medias - (input$sharpe - 1)*100)/sqrt(data_sharpe$varianzas)))
}
}
represent$Rendimiento <- round(represent$Rendimiento, 4)
represent$Rendimiento <- as.character(represent$Rendimiento)
represent$Riesgo <- round(represent$Riesgo, 4)
represent$Riesgo <- as.character(represent$Riesgo)
represent$Ratio.Sharpe <- round(represent$Ratio.Sharpe, 4)
represent$Ratio.Sharpe <- as.character(represent$Ratio.Sharpe)
}
represent
}
......@@ -853,6 +861,7 @@ server <- function(input, output, session) {
pdf(NULL)
output$scatter <- renderPlotly({
if(input$modelos == "Modelo biobjetivo de Markowitz"){
if(length(input$empresas) > 1){
data <- Data_markowitz()$dataframe
datos <- Data_empresas()
......@@ -909,6 +918,8 @@ server <- function(input, output, session) {
fig
}
}
})
......@@ -1340,6 +1351,10 @@ server <- function(input, output, session) {
data <- Data_markowitz2()
data$activ <- gsub("\\.X", "=X", data$activ)
data$activ <- gsub("\\.F", "=F", data$activ)
data$activ <- gsub("GSPC", "^GSPC", data$activ)
data$activ <- gsub("NDX", "^NDX", data$activ)
data$activ <- gsub("IBEX", "^IBEX", data$activ)
data$activ <- gsub("STOXX50E", "^STOXX50E", data$activ)
valores <- NULL
for(i in 1:dim(data)[1]){
valores <- c(valores, activos$activo[activos$simbolo == data$activ[i]][1])
......@@ -1373,6 +1388,10 @@ server <- function(input, output, session) {
data <- Data_markowitz2()
data$activ <- gsub("\\.X", "=X", data$activ)
data$activ <- gsub("\\.F", "=F", data$activ)
data$activ <- gsub("GSPC", "^GSPC", data$activ)
data$activ <- gsub("NDX", "^NDX", data$activ)
data$activ <- gsub("IBEX", "^IBEX", data$activ)
data$activ <- gsub("STOXX50E", "^STOXX50E", data$activ)
valores <- NULL
for(i in 1:dim(data)[1]){
valores <- c(valores, activos$activo[activos$simbolo == data$activ[i]][1])
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment