• C++ Programming for Financial Engineering
    Highly recommended by thousands of MFE students. Covers essential C++ topics with applications to financial engineering. Learn more Join!
    Python for Finance with Intro to Data Science
    Gain practical understanding of Python to read, understand, and write professional Python code for your first day on the job. Learn more Join!
    An Intuition-Based Options Primer for FE
    Ideal for entry level positions interviews and graduate studies, specializing in options trading arbitrage and options valuation models. Learn more Join!

Monte Carlo simulation using Java?

Joined
3/3/11
Messages
22
Points
11
I've heard that fast languages like C++ are better at implementing this type of quant simulation compare to Java. But I'm planning to use Java anyway. What would you recommend?
 
I've heard that fast languages like C++ are better at implementing this type of quant simulation compare to Java. But I'm planning to use Java anyway. What would you recommend?

Hi karafrylee! If you are already aware of C++ strength and still intend to implement your simulations in Java then go ahead. Java is not the language I think to do the numerical work. For web based applications it is still commonly used. C++ is much better in simulation techniques and generally all numerical calculations if you bet on speed as you must be willing since you might want to simulate a large amount of data vectors.
 
I think Java is fine. The difference in speed of runtime is minmial. However, Java provides better library so development time could be less. However, programming in Java isn't what a quant usually do.
 
I think Java is fine. The difference in speed of runtime is minmial. However, Java provides better library so development time could be less. However, programming in Java isn't what a quant usually do.

Yes that was my point also. Like .NET rich library, development time is less. It is more flexible, less time consuming but for compilation takes more time than C++. And for quantitative works C++ is preferred over any other programming languages because of its compilation speed. It hasn't got a overloaded library to carry while compiling your application. So it is far much faster than others on average.
 

Let's think of it this way: we have a trade off to make between development and processing time. If the concern is minimizing the development time then we should select those programming languages which have richer libraries like C# which is one of the most sophisticated language carrying a rich library making the development time to be minimized. You don't have to reinvent the wheel when working on .NET 4 platform since it grants you the capabilities to do whatever you want from the richest toolbox. But in C++ you have to invent some classes since you are not granted such capabilities. But that downside has one advantage: rich library requires more processing time, since C++ hasn't got such rich library it is by far fast than C#. I have read somewhere recently that well designed C# application can be 90% as fast as well designed C++ application. But achieving well design in C++ can be quite complicated due to some reasons mentioned above. That's what I meant. You can view C# as the Microsoft version of Java. C++ is faster than Java but it also depends on the application specifics. There are some nuances which are impossible (or very very hard) to achieve in C++. But all in all, C++ is and will always remain as number 1 programming language for quants since we sometimes need to make algorithms processing a large number of data. Let's take your case, you need some simulation to conduct, C++ will definitely handle numerical calculations faster than Java especially if you are shooting a large number of vectors. But Java and other languages are ok, we only have to choose the priorities: Speed and efficiency on the expense of big development time or less development time and more processing time.

Best
Tsotne
 
Tsotne, thank you for the useful insight of all these languages. You mentioned minimizing development time, that's exactly what I am trying to do. Speed is definitely not an issue here so I will definitely stick to Java for now.
 
Tsotne, thank you for the useful insight of all these languages. You mentioned minimizing development time, that's exactly what I am trying to do. Speed is definitely not an issue here so I will definitely stick to Java for now.

Yes. If your main concern is development time your better choice is Java. If you intend to minimize that time even further then try some more sophisticated languages. I would suggest C# since it fits with mathematicians' fantasy well. But this is a suggestion for future. Now concentrate on Java.

Good Luck
 
just remember this "premature optimization is the root of all evil" - Donal Knuth
 
Let's think of it this way: we have a trade off to make between development and processing time. If the concern is minimizing the development time then we should select those programming languages which have richer libraries like C# which is one of the most sophisticated language carrying a rich library making the development time to be minimized. You don't have to reinvent the wheel when working on .NET 4 platform since it grants you the capabilities to do whatever you want from the richest toolbox. But in C++ you have to invent some classes since you are not granted such capabilities. But that downside has one advantage: rich library requires more processing time, since C++ hasn't got such rich library it is by far fast than C#. I have read somewhere recently that well designed C# application can be 90% as fast as well designed C++ application. But achieving well design in C++ can be quite complicated due to some reasons mentioned above. That's what I meant. You can view C# as the Microsoft version of Java. C++ is faster than Java but it also depends on the application specifics. There are some nuances which are impossible (or very very hard) to achieve in C++. But all in all, C++ is and will always remain as number 1 programming language for quants since we sometimes need to make algorithms processing a large number of data. Let's take your case, you need some simulation to conduct, C++ will definitely handle numerical calculations faster than Java especially if you are shooting a large number of vectors. But Java and other languages are ok, we only have to choose the priorities: Speed and efficiency on the expense of big development time or less development time and more processing time.

Best
Tsotne

You say C# is slower because it has "a rich library". That's entirely not true. It doesn't even seem like you understand what that term even means. The classes from the library which is utilized in your programs are the ones you call explicitly. The base library itself has nothing to do with .NET's speed of execution. It's not like the compiler scans over the entire library or something.
 
... You mentioned minimizing development time, that's exactly what I am trying to do.

if you want to minimize development time, use a high level language with high level constructs. R is an easy choice for this. I will suggest Python as well. C++ and Java are too verbose.
 
You say C# is slower because it has "a rich library". That's entirely not true. It doesn't even seem like you understand what that term even means. The classes from the library which is utilized in your programs are the ones you call explicitly. The base library itself has nothing to do with .NET's speed of execution. It's not like the compiler scans over the entire library or something.

Rich library. isn't a complexity of a language's programming constructs determining what the speed will be?! Greater the ability of a language to handle problems or minimize the development time, lower the speed will be and vise versa. Take again C++, which is much more complex and difficult language than C#. It's complexity determines it's speed. It's kinda "rude" meaning that you have to handle many matters by hand which could be resolved in managed languages easily. The complexity of a language determines the speed. Give me one example where programming language is more difficult and complex and has a low speed of executing applications and vise versa.
 
Rich library, isn't a complexity of a language's programming constructs determining what the speed will be?! Greater the ability of a language to handle problems or minimize the development time, lower the speed will be and vise versa. Take again C++, which is much more complex and difficult language than C#. It's complexity determines it's speed. It's kinda "rude" meaning that you have to handle many matters by hand which could be resolved in managed languages easily. The complexity of a language determines the speed. Give me one example where programming language is more difficult and complex and has a low speed of executing applications and vise versa.

- "Rich library, isn't a complexity of a language's programming constructs determining what the speed will be"
Again, the library has nothing to do with .NET's execution speed. It's just a collection of assemblies sitting somewhere in a folder on your pc which you can call into your program.

- "It's complexity determines it's speed. It's kinda "rude" meaning that you have to handle many matters by hand which could be resolved in managed languages easily"
Once they both get compiled, it doesn't matter. That isn't why C++ is faster; but it is faster initially though, i'm not denying that. The real issue here is not even C#, but .NET itself, so the "complexity of a language's programming constructs" is irrelevant. C# has more keywords. It has a larger base library, and has pointers just as in C++ (although not as powerful). You can handle low level issues with it. It is still a general purpose language. You can run it unmanaged, and with some slight modifications to .NET's JIT compiler, can outperform C++ in many cases.
 
- "Rich library, isn't a complexity of a language's programming constructs determining what the speed will be"
Again, the library has nothing to do with .NET's execution speed. It's just a collection of assemblies sitting somewhere in a folder on your pc which you can call into your program.

- "It's complexity determines it's speed. It's kinda "rude" meaning that you have to handle many matters by hand which could be resolved in managed languages easily"
Once they both get compiled, it doesn't matter. That isn't why C++ is faster; but it is faster initially though, i'm not denying that. The real issue here is not even C#, but .NET itself, so the "complexity of a language's programming constructs" is irrelevant. C# has more keywords. It has a larger base library, and has pointers just as in C++ (although not as powerful). You can handle low level issues with it. It is still a general purpose language. You can run it unmanaged, and with some slight modifications to .NET's JIT compiler, can outperform C++ in many cases.

...but it is faster initially though
???

I really wonder: Doesn't a namespace imported effect the speed on the execution? I mean, when you have included a namespace, you have loaded then all the members of it with no option ro select among them which one to choose and which not - all is loaded. Does the execution speed completely ignore the size of that namespace?
 
???

I really wonder: Doesn't a namespace imported effect the speed on the execution? I mean, when you have included a namespace, you have loaded then all the members of it with no option ro select among them which one to choose and which not - all is loaded. Does the execution speed completely ignore the size of that namespace?

Not fully following you. Lets say i'm using System.Threading.Tasks: that's one specific file in a folder (It's really two but w/e). And within that file, CIL code is housed. It's a similar process as in C++ and almost every programming language. So I don't see why bring it up? We're not talking about compile time speed here. We're talking about execution speed. Hell, the .NET compiler will be able to tell what processor you're on and optimize your code for that specific processor. C++ compiler cannot do that.
 
I've heard that fast languages like C++ are better at implementing this type of quant simulation compare to Java. But I'm planning to use Java anyway. What would you recommend?

BTW, you can find many free Monte Carlo Codes in Java. I have several libraries downloaded and PDF files for MC in Java read. I can send you if interested.
 
I've heard that fast languages like C++ are better at implementing this type of quant simulation compare to Java. But I'm planning to use Java anyway. What would you recommend?

I second that if you want to minimize developing time you should go with python or R, if you still stick to Java just make sure you use BigDecimal instead of Double.
 
???

I really wonder: Doesn't a namespace imported effect the speed on the execution? I mean, when you have included a namespace, you have loaded then all the members of it with no option ro select among them which one to choose and which not - all is loaded. Does the execution speed completely ignore the size of that namespace?

Namespaces has nothing what so ever to do with this.

First of all, for the runtime (the CLR), there is nothing like a namespace, the namespace as we developers know and use is for the CLR just part of the typename.

Secondly, by default the CLR uses JIT compilation, which means that a particular class / method is not loaded until it is used for the first time. I.e. so when you execute a particular method for the first time in a running program, that method's IL code will be compiled into machine code and then subsequent executions of that method will directly execute the machine code. So the first execution of a method may be slower than subsequent executions, and I believe that is what AWilliams above are referring to when he says that C++ may be faster initially. Oh, and you can instead of using JIT compilation, pre-compile your application to get around this issue.

Niels
 
Back
Top