Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

We are in the process of building a stock market simulation game. The frontend design is ready but we are clueless about how exactly the back-end algorithms are to be designed.

What algorithms should we be looking at implementing in order to get this working?

We're coding in PHP/RoR/Python.

If there's an open source system that already exists that we could look at that would be an added bonus.

share|improve this question

migrated from webapps.stackexchange.com Jun 16 '11 at 14:22

This question came from our site for power users of web applications.

    
To get what working? Do you need algorithms to simulate the stock market? –  David Thornley Jun 16 '11 at 15:16
1  
/dev/random –  Jarrod Roberson Jun 16 '11 at 15:20
    
If this is a request for algorithms to simulate the stock market, it's off-topic here; otherwise the site would be open to discussion of essentially any topic. –  David Thornley Jun 16 '11 at 15:29
    
Are you trying to simulate the stock market, or a completely fictional one? –  whatsisname Jun 16 '11 at 15:44

3 Answers 3

Most generic thing, used also in physics simulation, is the Monte Carlo method. Due computational complexity in finance they are often substituted with simpler algorithms designed for specific task (like for example Black–Scholes for derivatives market). You can read about Monte Carlo method (and alternatives) application in finance in wiki.

Open source solutions? Only one that comes to mind is the QuantLib.

share|improve this answer

That's a billion dollar question. :-)

You might want to look into Steve Keen's research, or even get in touch with him. He's an engineer by train and posts his models here and there on his blog. I wouldn't be surprised if he'd be open to cooperate with you guys if you're implementing his models and share back in a way or another. (e.g. The models themselves, and you operating a live study of market dynamics using them and sharing the raw results with him.)

Barry Ritholtz might be another option for more or less the same idea, but keep in mind he's running an actual company, and that their models are private/proprietary. So I doubt they'd share them openly. (The same could be said for many a hedge fund or bank.)

Else you may find the Wikipedia interesting:

http://en.wikipedia.org/wiki/Financial_modeling

These problems are often stochastic and continuous in nature, and models here thus require complex algorithms, entailing computer simulation, advanced numerical methods such as numerical differential equations, and / or the development of optimization models. The general nature of these problems is discussed under Modeling and analysis of financial markets, while specific techniques are listed under Outline of finance: Mathematical tools.

share|improve this answer

For a game simulation, I'd rely a lot on a pseudo-random number generator. If it's obfuscated enough, players will never know and it's close enough to reality that it largely doesn't matter.

I'd assign a random initial "true value" for each item and have it fluctuate with a sinusoidal pattern or something with varying periods and amplitude. A categorical fluctuation and one overarching fluctuation would help. So globally, prices could be going up, but the fubar industry isn't as hot, while the specific fubar maker is in a rut and actually losing money.
Categories could be industries, regions, everyone with a name that's similar to a big company, or whatever fits into your game.
You could sprinkle in newsworthy events at random times for specific companies, categories, or global events. Spikes, crashes, small increases/decreases for the next 5 years, and so on.

But that's all the "true value". Which is largely irrelevant for stocks. So I'd have a number of agents that followed a set of policies for buying and selling with their own cash flow and profit. If the player, or one of the agents, wants to buy or sell, he has to make an offer that an agent agrees to. Someone inevitably goes bust and another is spawned.
One agent would be sane, rational, and well informed with a ludicrous pocketbook. He knows what the true value is and buys or sells when the price is good after a significant delay. He's supposed to be the general public and keeps things from getting too weird.
The rest would follow a policy, analyzing patterns trying to guess the true value and future trends.
One would buy whenever he saw a prolonged period of growth. Selling when it flat-lined.
One would never sell unless he made a buck.
One would try the classic pump and dump scheme.
And so on. I think this is the point where you would apply QuantLib and the other answers about mathematical finances.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.