mirror of
https://github.com/ArthurDanjou/ArtStudies.git
synced 2026-01-25 13:52:39 +01:00
Enhance tp2 Rmd (histogram, interactive maps, choropleth fixes); add TP3 Shiny apps and project files; update .gitignore; add shap (+cloudpickle, numba, llvmlite, tqdm, slicer) to pyproject.toml and uv.lock; remove generated tp2 HTML/assets
This commit is contained in:
122
M2/Data Visualisation/tp3/sh-black_scholes/app-enonce.R
Normal file
122
M2/Data Visualisation/tp3/sh-black_scholes/app-enonce.R
Normal file
@@ -0,0 +1,122 @@
|
||||
# Original source : https://srdas.github.io/MLBook/Shiny.html#the-application-program
|
||||
|
||||
library(shiny)
|
||||
library(plotly)
|
||||
library(ggplot2)
|
||||
library(ggthemes)
|
||||
|
||||
|
||||
|
||||
##### CONSIGNES #####
|
||||
# 1. Completer le code du serveur (???) permet de compléter l'objet `output` (argument plotCall
|
||||
# et plotPut). Il s'agit de deux figures qui permet de presenter la valeur
|
||||
# d'un call et d'un put en fonction du Strike K.
|
||||
|
||||
# 2. Compléter le code de l'ui (???) afin de creer des box affichant la valeur de l'action
|
||||
# 'Stock Price' et du strike 'Strike Price'. Prendre par dééfaut la valeur 100.
|
||||
|
||||
# 3 . Sur la base du slider pour la Maturité, ajouter un slider pour la volatilité,
|
||||
# le taux sans risque et le taux de dividende.
|
||||
|
||||
# 4. Lancer l'application.
|
||||
|
||||
##### SERVER #####
|
||||
|
||||
# Define server logic for random distribution application
|
||||
server <- function(input, output) {
|
||||
|
||||
#Generate Black-Scholes values
|
||||
BS = function(S,K,T,v,rf,dv) {
|
||||
d1 = (log(S/K) + (rf-dv+0.5*v^2)*T)/(v*sqrt(T))
|
||||
d2 = d1 - v*sqrt(T)
|
||||
bscall = S*exp(-dv*T)*pnorm(d1) - K*exp(-rf*T)*pnorm(d2)
|
||||
bsput = -S*exp(-dv*T)*pnorm(-d1) + K*exp(-rf*T)*pnorm(-d2)
|
||||
res = c(bscall,bsput)
|
||||
}
|
||||
|
||||
#Call option price
|
||||
output$BScall <- renderText({
|
||||
#Get inputs
|
||||
S = input$stockprice
|
||||
K = input$strike
|
||||
T = input$maturity
|
||||
v = input$volatility
|
||||
rf = input$riskfreerate
|
||||
dv = input$divrate
|
||||
res = round(BS(S,K,T,v,rf,dv)[1],4)
|
||||
})
|
||||
|
||||
#Put option price
|
||||
output$BSput <- renderText({
|
||||
#Get inputs
|
||||
S = input$stockprice
|
||||
K = input$strike
|
||||
T = input$maturity
|
||||
v = input$volatility
|
||||
rf = input$riskfreerate
|
||||
dv = input$divrate
|
||||
res = round(BS(S,K,T,v,rf,dv)[2],4)
|
||||
})
|
||||
|
||||
#Call plot
|
||||
output$plotCall <- renderPlotly({
|
||||
S = input$stockprice
|
||||
K = input$strike
|
||||
T = input$maturity
|
||||
v = input$volatility
|
||||
rf = input$riskfreerate
|
||||
dv = input$divrate
|
||||
vcall = NULL; vput = NULL
|
||||
strikes = seq(K-30,K+30)
|
||||
for (k in strikes) {
|
||||
vcall = ???
|
||||
vput = ???
|
||||
}
|
||||
df = data.frame(strikes,vcall,vput)
|
||||
p <- ggplot(???) + ???
|
||||
plotly::ggplotly(p)
|
||||
})
|
||||
|
||||
#Put plot
|
||||
output$plotPut <- ???
|
||||
|
||||
}
|
||||
|
||||
##### UI #####
|
||||
|
||||
ui <- shinyUI(fluidPage(
|
||||
|
||||
titlePanel("Black-Scholes-Merton (1973)"),
|
||||
|
||||
sidebarLayout(
|
||||
sidebarPanel(
|
||||
numericInput(???,'Stock Price', ???),
|
||||
numericInput(???,'Strike Price', ???),
|
||||
sliderInput('maturity','Maturity (years)',min=0.1,max=10,value=1,step=0.01),
|
||||
sliderInput(???),
|
||||
sliderInput(???),
|
||||
sliderInput(???),
|
||||
hr(),
|
||||
p('Please refer to following for more details:',
|
||||
a("Black-Scholes (1973)",
|
||||
href = "https://en.wikipedia.org/wiki/Black%E2%80%93Scholes_model")),
|
||||
hr()
|
||||
),
|
||||
|
||||
mainPanel(
|
||||
h2('European call price'),
|
||||
textOutput("BScall"),
|
||||
hr(),
|
||||
h2('European put price'),
|
||||
textOutput("BSput"),
|
||||
hr(),
|
||||
tabsetPanel(
|
||||
tabPanel("Calls", plotlyOutput("plotCall",width="100%")),
|
||||
tabPanel("Puts", plotlyOutput("plotPut",width="100%"))
|
||||
)
|
||||
)
|
||||
)
|
||||
))
|
||||
|
||||
##### Run #####
|
||||
???
|
||||
51
M2/Data Visualisation/tp3/sh-first_app/app.R
Normal file
51
M2/Data Visualisation/tp3/sh-first_app/app.R
Normal file
@@ -0,0 +1,51 @@
|
||||
#
|
||||
# This is a Shiny web application. You can run the application by clicking
|
||||
# the 'Run App' button above.
|
||||
#
|
||||
# Find out more about building applications with Shiny here:
|
||||
#
|
||||
# https://shiny.posit.co/
|
||||
#
|
||||
|
||||
library(shiny)
|
||||
|
||||
# Define UI for application that draws a histogram
|
||||
ui <- fluidPage(
|
||||
|
||||
# Application title
|
||||
titlePanel("Old Faithful Geyser Data"),
|
||||
|
||||
# Sidebar with a slider input for number of bins
|
||||
sidebarLayout(
|
||||
sidebarPanel(
|
||||
sliderInput("bins",
|
||||
"Number of bins:",
|
||||
min = 1,
|
||||
max = 50,
|
||||
value = 30)
|
||||
),
|
||||
|
||||
# Show a plot of the generated distribution
|
||||
mainPanel(
|
||||
plotOutput("distPlot")
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
# Define server logic required to draw a histogram
|
||||
server <- function(input, output) {
|
||||
|
||||
output$distPlot <- renderPlot({
|
||||
# generate bins based on input$bins from ui.R
|
||||
x <- faithful[, 2]
|
||||
bins <- seq(min(x), max(x), length.out = input$bins + 1)
|
||||
|
||||
# draw the histogram with the specified number of bins
|
||||
hist(x, breaks = bins, col = 'darkgray', border = 'white',
|
||||
xlab = 'Waiting time to next eruption (in mins)',
|
||||
main = 'Histogram of waiting times')
|
||||
})
|
||||
}
|
||||
|
||||
# Run the application
|
||||
shinyApp(ui = ui, server = server)
|
||||
198
M2/Data Visualisation/tp3/style.css
Normal file
198
M2/Data Visualisation/tp3/style.css
Normal file
@@ -0,0 +1,198 @@
|
||||
.infobox {
|
||||
padding: 1em 1em 1em 4em;
|
||||
margin-bottom: 10px;
|
||||
border: 2px solid orange;
|
||||
border-radius: 10px;
|
||||
background: #f5f5f5 5px center/3em no-repeat;
|
||||
}
|
||||
|
||||
/* Custom box styles for math environments */
|
||||
|
||||
/* Lemma Box */
|
||||
.lemma-box {
|
||||
border: 2px solid #3c8dbc;
|
||||
background-color: #e6f7ff;
|
||||
padding: 10px;
|
||||
border-radius: 8px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
/* Theorem Box */
|
||||
.theorem-box {
|
||||
border: 2px solid #2ca02c;
|
||||
background-color: #eaffea;
|
||||
padding: 10px;
|
||||
border-radius: 8px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
/* Corollary Box */
|
||||
.corollary-box {
|
||||
border: 2px solid #2ca02c;
|
||||
background-color: #eaffea;
|
||||
padding: 10px;
|
||||
border-radius: 8px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
/* Proposition Box */
|
||||
.proposition-box {
|
||||
border: 2px solid #ff7f0e;
|
||||
background-color: #fff3e6;
|
||||
padding: 10px;
|
||||
border-radius: 8px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
/* Conjecture Box */
|
||||
.conjecture-box {
|
||||
border: 2px solid #9467bd;
|
||||
background-color: #f5e6ff;
|
||||
padding: 10px;
|
||||
border-radius: 8px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
/* Definition Box */
|
||||
.definition-box {
|
||||
border: 2px solid #d62728;
|
||||
background-color: #ffe6e6;
|
||||
padding: 10px;
|
||||
border-radius: 8px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
/* Example Box */
|
||||
.example-box {
|
||||
border: 2px solid #17becf;
|
||||
/* background-color: #e6f7ff;*/
|
||||
padding: 10px;
|
||||
border-radius: 8px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
/* Exercise Box */
|
||||
.exercise-box {
|
||||
border: 2px solid #1f77b4;
|
||||
background-color: #e6f7ff;
|
||||
padding: 10px;
|
||||
border-radius: 8px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
/* Hypothesis Box */
|
||||
.hypothesis-box {
|
||||
border: 2px solid #e377c2;
|
||||
background-color: #ffe6f5;
|
||||
padding: 10px;
|
||||
border-radius: 8px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
/* Remark Box */
|
||||
.remark-box {
|
||||
border: 2px solid #7f7f7f;
|
||||
background-color: #f2f2f2;
|
||||
padding: 10px;
|
||||
border-radius: 8px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
/* Proof Box */
|
||||
.proof-box {
|
||||
border: 2px solid #bcbd22;
|
||||
background-color: #fafad2;
|
||||
padding: 10px;
|
||||
border-radius: 8px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
/* Hint Box */
|
||||
.hint-box {
|
||||
border: 2px solid #7f7f7f;
|
||||
background-color: #f2f2f2;
|
||||
padding: 10px;
|
||||
border-radius: 8px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
|
||||
/* Numérotation automatique */
|
||||
|
||||
|
||||
.lemma-box::before {
|
||||
counter-increment: lemma-counter;
|
||||
content: "Lemme " counter(lemma-counter) ". ";
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.theorem-box::before {
|
||||
counter-increment: theorem-counter;
|
||||
content: "Théorème " counter(theorem-counter) ". ";
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.corollary-box::before {
|
||||
counter-increment: corollary-counter;
|
||||
content: "Corollaire " counter(corollary-counter) ". ";
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.proposition-box::before {
|
||||
counter-increment: proposition-counter;
|
||||
content: "Proposition " counter(proposition-counter) ". ";
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.conjecture-box::before {
|
||||
counter-increment: conjecture-counter;
|
||||
content: "Conjecture " counter(conjecture-counter) ". ";
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.definition-box::before {
|
||||
counter-increment: definition-counter;
|
||||
content: "Définition " counter(definition-counter) ". ";
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.example-box::before {
|
||||
counter-increment: example-counter;
|
||||
content: "Exemple " counter(example-counter) ". ";
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
|
||||
.exercise-box::before {
|
||||
counter-increment: exercise-counter;
|
||||
content: "Question " counter(exercise-counter) ". ";
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.hypothesis-box::before {
|
||||
counter-increment: hypothesis-counter;
|
||||
content: "Hypothèse " counter(hypothesis-counter) ". ";
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.remark-box::before {
|
||||
counter-increment: remark-counter;
|
||||
content: "Remarque " counter(remark-counter) ". ";
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.proof-box::before {
|
||||
counter-increment: proof-counter;
|
||||
content: "Preuve " counter(proof-counter) ". ";
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.hint-box::before {
|
||||
content: "Indice." ;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* Initialisation des compteurs */
|
||||
body {
|
||||
counter-reset: lemma-counter corollary-counter proposition-counter conjecture-counter definition-counter example-counter exercise-counter hypothesis-counter remark-counter proof-counter;
|
||||
}
|
||||
30
M2/Data Visualisation/tp3/tp3.Rmd
Normal file
30
M2/Data Visualisation/tp3/tp3.Rmd
Normal file
@@ -0,0 +1,30 @@
|
||||
---
|
||||
title: "Exemple R Markdown"
|
||||
author: "Quentin Guibert"
|
||||
date: "`r Sys.Date()`"
|
||||
output: html_document
|
||||
---
|
||||
|
||||
```{r setup, include=FALSE}
|
||||
knitr::opts_chunk$set(echo = TRUE)
|
||||
```
|
||||
|
||||
## R Markdown
|
||||
|
||||
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
|
||||
|
||||
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
|
||||
|
||||
```{r cars}
|
||||
summary(cars)
|
||||
```
|
||||
|
||||
## Including Plots
|
||||
|
||||
You can also embed plots, for example:
|
||||
|
||||
```{r pressure, echo=FALSE}
|
||||
plot(pressure)
|
||||
```
|
||||
|
||||
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
|
||||
17
M2/Data Visualisation/tp3/tp3.Rproj
Normal file
17
M2/Data Visualisation/tp3/tp3.Rproj
Normal file
@@ -0,0 +1,17 @@
|
||||
Version: 1.0
|
||||
|
||||
RestoreWorkspace: Default
|
||||
SaveWorkspace: Default
|
||||
AlwaysSaveHistory: Default
|
||||
|
||||
EnableCodeIndexing: Yes
|
||||
UseSpacesForTab: Yes
|
||||
NumSpacesForTab: 2
|
||||
Encoding: UTF-8
|
||||
|
||||
RnwWeave: Sweave
|
||||
LaTeX: pdfLaTeX
|
||||
|
||||
BuildType: Website
|
||||
|
||||
SpellingDictionary: fr_FR
|
||||
Reference in New Issue
Block a user