## 这个作业是用C++编写程序使用历史模拟方法来计算XX％的一日风险值的编程代写

EC7103 – C++ Programming for Finance – Coursework 3

In this coursework you have to write a programme to calculate the XX% one-day Value-at-Risk using the historical simulation method. In its simplest form, the method can be described as follows:

• Assume that you have data on prices of a given asset for n trading days, {x1,x2,…,xn}
• Simulate n-1 possible values (scenarios) for the price in day n+1 using the historical rate of change of the price of the asset as where i=2,…,n.
• These n-1 values can be used as the distribution of the likely prices tomorrow, assuming that each value is equally likely to occur.
• The XX% (e.g. 90%) VaR is calculated taking the (1-XX)% percentile of the distribution of prices calculated earlier, and subtracting its value to the last observation.

Your programme must load the data that you will be given provided, ask the user the confidence level used to calculate the VaR, calculate this value, and show it to the user in an informative way. For a more detailed explanation of the Historical Simulation method, please check the references given at the end of this assessment brief.

HINTS:

• We can input data from an external _le using the fstream library and using

ifstream source(“file_name.txt”);

vector<double> y;

double a;

if (source.is_open()){

while(!source.eof()){

source >> a;

y.push_back(a);

}

source.close();

}

where source is the stream for file.txt.

• The function sort(data.begin(),data.end(),compare) arranges in ascending order the numbers stored in a vector named data.
• The function floor(x) returns the integer part of double x.

Getting Started!

You can use the examples in the lectures and seminars as starting point, and reference to understand the use of the tools needed to solve this coursework. Some of the tools you need to complete this coursework can be found in the following books (and other references listed in the module handbook):

• For a full description of the Historical Simulation VaR you can read chapter 13 of Hull, J., 2012, Options, futures and other derivatives, eighth edition, Pearson
• M.J. Capinski and T. Zastawniak (2012), Numerical Methods in Finance with C++. Cambridge University Press.
• J. Duffy (2004), Financial Instrument Pricing Using C++. Wiley Finance.