> For the complete documentation index, see [llms.txt](https://docs.fyde.fi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.fyde.fi/fyde-trading-game/game-market-simulation.md).

# Game Market Simulation

## Abstract

This document describes the mathematical foundation behind the price generation and market dynamics of the game. The model is inspired by financial markets, using random processes and market factors to simulate the fluctuation of asset prices. The primary mathematical concepts employed include **geometric Brownian motion**, random drift, and volatility, which together form a stochastic process for price generation. We present the formulas and their explanations, followed by a discussion of how these components are combined into a functioning market model.

## 1. Random Data Point Generation

The asset prices in the game follow the principles of [**geometric Brownian motion (GBM)**](https://unofficed.com/courses/markov-model-application-of-markov-chain-in-stock-market/lessons/geometric-brownian-motion-gbm-in-stock-market/), which models stock price behavior using the following formula:

$$
dS\_t = \mu S\_t dt + \sigma S\_t dW\_t
$$

Where:

* ( $$dS\_t$$) is the price of the asset at time ( t ),
* ( $$\mu$$ ) is the drift as average rate of return over time,
* ( $$\sigma$$ ) is the volatility as the randomness or risk in the market,
* ( $$dW\_t$$ ) is random component as a Wiener process

In discrete time, this becomes:

$$
S\_{t+1} = S\_t \cdot e^{(\mu - \frac{1}{2} \sigma^2) \Delta t + \sigma \sqrt{\Delta t} Z}
$$

Where:

* ( $$Z \sim N(0, 1)$$ ) is a standard normal random variable,
* ( $$\Delta t$$ ) is the time step.

## 2. Initial Setup

At the beginning of the game, each asset is initialized with random drift and volatility:

* **Drift**: A random drift is assigned to each asset, with a 60% probability of a positive trend.
* **Volatility**: A random level of volatility is assigned to simulate market risk.

Formula for initial drift:

$$
\mu = \begin{cases} DRIFT \times (0.5 + \text{rand()}) & \text{if } \text{rand()} < 0.6 \ -DRIFT \times \text{rand()} & \text{otherwise} \end{cases}
$$

## 3. Updating Prices Over Time

As the game progresses, prices update based on pre-generated data points, which simulate time evolution.

The absolute gain and percentage gain are calculated as:

$$
\text{percentageGain}\_t = \frac{\text{New Price} - \text{Previous Price}}{\text{Previous Price}}
$$

$$
\text{absoluteGain}\_t = \frac{\text{New Price} - \text{initialPrice}}{\text{initialPrice}}
$$

## 4. Market Influence and Weighted Average

The performance of individual assets influences the overall market performance. The market's value is a weighted sum of individual assets' performance, based on their allocation.

Let ( $$A\_i$$ ) be the allocation of asset ( $$i$$ ) in the market, and ( $$P\_i(t)$$ ) be the price of asset ( $$i$$ ) at time ( $$t$$ ). Then the market value ( $$M(t)$$ ) is calculated as:&#x20;

$$
M(t) = \sum\_{i} A\_i P\_i(t)
$$

The percentage gain for the market is calculated as:

$$
\text{Market Percentage Gain} = \frac{M(t) - M(t-1)}{M(t-1)}
$$

Where ( $$M(t-1)$$ ) is the market value from the previous period.

## 5. Summary

The game uses a simplified **geometric Brownian motion** model to simulate asset prices, where random drift and volatility generate price movements over time.

&#x20;The combined performance of all assets influences the overall market, weighted by asset allocations. The result is a dynamic simulation where prices can rise and fall unpredictably, while still adhering to the underlying mathematical principles of financial markets.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.fyde.fi/fyde-trading-game/game-market-simulation.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
