Stock market AI

Started by
53 comments, last by medovids 22 years, 2 months ago
Based on that then, you need the following factors:

Many broad economic indicators that affect stock prices.
Each company needs to be lumped into an industry sector - i.e. tech, industry, services, travel, leisure, health. Then, create industry specific economic indicators that affect prices in that industry.
Company specific press releases that affect that company''s stock and possibly related companies.

Using these 3 areas as starters, you can concoct many types of releases and news items with formulas connected to them. Each company will be affected on 3 levels. Overall economy, industry related and company related. Each news report will have an effect on 1 or more of those 3 areas on some sort of curve basis. There will be 2 changes that need to take place for every indicator, however. One is that of perception - which is usually fairly immediate (a day or two long). The second is the more concrete ramifications of the news report and tend to be longer lived (weeks, months or years).

For example, something good happens in a particular industry... there should be a jump in stocks in those industries as the "public" perception is affected positively... that may wear off after a couple of days and the stock may sink a bit. However, at that point - and for some time to come, the stock would be affected by the long term effects of whatever the news was. That would continue on until another news item about the same indicator supercedes it.

Real worldish example. An airline is trading at $20. News comes out that people will likely be travelling 10% more in the next year. Immediately (over 2 days), our airline (and others) may jump 5-10% as people try to get in on what looks to be an improving industry. On the 3rd day, the stock sinks 2-5% on "profit taking"... that is, the people who benefited from the initial jump cash in. We are now at a net gain of 3-5% or so. Now, as time passes (months), and the earnings reports come in on our airline... it does indeed show that there is more profit in the company and the dividends are paid out, etc. That is the concrete effect - and the stock may improve a certain amount over the course of that year. Of course, all this is based on the idea that no other news items come out to counter the first. Examples might be that the airline reports higher than expected maintanence expenses, an increase in the price of crude oil (fuel costs), a shrinking of the economy that causes a revision in the vacation travel predictions, etc.

The effect needs to be slow enough that, if the player watches carefully, they can get in on the "front of the curve". That is, if something good happens, and the player reacts right away, they will benefit from the "rest of the world" reacting as well.

Also, to show the day to day stuff, it wouldn''t hurt to throw a +/- random number in there so that there is minor fluctuation... but those should all be based off of the net rise or fall that you have calculated for the individual stock. It would be for appearance only and give people the option of "day trader" techniques.

If you are looking for someone to design the mathematical models and do the game balancing, that is my specialty. (I also have an OK handle on the stock market. ) However, I am not free. Hope the above helps point you in the right direction, though!


Dave Mark
Intrinsic Algorithm Development

Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

Advertisement
Remember, stocks rise (or fall) in anticipation of news. When the news is finally released, the stock price has done one of three things:

  • Overcompensated, in which case, even good news isn't good enough, and the stock price falls.
  • Pinned it right on the money, in which case the emotions of the general market will likely drag the price up or down.
  • Underestimated the magnitude of the news, in which case we get continued follow through on the stock's current trend.


On a separate note, let me point out the power of the trend. Inverstors and traders love stocks which trend. Individuals going long like smooth upward trends which continue for sometimes a couple of years. Short sellers love downward moving trends. These market players make the trend continue often well beyond what is reasonable. Huge profits exist for those who aren't left holding the bag at the end.

Let's take a look at JDSU on a 5 year chart. This stock (and a lot of other techs) had an amazing trend in 1999. Look specifically at JDSU's behavior in 1999. The 1999 trend was very straight, and its highs and lows could have been connected with a ruler. A random simulation would not produce this effect. What is happening is a self fulfilling pattern being created by traders and momentum investors basing their decisions off of the prior stock movement and pattern. Once the pattern breaks, traders lose confidence in the pattern, and anything goes.

If we look at the last few years in SUNW, we see a classic double bottom in late 1998. They are next to impossible to predict, but manifest themselves due to traders observing prior price bottoms. Once again, random simulation is almost guaranteed to not produce such phenomena.


___________________________________



Edited by - bishop_pass on January 17, 2002 3:33:05 PM
_______________________________
"To understand the horse you'll find that you're going to be working on yourself. The horse will give you the answers and he will question you to see if you are sure or not."
- Ray Hunt, in Think Harmony With Horses
ALU - SHRDLU - WORDNET - CYC - SWALE - AM - CD - J.M. - K.S. | CAA - BCHA - AQHA - APHA - R.H. - T.D. | 395 - SPS - GORDIE - SCMA - R.M. - G.R. - V.C. - C.F.
Another thing to consider is that there are really intertwining dynamics here...

In one case, the perception of a company affects the price movement of the stock.

In another case, the movement of the price of the stock affects the perception of the company.

After a little while, you have quite the chicken/egg routine going on and no one really knows what the stock SHOULD be valued at. Also, when you consider that some forces are determined by the perception and/or the market capitalization (like Enron''s debt ratings being changed) then you have a scenario where the stock slide caused a perception change which CAUSED a major business ripple that then caused another stock slide which caused a panic which caused another selloff which caused more business liquidity issues... etc...

Of course, then there is the faction that cares nothing for the company but only looks at the delta in price and cashes in on that.

Dave Mark
Intrinsic Algorithm Development

Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

Discussing perceptions and what ''causes'' stock prices to change is certainly worthwhile, but I think things are getting a little ahead of themselves. If you want to create a good AI then start simple and build up your complexity. This is true for ANY game AI. If you create a good agent structure then adding complexity is easy.

From Medovids latest post, it would seem that he seeks to create a trading game.

So, first off... write a design spec for the game. Include the gameplay features you want to have: how many players, number of stocks, speed of updates, etc. Visit the game design forum for help with this!

Then write a tech spec for your AI. Will you have seperate AI modules for each of the traders? What information do you need to store and how will you store it? What AI methodology will you use to make trading decisions?

Finally, when you are completely happy with all of this, then start planning out your code!

Perhaps Medovids you could post your tech spec so that people can hash it out with you and help you refine it?

Cheers,

Timkin
Stocks'' values are affected by the conditions of the company, the given industry, and the economy as a whole. All these things factor into the decisions traders make. Traders also look for long-term statistical trends.

Now: How do we determine the state of a given industry? We''ll simply say that it is a number between 1 and -1 that represents growth. How do you determine it? Here''s one technique: Let''s say you''re investing in an agricultural company. Run a meteorological simulation, a simulation of global population growth (and thus food demand), and simulations of a thousand other things - because, as we all know, it isn''t random.

But it might as well be.

Roll a pair of dice. Is this random? No. Depending on the exact way you apply force, the exact properties of the materials the dice and the surface they are landing on, and a hundred other things, they will land with a specific face pointing upwards. Given enough information, you could deterministically simulate this. But there''s no need to. Just use a random number generator.

Like dice, stocks are affected by a thousand factors which we can never hope to simulate. All we know is that the end result is fractal. You could just use midpoint displacement.

But this wouldn''t be very entertaining, would it? You need some way for the player to predict stocks. So here''s my plan:

Use random midpoint displacement or perlin noise to simulate various factors that you will use to determine a stock''s value. Notify the player when these factors exceed certain minimum and maximum thresholds of value, and for a lack of better terms, velocity and acceleration. Have several pre-written messages for each such event, such as "[INDUSTRY NAME] Booming!" or "[COMPANY NAME]''s Product a Flop!"

Let''s say you have 100 companies in your simulation. Each company will fit into a single industry. Each industry has a graph associated with it. Each company also has its own graph, to represent its management and other company-specific things. Finally there is a master economy graph. As I mentioned before, each graph is generated using something like midpoint displacement. Now, the value of a given companies'' stock can simply be the sum of the current y values on each of these graphs. Each graph will of course also need a coefficient to signify its importance.

To further improve this simulation, you can add events such as mergers, buyouts, and splits. Each event would have a probability proportional to a certain factor. Buyouts of Compay X could have an increased probability when Company X''s "velocity" is negative, and below a certain amount.

And that''s all there is. This strategy allows for the appearance of external events, but also recognizes the fact that the stock market is indeed chaotic in nature. It attempts to simulate the stock market through Fractional Brownian Motion, and I think it should do a decent job.
quote:Original post by Torn Space
You could also just connect to yahoo or something and download the prices. Can''t get much more accurate than that.


Actually I thought this sounded like a great idea. You can get web updates every 20 mintes. This wouldn''t work for day trading, but you''ld have everything you need right there for long haul stock simulation.

Another approach however is to simplify the AI considerably taking into effect some factors that seemed to me at the time reasonable. Each of these is on a continuum.

1) Never trades -- Day Trader
2) Low Risk -- High Risk
3) Single Stock -- Diversified Portfolio
4) Picks every stock themself -- Personal Portfolio Manager
5) Anything else you''ld like to include.

Certain things will of course go together. Day Traders will probably go for high risk stocks as such. The point is is that you don''t have to create dynamic personalities for this. Take what is already obviously out there. Don''t go from the standpoint that well this person has a family and it very conservative so he/she won''t trade very often and won''t get into high risk stocks. Go about it from the other direction. Create their behavior and then give the person personality if they want it.

Some of my own personal observations about the stock market (though I don''t pretend to be an expert). Certain stocks are dinasaurs. They''re massive and they don''t go very far. They''re safe bets almost all the time. Utilities before deregulation. Really old companies that have been around like GM and IBM (no it has nothing to do with acronyms). I only mention this because I don''t remember reading it in the above posts.

Orion
quote:Original post by TerranFury
Stocks'' values are affected by the conditions of the company, the given industry, and the economy as a whole.
[snip]
Let''s say you have 100 companies in your simulation. Each company will fit into a single industry. Each industry has a graph associated with it. Each company also has its own graph, to represent its management and other company-specific things. Finally there is a master economy graph.


Funny... that''s what I said a while back!



Dave Mark
Intrinsic Algorithm Development

Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

quote:Original post by _Orion_
Another approach however is to simplify the AI considerably taking into effect some factors that seemed to me at the time reasonable. Each of these is on a continuum.

Remember, we are trying to model the market, not the trader.

Dave Mark
Intrinsic Algorithm Development

Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

quote:Original post by InnocuousFox
Remember, we are trying to model the market, not the trader.


Actually, that''s an assumption you are making IF. Medovids actual request was that he wanted a method of making the stock prices realistic. There are 3 ways that I see this is possible: 1) use real stock prices; 2) simulate the market price using a mathematical model; or 3) simulate the market using artificial traders so as to generate a ''market price''.

Each of these ideas has been discussed. Now it really depends on Medovids which one he prefers.

Timkin

quote:Original post by medovids
I am looking too make a stock market game where you buy the stocks you want and you try too make money!

What I wnat is too make the stock market prices realistic. From what I understood that is exactly what we are trying to figure out.

sorry for the misunderstanding.


Uh... this is what I was going off of. It is my understanding that he wants to "make the stock market prices realistic." That is to say he wants to model the market. The player is the trader. Certainly one of the methods addressed was modeling many virtual traders as a way of making the market move... but that was prior to us clarifying what it was he wanted.



Dave Mark
Intrinsic Algorithm Development

Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

This topic is closed to new replies.

Advertisement