Project Name: Ramstack
RAM stands for Randomness + Aptos + Move.
Introduction
Ramstack implements math modules and algorithms on-chain to simulate token pair price and predict option price.
Team
John A2N: Ramstack project representative. His responsibilities include:
- Paper research & Math advisor
- Ideas development
- Application prototype
Levi A2N: Smart contract developer. His responsibilities include:
- Develop Move modules
- Implement math formulas.
- Integrate smart contracts with the Ramstack frontend application.
About project
Ramstack is built for the Aptos RaNd0M Hack and runs on Aptos RandomNet. This project extends the use cases of Aptos Randomness by converting random numbers generated by the Randomness API to other random numbers following different probability distributions. Afterward, these numbers are used in the main module to simulate random price paths based on historical data.
This is the workflow of the price simulation feature:
- Retrieve historical price data of a token pair from the Binance API.
- Calculate statistical values.
- Call the price_simulation contract to generate price paths.
- Display price paths on the application frontend.
- Allow users to predict option prices based on Strike price and option type (Call or Put).
Build with
 |
- We use Aptos_std and Aptos_framework as the foundation to develop Ramstack. The most important modules are fixed_point64 and math_fixed64.
- To generate random numbers following probability distributions, we utilize the Aptos randomness API to generate uniform distribution numbers initially. Subsequently, math formulas such as Box-Muller and inverse CDF are applied to transform these numbers.
- For frontend development, we employ Aptos-labs/ts-sdk, Next.js, Redux Toolkit, Rechart, and Ant Design.
|
What it does
Our project employs the main idea of developing an on-chain algorithm using Monte Carlo in smart contracts and implementing distributed computation using smart contracts to simulate the token price. Our project includes features:
1. Extend aptos-move std math modules
- PI: Approximate the value of π using the Bailey-Borwein-Plouffe and Leibniz formulas.
- Cosine and Sine: Approximate Cos(x) and Sin(x) using the Maclaurin series formula, where x is in radians.
- Fixed Point64 with Sign: Enhance the original fixed_point64 module in the aptos_std package to support both positive and negative numbers.
- Math Fixed64 with Sign: Enhance the original math_fixed64 module in the aptos_std package to allow operations such as multiplication, division, natural logarithm, mean, standard variation, minimum, maximum, and square root using fixed_point64_with_sign. This enables operations on both negative and positive numbers.
2. Transform random numbers
- Box-Muller: Transform random numbers of uniform distribution (generated from Randomness) to a normal distribution using the Box-Muller method.
- Chi-square Transform: Transform random numbers of uniform distribution to Chi-square distribution. (uniform -> normal -> Chi-square)
- Laplacian Transform: Transform random numbers of uniform distribution to Laplacian distribution using the inverse CDF.
- Exponential Transform: Transform random numbers of uniform distribution to Exponential distribution using the inverse CDF.
3. Simulate token price paths
Implement the Monte Carlo algorithm on-chain to simulate price paths in the future. This algorithm utilizes random numbers from the normal distribution to calculate possible paths. The Box-Muller method and additional math modules are utilized in this implementation.
Visualize distributions of converted random numbers - Smart contract: Include view functions to generate random numbers based on inputs and specific distributions.
- Frontend: Retrieve random numbers and visualize them on charts.
|

|
Visualize price paths and predict option price - Smart contract: Include view functions to generate price paths based on inputs and the Monte Carlo simulation.
- Frontend: Display data on a chart. Users can view price paths, price steps, show/hide paths, show/hide data points, and predict option prices based on inputs.
|
 |
Challenges we ran into
- Challenge 1: Signed integers. In the first phase of development, the ideas we had intended to implement require complex mathematical formulas involving negative numbers using operations such as 'mul', 'div', 'sub', 'add', 'exp', 'ln', 'cosine', and 'sine'. Some of these formulas need to be associated with 'ln' and other elements. For example, if we use the 'ln_plus_32ln2' function, the returned result does not determine whether or not the original 'ln' is positive; it also adds 64*LN2 to the result. If the original result is F(x), then the calculated result using math_fixed64 is G(x), and there is a challenge to convert G(x) to F(x). Therefore, we have created two new modules: fixed_point64_with_sign and math_fixed64_with_sign.
- Challenge 2: Testing. We want all math formulas to be tested, so this work is a little extensive and requires hard work. All returned results are the original float. When we do that on-chain, all results must be multiplied by 2^64 (<< 64). To ensure correctness, we have to combine automated tests and manual verification with a calculator. We have also drawn experimental charts before publishing modules to ensure that generated random numbers follow distributions.
- Challenge 3: Approximation Error. Because we approximate results on-chain, this solution must introduce some noise. To address the approximation problem, we utilize math_fixed64_with_sign in every possible formula. While this approach still introduces bias, the bias is reduced.
- Challenge 4: Execution Limit Reached. We are uncertain about the exact limitation; it is related to how much random data we can generate on-chain. This limitation consistently affects probability distribution models. Asynchronous calls from the app client cannot be utilized because price paths are generated with the same price step values. Therefore, we resort to synchronous calls from the client, allowing a maximum of 150 paths to be generated using thousands of random numbers.
What we're proud of
A product based on the Aptos Randomness API. Ramstack can also contribute to the Aptos ecosystem by supporting developers in building complex math formulas for any kind of applications.
Try it out
Frontend application
Github
Math formulas
Deployed Ramstack on RandomNet