-
Notifications
You must be signed in to change notification settings - Fork 1
/
gradeAlloc.R
211 lines (177 loc) · 6.18 KB
/
gradeAlloc.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
library(shiny)
library(shinyBS)
# Change working directory
if ( file.exists('/home/john') ) {
setwd("/home/john/Dropbox/pls")
path <- '/usr/bin/chromium-browser'
} else {
setwd("C:/Users/john/Dropbox/pls")
path <- file.path('C:','Program Files (x86)','Google','Chrome','Application','chrome.exe')
}
load('config/config.rda')
help <- function() {
return('
<li>You can assign the maximum percentage of new notes to purchase for each loan grade based on
your existing portfolio distribution.
<li>PLS will not purchase
any new notes in a particular loan grade if it exceeds the maximum threshold. For example,
if you assign grade C 60%, PLS will not purchase any new C notes
which would increase your current portfolio of C notes above 60%.
<li>An empty value will allow new notes to be purchased in the respective
loan grade regardless of allocation values in other grades.
<li>Setting 0% maximum value will disable any new notes to be purchased
in the respective loan grade.
<li>PLS will not sell or any way adjust your existing portfolio to match
the assigned allocation.
<p></p>
Example 1:<br>
A=30, B=70, C=0, D=0, E=0, F=0, G=0<br>
Only purchase A notes if A notes do not exceed 30% of portfolio.
Only purchase B notes if B notes do not exceed 70% of portfolio.
Do not purchase any C,D,E,F or G notes.
<p></p>
Example 2:<br>
A=0, B=, C=40, D=40, E=40, F=0, G=0<br>
No limit on purchasing B notes.
Only purchase C notes if C notes do not exceed 40% of portfolio.
Only purchase D notes if D notes do not exceed 40% of portfolio.
Only purchase E notes if E notes do not exceed 40% of portfolio.
Do not purchase any A, F or G notes.
')
}
ui <- shinyUI(fluidPage(
tags$head(
tags$style(type="text/css","
.well {
margin-top: 20px;
}
.inline {
display: inline-block;
}
input {
margin-bottom: 20px;
}
#total {
margin-top: 50px;
}
.fa {
margin-left: 20px;
}
.alert {
margin-left: 20px;
}
")
),
wellPanel(
fluidRow(
column(3,
numericInput("gradeA", "Grade A:", min = 0, max = 100, value = NA, step = 1),
numericInput("gradeE", "Grade E:", min = 0, max = 100, value = NA, step = 1)
),
column(3,
numericInput("gradeB", "Grade B:", min = 0, max = 100, value = NA, step = 1),
numericInput("gradeF", "Grade F:", min = 0, max = 100, value = NA, step = 1)
),
column(3,
numericInput("gradeC", "Grade C:", min = 0, max = 100, value = NA, step = 1),
numericInput("gradeG", "Grade G:", min = 0, max = 100, value = NA, step = 1)
),
column(3,
numericInput("gradeD", "Grade D:", min = 0, max = 100, value = NA, step = 1)
)
)
),
fluidRow(
column(5,
actionButton("save", "Save"),
actionButton("reset", "Clear"),
tags$button( "Close", id="close", type="button", class="btn action-button", onclick="self.close()"),
actionButton("help", "Help")
),
column(7,
bsAlert("alert"),
bsModal("helper", "Grade Allocation", "help", size = "large",
HTML(help())
)
)
)
))
server <- function(input, output, session) {
# Update inputs on load
updateNumericInput(session, "gradeA", value = config$gradeA)
updateNumericInput(session, "gradeB", value = config$gradeB)
updateNumericInput(session, "gradeC", value = config$gradeC)
updateNumericInput(session, "gradeD", value = config$gradeD)
updateNumericInput(session, "gradeE", value = config$gradeE)
updateNumericInput(session, "gradeF", value = config$gradeF)
updateNumericInput(session, "gradeG", value = config$gradeG)
session$onSessionEnded(function() {
stopApp()
})
observeEvent(input$reset, {
updateNumericInput(session, "gradeA", value = NA)
updateNumericInput(session, "gradeB", value = NA)
updateNumericInput(session, "gradeC", value = NA)
updateNumericInput(session, "gradeD", value = NA)
updateNumericInput(session, "gradeE", value = NA)
updateNumericInput(session, "gradeF", value = NA)
updateNumericInput(session, "gradeG", value = NA)
closeAlert(session, alertId = "ALERT")
})
observeEvent(input$save, {
closeAlert(session, alertId = "ALERT")
config['gradeAlloc'] <- FALSE
msg='disabled'
for (name in c('gradeA','gradeB','gradeC','gradeD','gradeE','gradeF','gradeG')) {
if(!is.na(input[[name]])) {
# Check for decimal point
if(grepl("\\.",(input[[name]]))) {
createAlert(session, anchorId = "alert", alertId = "ALERT",
content=paste("Positive integer between 0 and 100 expected for",name),
style = "danger",
append = FALSE)
return()
}
if(input[[name]] < 0) {
createAlert(session, anchorId = "alert", alertId = "ALERT",
content=paste("Positive integer between 0 and 100 expected for",name),
style = "danger",
append = FALSE)
return()
}
if(input[[name]] > 100) {
createAlert(session, anchorId = "alert", alertId = "ALERT",
content=paste("Positive integer between 0 and 100 expected for",name),
style = "danger",
append = FALSE)
return()
}
config['gradeAlloc'] <- TRUE
msg="Enabled"
}
}
config['gradeA'] <- input$gradeA
config['gradeB'] <- input$gradeB
config['gradeC'] <- input$gradeC
config['gradeD'] <- input$gradeD
config['gradeE'] <- input$gradeE
config['gradeF'] <- input$gradeF
config['gradeG'] <- input$gradeG
save(config,file='config/config.rda')
createAlert(session, anchorId = "alert", alertId = "ALERT",
content=paste("Configuration Saved - Allocation ",msg, "",sep=''),
style = "success",
append = FALSE)
})
}
# Browser launch settings
launch.browser = function(appUrl, browser.path=path) {
system(sprintf('"%s" --disable-gpu --app="data:text/html,<html>
<head>
<title>Grade Allocation</title>
</head>
<body>
<script>window.resizeTo(830,350);window.location=\'%s\';</script>
</body></html>" &', browser.path, appUrl))
}
shinyApp(ui = ui, server = server, options = list(launch.browser=launch.browser))