Skip to content

Update code and publish as shinyapp#1

Merged
mjeshtri merged 13 commits intomasterfrom
update-latest
Oct 1, 2025
Merged

Update code and publish as shinyapp#1
mjeshtri merged 13 commits intomasterfrom
update-latest

Conversation

@mjeshtri
Copy link
Owner

@mjeshtri mjeshtri commented Oct 1, 2025

No description provided.

@mjeshtri mjeshtri requested a review from Copilot October 1, 2025 10:54
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates an R bond pricing interactive application by refactoring code organization and adding Shiny app deployment capabilities. The changes modernize the existing manipulate-based interface while maintaining the core bond pricing functionality and adding a web-deployable version.

Key changes:

  • Refactors the main bond plotting logic into a separate modular file (bondPlot.R)
  • Adds dynamic working directory detection for better script portability
  • Creates a new Shiny app interface (app.R) for web deployment
  • Updates documentation with new R version requirements and deployment links

Reviewed Changes

Copilot reviewed 5 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
run_tests.R Adds dynamic working directory detection function
interactive_bonds.R Refactors to use extracted bondPlot function and adds working directory detection
bondPlot.R New file containing extracted and improved bond plotting logic with better text positioning
app.R New Shiny application providing web interface for the bond pricing tool
README.md Updates documentation with new R version, deployment link, and usage instructions

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +2 to +3
# 19 February 2015
library(manipulate)
source("helpers/helpers.R")

bondP=function(c,n,f,r,rN){
# c = bond coupon in %
# n = time to maturity in years
# f = frequency of payments per year
# r = current interest rate
# rN = new interest rate (to see convexity effect)

# Plot bond price as a function of yield
yields <- seq(0.02,0.5,by=0.01)
nominal_price <- bond_price(c,n,f,yields)
op <- par(mar = c(6,4,4.5,4) + 0.5)
plot(yields,nominal_price,type="l",xlim=c(0,0.5),axes = F,xlab = NA,ylab = NA)
title(main="Bond price",line=4)


# calculate the gradient for tanget line
myenv <- new.env()
assign("r", r, envir = myenv)
drv <- numericDeriv(quote(bond_price(c,n,f,r)),c("r"),myenv)

# draw tangent line
abline(a=(c(attr(drv,"gradient")*(0-r))+drv[1]),b=attr(drv,"gradient"),col="green")

points(r,bond_price(c,n,f,r),col="red",pch=19)
lines(c(r,r),c(0,bond_price(c,n,f,r)), col = "red",lty=3,lwd=2)
lines(c(0,r),c(bond_price(c,n,f,r),bond_price(c,n,f,r)), col =
"red",lty=3,lwd=2)

# new interest rate to see the convexity effect (area in yellow)
polygon(x=c(seq(r,rN,length.out=10),seq(rN,r,length.out=10)),
y=c(bond_price(c,n,f,seq(r,rN,length.out=10)),rev(c(attr(drv,"gradient")*(0-r)+drv[1])+c(attr(drv,"gradient"))*seq(r,rN,length.out=10))),
col="yellow1")
points(rN,bond_price(c,n,f,r=rN),col="blue",pch=19)
lines(c(rN,rN),c(bond_price(c,n,f,r=rN),bond_price(c,n,f,r=min(yields))), col =
"grey",lty=3,lwd=2)
lines(c(rN,max(yields)),c(bond_price(c,n,f,r=rN),bond_price(c,n,f,r=rN)), col =
"grey",lty=3,lwd=2)
lines(c(rN,rN),c(0,bond_price(c,n,f,r=rN)), col = "blue",lty=3,lwd=2)
lines(c(0,rN),c(bond_price(c,n,f,r=rN),bond_price(c,n,f,r=rN)), col =
"blue",lty=3,lwd=2)

box()
axis(1,r)
axis(2,bond_price(c,n,f,r))
# Last update: 1 October 2025
Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The date format should use a consistent style. Consider using 'October 1, 2025' or '2025-10-01' for better readability and consistency.

Copilot uses AI. Check for mistakes.
mjeshtri and others added 2 commits October 1, 2025 12:55
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@mjeshtri mjeshtri requested a review from Copilot October 1, 2025 10:57
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 5 out of 7 changed files in this pull request and generated 2 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

mjeshtri and others added 2 commits October 1, 2025 12:59
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@mjeshtri mjeshtri requested a review from Copilot October 1, 2025 11:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 5 out of 7 changed files in this pull request and generated 2 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

mjeshtri and others added 2 commits October 1, 2025 13:04
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@mjeshtri mjeshtri requested a review from Copilot October 1, 2025 11:06
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 5 out of 7 changed files in this pull request and generated 3 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

# Plot bond price as a function of yield
yields <- seq(0.02, 0.5, by = 0.01)
nominal_price <- bond_price(c, n, f, yields)
op <- par(mar = c(6, 4, 4.5, 4) + 0.5)
Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable op stores the previous par settings but is never used to restore them. Either remove this assignment or add par(op) at the end of the function to restore the original graphics parameters.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 5 out of 8 changed files in this pull request and generated 3 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

bondPlot.R Outdated
mtext(side = 2, "Price in % for selected YTM", line = 2)
mtext(side = 3, "Market interest rate", line = 2)
mtext(side = 4, "Market price in %", line = 2)
par(op)
Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The par() reset should be wrapped in a tryCatch or on.exit() to ensure graphical parameters are restored even if an error occurs during plotting. Consider using on.exit(par(op)) right after line 18 where op is defined.

Copilot uses AI. Check for mistakes.
@mjeshtri mjeshtri merged commit 5e34112 into master Oct 1, 2025
1 check passed
@mjeshtri mjeshtri deleted the update-latest branch October 1, 2025 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants