SERVING THE QUANTITATIVE FINANCE COMMUNITY

 
User avatar
Cuchulainn
Topic Author
Posts: 54228
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

Monte Carlo: is PathEvolver:Price 1:1 or 1:N?

October 20th, 2017, 6:18 pm

// A message buffer that is shared by the agents.
concurrency::overwrite_buffer<double> buffer;
concurrency::overwrite_buffer<bool> sentinel;

// Communication with MIS agent (draw count)
concurrency::overwrite_buffer<std::size_t> misCount;

// Create and start the producer and consumer agents.
OptionData myOption((
 OptionParams::strike = 65.0, OptionParams::expiration = 0.25,
 OptionParams::volatility = 0.3, OptionParams::dividend = 0.0,
 OptionParams::optionType = 1, OptionParams::interestRate = 0.08));


// ...

OptionData myOption4((
 OptionParams::strike = 60.0, OptionParams::expiration = 0.25,
 OptionParams::volatility = 0.3, OptionParams::dividend = 0.0,
 OptionParams::optionType = 1, OptionParams::interestRate = 0.08));

int NT = 500;
int NSIM = 1'000'000;

StopWatch<> sw;
sw.Start();

PathEvolver producer(buffer, sentinel, misCount, NT, NSIM, myOption);
OptionPricer consumer(buffer, sentinel, myOption);
// ...
OptionPricer consumer5(buffer, sentinel, myOption4);
MIS mis(misCount, sentinel, 100'000);
MIS mis2(misCount, sentinel, 100'100);

producer.start();
consumer.start();
// ...
consumer5.start();
mis.start();
mis2.start();

// Wait for the agents to finish.
concurrency::agent::wait(&producer);
concurrency::agent::wait(&consumer);
// ...

concurrency::agent::wait(&consumer5);
concurrency::agent::wait(&mis);
concurrency::agent::wait(&mis2);

sw.Stop();
std::cout << "Elapsed time, Raw creation: " << sw.GetTime() << '\n';

std::cout << '\n' << consumer.Price() << '\n';
std::cout << '\n' << consumer2.Price() << '\n';
std::cout << '\n' << consumer3.Price() << '\n';
std::cout << '\n' << consumer4.Price() << '\n';
std::cout << '\n' << consumer5.Price() << '\n';

1:1
One pricer has its own path evolver

1:N 
Multiple (different) pricers use the same path infomation from a single path evolver

Are there major differences? Of course, the 2nd case is much faster. And easier to configure. And no chance of a race condition.
http://www.datasimfinancial.com

What is 2^77232917 -1?
ABOUT WILMOTT

PW by JB

Wilmott.com has been "Serving the Quantitative Finance Community" since 2001. Continued...


JOBS BOARD

JOBS BOARD

Looking for a quant job, risk, algo trading,...? Browse jobs here...