PHP code example of zyan / stock-generate

1. Go to this page and download the library: Download zyan/stock-generate library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

zyan / stock-generate example snippets




use Zyan\StockGenerate\StockGenerate;

// Configuration for the stock simulation
$config = [
    'symbol' => 'SZ10000', // Stock code
    'name' => 'Virtual Stock', // Stock name
    'start_date' => '2010-01-01', // Listing date
    'end_date' => null, // End date (null means today's date) or end day count
    'end_day' => null, // End day count (optional, overrides end_date if provided)
    'upper_limit_up' => 10, // Limit up percentage
    'upper_limit_down' => 10, // Limit down percentage
    'init_price' => 10, // Initial stock price
    'odds_limit_up_percentage' => 1, // Probability of limit up (percentage)
    'odds_limit_down_percentage' => 1, // Probability of limit down (percentage)
    'continuity_odds_limit_up_percentage' => 1, // Probability of consecutive limit up (percentage)
    'continuity_odds_limit_down_percentage' => 1, // Probability of consecutive limit down (percentage)
    'max_day_limit_up' => 10, // Maximum consecutive limit up days
    'max_day_limit_down' => 10, // Maximum consecutive limit down days
];

// Initialize the StockGenerate object with the configuration
$stock = new StockGenerate($config);

// Generate the stock data
$stock->go();

// Retrieve the generated stock data
$list = $stock->getList();

// Output the generated data
print_r($list);

Array
(
    [0] => Array
        (
            [date] => 2010-01-04
            [price] => 10.50
            [change] => 0.50
            [percentage_change] => 5.00
        )
    [1] => Array
        (
            [date] => 2010-01-05
            [price] => 10.00
            [change] => -0.50
            [percentage_change] => -4.76
        )
    ...
)