-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
72 lines (56 loc) · 1.71 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include<cstdio>
#include<cstdio>
#include<vector>
#include<string>
#include"tinyxml/tinyxml.h"
#include "option.h"
using namespace std;
TiXmlDocument ProcessRequest(const TiXmlDocument &doc);
TiXmlElement *GetModelResults(const TiXmlElement *elem);
int main()
{
string filename = "request.xml";
TiXmlDocument doc(filename.c_str());
bool loadOkay = doc.LoadFile();
if(loadOkay)
{
TiXmlDocument response = ProcessRequest(doc);
}
else
{
printf("Error: %s not loaded.", filename.c_str());
}
return 0;
}
TiXmlDocument ProcessRequest(const TiXmlDocument &doc)
{
TiXmlDocument response("response.xml");
const TiXmlElement * elem = doc.RootElement()->FirstChildElement();
while(elem)
{
TiXmlElement * response_elem = GetModelResults(elem);
response.LinkEndChild(response_elem);
elem = elem->NextSibling() ? elem->NextSibling()->ToElement() : NULL;
}
return response;
}
TiXmlElement *GetModelResults(const TiXmlElement *elem)
{
TiXmlElement *list = new TiXmlElement("ResultList");
string ticker = elem->Attribute("ticker");
double strike = atof(elem->Attribute("strike"));
double expiry = atof(elem->Attribute("expiry"));
double rate = atof(elem->Attribute("rate"));
double div = atof(elem->Attribute("div"));
double args[] = {0,.25,rate, div, expiry };
VanillaCall call(strike);
for(int i = 0; i!= 10; ++i)
{
double spot = 40.0 + static_cast<double>(i)/10.0 * 10.0;
args[0] = spot;
double price = call.Price(args);
HedgeRatios greeks = call.Greeks(args);
printf("%f : %f delta=%f, gamma=%f, theta=%f, vega=%f, rho=%f\n", spot, price, greeks.delta, greeks.gamma, greeks.theta, greeks.vega, greeks.rho);
}
return list;
}