Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using C++ to solve these issues. 1. Download historical daily prices from Bloomberg or Yahoo! Finance for two or more stocks (e.g. AAPL and MSFT)and

Using C++ to solve these issues.

1. Download historical daily prices from Bloomberg orYahoo! Finance for two or more stocks (e.g. AAPL and MSFT)and graph them together. As ever, be careful with axes, labels, useof color, etc.

2. Using the EuropeanOption class implementation fromplot the payoff of both call and put options. To accomplish this,remember to keep all parameters equal, except the spot price of theunderlying asset. You may use real or fake values for this problem.Analyze what happens to the payoff curve as the options approachmaturity.

3. Design and implement an AmericanOption class. It should holdinformation such as option type (call or put), spot price (of theunderlying asset), strike price, interest rate, volatility (of theunderlying asset) and time to maturity. Don’t accept illegalvalues. Implement a get_price() function which gives the price ofthe option using a binomial tree defined as a matrix ( vector ).

4.Design and implement an Option class as the base class forboth EuropeanOption and AmericanOption classes. It should containall the member variables that are common between both option types,as well as a virtual function get_price() . Moreover, it shouldcontain four (non - virtual) functions to compute the Greeks (get_delta() for spot price, get_rho() 1 for interest rate,get_sigma() f or volatility, and get_theta() for time to maturity)of a given option. These functions should: Compute theprice of the option by calling the virtual function get_price() ; Apply a small bump to the required pricing factor (thesize of the bump should be a parameter of the function); Compute the "bumped price" of the option by calling the virtualfunction get_price() ; Change the modified pricingfactor back to its original value; Return the numericapproximation of the given Greek. After all the a bove is done,implement an external function (to the class) which takes aOption& as parameter and compute all four Greeks in a row.Compare the results you obtain for both American and EuropeanOptions (call and put options).

5. Modify the Link class from section 17.10.1 of the book tohold a value of a struct God . struct God should have members oftype string : name, mythology, vehicle, and weapon. For exampleGod{"Zeus", "Greek", "", "lightning"} and God{"Odin", "Norse","Eight - l egged flying horse called Spleipner", "Spear calledGungnir"} . Write a print_all() function that lists gods with theirattributes one per line. Add a member function add_ordered() thatplace its new element in its correct lexicographical position.Using th e Link s with the values of type God , make a list of godsfrom three mythologies; then move the elements (gods) from thatlist to three lexicographically ordered lists - one for eachmythology.

6. Run a small timing experiment to compar e the cost of usingvector and list . You can find an explanation on how to time aprogram in section 26.6.1 of the book (or on the web). GenerateN random int values in the range [0 : N ) . Aseach int is generated, insert it into a vector (which grows by oneelement each time). Keep the vector sorted; that is, a value isinserted after every previous value that is less than or equal tothe new value and before every previous value that is larger thanthe new value. Now do the same experiment using a lis t to hold theint s. For which N is the list faster than the vector ?Try to explain your result.

Hint 1: Use insert() instead of push_back() .

Hint 2:http://en.cppreference.com/w/cpp/numeric/random/uniform_int_distribution

7. Write a template class Pair that can hold a pair of values ofany type. Use this to implement a simple symbol table like the onewe used in the calculator.

8. Modify class Link from section 17.9.3 of the book to be atemplate with the type of value as the template argument. Then redoProblem 5 with Link . 2

Extra Information:

#include "std_lib_facilities.h"

class EuropeanOption {

public:

string type;

double spot_price;

double strike_price;

double interest_rate;

double volatility;

double time_to_maturity;

// Default constructor

EuropeanOption()

{

}

// Regular constructor with all field pre-set

EuropeanOption(string t, double spot_p, doublestrike_p, double i_rate, double v, double time)

: type(t)

, spot_price(spot_p)

, strike_price(strike_p)

, interest_rate(i_rate)

, volatility(v)

, time_to_maturity(time)

{

}

// N(d1) = 0.5 * erfc(-d1 * M_SQRT1_2)

double N(double value)

{

return 0.5 * erfc(-value *sqrt(0.5));

}

double get_price()

{

double price;

double d1 = (log(spot_price /strike_price) + (interest_rate + volatility * volatility / 2) *time_to_maturity) / (volatility * sqrt(time_to_maturity));

double d2 = d1 - volatility *sqrt(time_to_maturity);

if (type == "call") {

price = N(d1) *spot_price - N(d2) * strike_price * exp(-interest_rate *time_to_maturity);

} else {

price = N(-d2) *strike_price * exp(-interest_rate * time_to_maturity) - N(-d1) *spot_price;

}

return price;

}

};

int main()

{

double spt = 100.0; // spot_price

double strk = 100.0; // strike_price

double interest = 0.05; // interest_rate

double vol = 0.2; // volatility

double ttm = 1.0; // 1 year till mature

EuropeanOption* myOption_call = newEuropeanOption("call", spt, strk, interest, vol, ttm);

EuropeanOption* myOption_put = newEuropeanOption("put", spt, strk, interest, vol, ttm);

cout << "Spot price: " << spt <

cout << "Strike price: " << strk<< endl;

cout << "Interest rate: " << interest<< endl;

cout << "Volatility: " << vol <

cout << "Time to maturity: " << ttm<< endl;

cout << "Calculation results: " <

cout << "Call price: " <get_price() << endl;

cout << "Put price: " <get_price() << endl;

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Computer Performance Engineering 10th European Workshop Epew 2013 Venice Italy September 17 2013 Proceedings

Authors: Maria Simonetta Balsamo ,William Knottenbelt ,Andrea Marin

2013 Edition

3642407242, 978-3642407246

More Books

Students also viewed these Programming questions

Question

=+for the shareholder of the acquiring company?

Answered: 1 week ago

Question

=+for the shareholder of the acquired company?

Answered: 1 week ago

Question

=+for the acquired company?

Answered: 1 week ago