2
$\begingroup$

I need help as I am new to Mathematica. I have a table with some nominal bond values:

 {
 {, Nominal, Maturity, Coupon },
 {Bond 1, 200, 1, 0.05},
 {Bond 2, 110, 15, 0.1},
 {Bond 3, 195, 7, 0.05},
 {Bond 4, 100, 25, 0.025},
 {Bond 5, 100, 10, 0.03}
}

and I want to calculate the Value of the bond with the following function but I could not map it right so that the values fit. Could someone help me ?

Here is the function for the valuation of the bond. If I paste each value by hand it works fine but I have to match it with the table with the Map function.

mwbond2[Nominal_, Maturity_, Coupon_, int0_] := Module[
  {n = Nominal, m = Maturity, c = Coupon, int = int0},
  MW = Sum[n*c /(1+int)^i, {i, 1, m, 1}] + n/(1 + int)^m; Print[MW]]

Thanks

$\endgroup$
2
  • $\begingroup$ Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. $\endgroup$ – bbgodfrey May 30 at 21:15
  • 1
    $\begingroup$ Dataset might be a good fit for storing and processing this data. $\endgroup$ – Szabolcs Jun 30 at 10:24
2
$\begingroup$

Using your data

list = {{, Nominal, Maturity, Coupon}, {Bond 1, 200, 1., 
    0.05}, {Bond 2, 110., 15., 0.1}, {Bond 3, 195., 7., 
    0.05}, {Bond 4, 100., 25., 0.025}, {Bond 5, 100., 10., 0.03}};

and a slightly modified version of your function

mwbond2[Nominal_, Maturity_, Coupon_, int0_] := 
 Module[{n = Nominal, m = Maturity, c = Coupon, int = int0}, 
  Sum[n*c/(1 + int)^i, {i, 1, m, 1}] + n/(1 + int)^m]

Note that Module evaluates to the Sum given at the end. Assigning the value to a variable is unnecessary here and I get it to return a value rather than printing it.

We don't use the row or column labels, so drop these

list1 = Drop[#, 1] & /@ Drop[list, 1]
(* {{200, 1., 0.05}, {110., 15., 0.1}, {195., 7., 0.05}, {100., 
  25., 0.025}, {100., 10., 0.03}} *)

We do want an interest rate (which I assume you omitted inadvertently). I use rates of 1%, 2%, ..., 5% for the 5 cases. I add the rates into the table

list2 = MapThread[Append, {list1, {1, 2, 3, 4, 5}/100}]
(* {{200, 1., 0.05, 1/100}, {110., 15., 0.1, 1/50}, {195., 7., 
  0.05, 3/100}, {100., 25., 0.025, 1/25}, {100., 10., 0.03, 1/20}} *)

I now apply the function to each row of the table

mwbond2 @@@ list2
(* {207.921, 223.074, 219.298, 76.5669, 84.5565} *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.