-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathExoticEngine.cpp
45 lines (35 loc) · 1.09 KB
/
ExoticEngine.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
#include "StdAfx.h"
#include "ExoticEngine.h"
#include <cmath>
ExoticEngine::ExoticEngine(const Wrapper<PathDependent>& TheProduct_, const Parameters& r_)
: TheProduct(TheProduct_),
r(r_),
Discounts(TheProduct_->PossibleCashFlowTimes())
{
for (unsigned long i=0; i< Discounts.size(); i++)
Discounts[i] = exp(-r.Integral(0.0, Discounts[i]));
TheseCashFlows.resize(TheProduct->MaxNumberOfCashFlows());
}
void ExoticEngine::DoSimulation(StatisticsMC& TheGatherer, unsigned long NumberOfPaths)
{
MJArray SpotValues(TheProduct->GetLookAtTimes().size());
TheseCashFlows.resize(TheProduct->MaxNumberOfCashFlows());
double thisValue;
for (unsigned long i=0; i< NumberOfPaths; i++)
{
GetOnePath(SpotValues);
thisValue = DoOnePath(SpotValues);
TheGatherer.DumpOneResult(thisValue);
}
return;
}
double ExoticEngine::DoOnePath(const MJArray& SpotValues) const
{
unsigned long NumberFlows = TheProduct->CashFlows(SpotValues, TheseCashFlows);
double Value=0.0;
for(unsigned i=0; i< NumberFlows; ++i)
{
Value += TheseCashFlows[i].Amount * Discounts[TheseCashFlows[i].TimeIndex];
}
return Value;
}