3 ms·
Your approach is intriguing. I appreciate the inclusion of descriptions that elucidate what's happening in the code; this is often lacking in professional and s
by darou 3y ago
Your approach is intriguing. I appreciate the inclusion of descriptions that elucidate what's happening in the code; this is often lacking in professional and scientific programming. This is particularly relevant in quantitative finance, where many bugs stem from misunderstandings related to the timing associated with variables.
To address this, we implemented a similar concept in ThetaML for defining stochastic processes, financial instrument payoffs, and trading strategies. We introduced the
theta t
operator, which represents the passage of time t. Here's how a stochastic process might be represented:
S = 1
loop inf
theta @dt
S = S * exp( (r - 0.5 * sigma^2) * @dt
end
We also introduced stochastic expressions like expected value E(V!) given the current state of all simulated values where V! is a reference to the future value of V.
Example:
1: model EuropeanPut
2: % This model returns a simulated European put option price
3: import S “Stock prices”
4: import CUR “Discount factor”
5: import K “Strike price for the European put option”
6: import T “Time to maturity in years”
7: export P “European put option price”
8:
9: P = E(V_CUR!)
10: % T years pass
11: theta T
12: % at maturity T, the option payoff is discounted to time 0
13: V_CUR = max(K - S, 0) * CUR
14:
15: end
This system enables the evaluation of the models using Monte Carlo Simulations and the computation of expected values E(x!) using regression techniques.
For those interested, you can find more information in the ThetaML Handbook:
Here is the ThetaML Handbook: https://www.thetaris.com/doc/book-2012-thetaml-Handbook.pdf https://www.thetaris.com/doc/book-2012-thetaml-Handbook.pdf