Principles of Financial Computing Course

Principles of Financial Computing

Time: 9:10 ~ 12:10 Friday (Spring Semester)
Location: Room 111 of the CSIE Building


On Wall Street, being right on the fundamentals and
wrong on the timing is the same as just being wrong.
---Jonathan Cohen

Where is the risk management at J.P. Morgan Chase?
--- Bloomberg News, January 16, 2002

10. Of course, I make a lot investing.
I only teach so I can help young people.
--- Top Ten Lies Finance Professors Tell Their Students



To Students,

You will learn a perhaps different perspective on finance, especially as it pertains to pricing and software engineering. Our emphasis on computation should add a new dimension and toolbox to your existing knowledge and financial sense. (But see Enrollments below.)
It is your responsibility to learn to write in high-level programming languages. We cannot impart that skill in the class. If the mathematics proves hard going, you are expected to fill in the gap by self-reading. The technicalities are not beyond a motivated graduate student's reach.


The major topics covered in the course, time permitting, are listed below for your reference.


Notes [ 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025 ]

  1. 2025.02.21
  2. 2025.02.28 holiday
  3. 2025.03.07
  4. 2025.03.14
  5. 2025.03.21 & 1st assignment due
  6. 2025.03.28
  7. 2025.04.04 holiday
  8. 2025.04.11
  9. 2025.04.18 & 2nd assignment due
  10. 2025.04.25
  11. 2025.05.02
  12. 2025.05.09 & 3rd assignment due
  13. 2025.05.16
  14. 2025.05.23
  15. 2025.05.30
  16. 2025.06.06 & 4th assignment due

Programming Exercises

Homework should be turned in on time. No late homework will be accepted without legitimate reasons. There will be four to six programming assignments.
Treat each homework as an examination.
  1. Write a program to analyze bond investment financing through a loan. Consider an n-year, V1-dollar loan charging an annual interest rate of r1 (the repayment schedule is by amortization), and an n-year level-coupon bond with a par value of V2 and paying an annual interest rate of r2, where r1 < r2. TA holds C dollars in cash, and intends to take out the loan to purchase the bond. The total sum of cash and loan proceeds will be fully invested in the bond (V1 + C = V2). In addition, TA aims to ensure that the payments for the loan (principal and interest) do not exceed the bond (interest) throughout the investment period. Note that V1 and V2 are integers, and payments and interests should be rounded to six decimal places. Inputs:
    • C: cash in TA's hand;
    • n: time to maturity of the loan and bond in years, an integer;
    • m: the number of payments per annum, an integer;
    • r1: annual interest rate of the loan, compounded m times per year;
    • r2: annual interest rate of the bond, compounded m times per year.
    Outputs:
    • The maximum loan amount (V1, an integer) that TA can apply for balanced payments (the following outputs are with V1 of the maximum loan amount);
    • Total interest paid on the loan (rounded to six decimal places);
    • Total interest received from the bond (rounded to six decimal places);
    • Annualized internal rate of return of the investment (rounded to six decimal places).
    For example, if C = 10000, n = 2, m = 12, r1 = 0.018, r2 = 0.045, the outputs are 968, 18.254282, 987.120000, and 0.046329. Input Format (for Python codes, replace the student ID with uppercase): "python3 F08922011_HW_1.py 10000 2 12 0.018 0.045". Output Format: "968, 18.254282, 987.120000, 0.046329". Please send your source (and executable) code and a brief explanation txt file (if the code is not written in Python, describe how to run it) using NTU COOL before 08:00 AM (GMT+8) 2025 March 21. No late submissions will be accepted. Compress all files into a single zip file, and name it ID_HW_i.zip, where ID is your student ID in uppercase and i is the number of the homework (example: F08922011_HW_1.zip). If the code is not written in Python, you may be asked to demonstrate your code to TA and you still have to submit the files before the deadline.
  2. Write a binomial tree program to price Bermudan options, where early exercise is only allowed on specific dates. Inputs:
    • S: stock price;
    • X: strike price;
    • r: continuously compounded annual interest rate;
    • s: annual volatility;
    • T: time to maturity in days, which is an integer and also an exercise date;
    • m: number of periods per day for the tree, an integer;
    • E: early exercise dates from now, a list of integers.
    Output: The prices of the Bermudan put option and the Bermudan call option. For example, if S = 100, X = 110, r = 0.03, s = 0.3, T = 60, m = 5, and E = 10, 20, 30, 40, 50, the example outputs are 11.248139 and 1.687963. Input Format (for Python codes, replace your student ID with uppercase): "python3 F08922011_HW_2.py 100 110 0.03 0.3 60 5 10 20 30 40 50". Output Format: "11.248139, 1.687963". Please send your source (and executable) code and a brief explanation txt file (if the code is not written in Python, describe how to run it) using NTU COOL before 08:00 AM (GMT+8) 2025 April 18. No late submissions will be accepted. Compress all files into a single zip file, and name it ID_HW_i.zip, where ID is your student ID in uppercase and i is the number of the homework (example: F08922011_HW_2.zip). If the code is not written in Python, you may be asked to demonstrate your code to TA 許家豪 and you still have to submit the files before the deadline.
  3. Write a binomial tree program to price up-and-out and up-and-in barrier options. Note that the binomial tree may not align exactly with the barrier. Adjust the barrier by rounding it up to the nearest tree level. Inputs:
    • S: stock price;
    • X: strike price;
    • r: continuously compounded annual interest rate;
    • s: annual volatility;
    • T: time to maturity in days, which is an integer, and there are 365 days in a year;
    • H: up-and-out barrier, where H > S and H > X;
    • n: number of time steps in T, which is an integer.
    Output:
    • The price of the up-and-out barrier call option.
    • The price of the up-and-out barrier put option.
    • The price of the up-and-in barrier call option.
    • The price of the up-and-in barrier put option.
    For example, if S = 100, X = 110, r = 0.03, s = 0.3, T = 60, H = 120, and n = 100, the outputs are 0.311069, 11.083348, 1.370665, and 0.057256. Input Format (for Python codes, replace your student ID with uppercase): "python3 F08922011_HW_3.py 100 110 0.03 0.3 60 120 100". Output Format: "0.311069, 11.083348, 1.370665, 0.057256". Please send your source (and executable) code and a brief explanation txt file (if the code is not written in Python, describe how to run it) using NTU COOL before 08:00 AM 2025 May 9. No late submissions will be accepted. Compress all files into a single zip file, and name it ID_HW_i.zip, where ID is your student ID in uppercase and i is the number of the homework (example: F08922011_HW_3.zip). If the code is not written in Python, you may be asked to demonstrate your code to TA 許家豪 and you still have to submit the files before the deadline.
  4. TBA
  5. Write a program for loan amortization swapping. Consider an n1-year, V-dollar loan at an r1 interest rate. At the end of year n2 (n2 < n1), however, there is an opportunity to swap the loan (i.e., the remaining principal) into a new loan with an r2 interest rate for the remaining n1-n2 years, of course under a new amortization. An F-dollar fee is charged at the end of year n2 if the loan is swapped. Both loans have the same number of payments per annum, m. Inputs:
    • V: original loan amount in dollars;
    • m: number of payments per annum, an integer;
    • n1: duration of the original loan in years, an integer;
    • r1: annual interest rate of the original loan, compounded m times per annum;
    • n2: the year that loan swapping is possible;
    • r2: annual interest rate of the new loan, also compounded m times per annum;
    • F: swapping fee.
    Outputs:
    • total principal paid in the first n2 years;
    • total interest paid in the first n2 years;
    • total interest paid from the end of year n2 (excluded) to the end of year n1 if the loan is not swapped (so the r1 interest rate is maintained);
    • total interest paid from the end of year n2 (excluded) to the end of year n1 if the loan is swapped to the new r2 interest rate;
    • the IRR for the whole n1 years (the fee F considered) if the loan is swapped;
    • does swapping the loan lower the IRR? Answer 1 for yes, 0 for no difference, and -1 for no.
    For example, if V = 1000000, m = 12, n1 = 2, r1 = 0.060, n2 = 1, r2 = 0.025, F = 888, the outputs are 485041.840313, 46805.482720, 16889.163346, 6999.998244, 0.051895, 1. Input format (for Python codes): "python3 F08922011_HW_1.py 1000000 12 2 0.060 1 0.025 888". Output format: "485041.840313, 46805.482720, 16889.163346, 6999.998244, 0.051895, 1". Please send your source (and executable) code and a brief explanation txt file (if the code is not written in Python, describe how to run it) using NTU COOL before 08:00 AM of March 22, 2024. No late submissions will be accepted. Compress all files into a single zip file, and name it ID_HW_i.zip, where ID is your student ID in uppercase and i is the number of the homework (example: F08922011_HW_1.zip). If the code is not written in Python, you may be asked to demonstrate your code to TA 許家豪 and you still have to submit the files before the deadline.
  6. Write a binomial tree program to price Bermudan put options, where early exercise is only allowed on specific dates. Inputs:
    • S: stock price;
    • X: strike price;
    • r: continuously compounded annual interest rate;
    • s: annual volatility;
    • T: time to maturity in days, which is an integer and also an exercise date;
    • m: number of periods per day for the tree, an integer;
    • E: early exercise dates from now, a list of integers.
    Output: The price of the Bermudan put option. For example, if S = 100, X = 110, r = 0.03, s = 0.3, T = 60, m = 5, and E = [10, 20, 30, 40, 50], the output is 11.248139. Input format (for Python codes, replace your student ID with uppercase): "python3 F08922011_HW_2.py 100 110 0.03 0.3 60 5 10 20 30 40 50". Output format: "11.248657". Please send your source (and executable) code and a brief explanation txt file (if the code is not written in Python, describe how to run it) using NTU COOL before 08:00 AM (GMT+8) 2024 April 19. No late submissions will be accepted. Compress all files into a single zip file, and name it ID_HW_i.zip, where ID is your student ID in uppercase and i is the number of the homework (example: F08922011_HW_2.zip). If the code is not written in Python, you may be asked to demonstrate your code to TA 許家豪 and you still have to submit the files before the deadline.
  7. Write a trinomial tree program to price a up-and-out barrier put. The trinomial tree must match the barrier. Inputs:
    • S: stock price;
    • X: strike price;
    • r: continuously compounded annual interest rate;
    • s: annual volatility;
    • T: time to maturity in days, which is an integer, and there are 365 days in a year;
    • H: up-and-out barrier;
    • n: number of time steps in T, which is an integer.
    Output: The price of the up-and-out barrier put option. For example, if S = 100, X = 110, r = 0.03, s = 0.3, T = 60, H = 120, and n = 100, the output is 11.089643. Input Format (for Python codes, replace your student ID with uppercase): "python3 F08922011_HW_3.py 100 110 0.03 0.3 60 120 100". Output Format: "11.089643". Please send your source (and executable) code and a brief explanation txt file (if the code is not written in Python, describe how to run it) using NTU COOL before 08:00 AM 2024 May 10. No late submissions will be accepted. Compress all files into a single zip file, and name it ID_HW_i.zip, where ID is your student ID in uppercase and i is the number of the homework (example: F08922011_HW_3.zip). If the code is not written in Python, you may be asked to demonstrate your code to TA 許家豪 and you still have to submit the files before the deadline.
  8. Write a least-squares Monte Carlo program to price an American-style Asian put, and use 1, x, x2 as the basis functions. Note that the put's payoff, when exercised early, uses the running average. Output its price and delta. Inputs:
    • S: stock price, which is a float;
    • X: strike price, which is a float;
    • T: time to maturity in days, which is an integer, and there are 365 days in a year;
    • r: continuously compounded annual interest rate, which is a float;
    • s: annual volatility, which is a float;
    • n: number of time steps in T, which is an integer;
    • N: number of simulation paths, which is an integer.
    Output: (1) Price of the put; (2) Delta of the put (caluclated by S × 1.01 and S × 0.99). For example, if S = 100, X = 100, T = 365, r = 0.05, s = 0.3, n = 100, and N = 10000, the example outputs are 5.483093 and -0.407075. Note that Input Format (for Python codes, replace your student ID with uppercase): "python3 F08922011_HW_4.py 100 100 365 0.05 0.3 100 10000". Output Format: "5.483093, -0.407075". Please send your source (and executable) code and a brief explanation txt file (if the code is not written in Python, describe how to run it) using NTU COOL before 08:00 AM 2024 June 7. No late submissions will be accepted. Compress all files into a single zip file, and name it ID_HW_i.zip, where ID is your student ID in uppercase and i is the number of the homework (example: F08922011_HW_4.zip). If the code is not written in Python, you may be asked to demonstrate your code to TA 閮勗振鞊?and you still have to submit the files before the deadline.

Enrollments