What is Stock Script?
Stock Script is a domain-specific language designed to help you declare stocks, manipulate their attributes, and perform operations like splits and merges—all with a simple, human-readable syntax. It's perfect for financial modeling, educational purposes, or just experimenting with stock-like entities in a controlled environment.
Key Features
- Intuitive Stock Declarations: Quickly define stocks with attributes like price and number of shares. Example:
stock AAPL { price: 150.50; shares: 100; } - Advanced Stock Operations: Perform operations like splits, reverse splits, merges, and price adjustments. Example:
AAPL.split(2); // 2-for-1 stock split AAPL.merge(MSFT); // Merge MSFT into AAPL AAPL.adjust_price(10%); // Increase price by 10% - Clear and Customizable Output: Use display commands to view detailed stock data, including price, shares, and market capitalization.
- Cryptocurrency Support: Extend functionality to include cryptocurrency trading and market analysis with the crypto module.
- Market Simulation: Simulate complex market scenarios using user-defined rules and interactions between stocks and cryptocurrencies.
- Human-Readable Syntax: Stock Script is easy to write and understand, making it suitable for both beginners and professionals.
Example
stock AAPL {
price: 150.50;
shares: 100;
}
stock MSFT {
price: 87.00;
shares: 250;
}
display AAPL;
AAPL.merge(MSFT);
display AAPL;
AAPL.split(2);
display AAPL.shares;
In this example, we define two stocks and merge MSFT into AAPL, then perform a 2-for-1 split on AAPL. The display commands show you how the changes affect price, shares, and market cap.
Getting Started
- Install textX
- Clone the stock-script interpreter repository.
- Write your .stock scripts and run them with the interpreter.
For detailed instructions, visit the GitHub repository.