diff --git a/miner-dummy.local.config.js b/miner-dummy.local.config.js deleted file mode 100644 index 106c99a1..00000000 --- a/miner-dummy.local.config.js +++ /dev/null @@ -1,9 +0,0 @@ -module.exports = { - apps: [ - { - name: 'miner-dummy-local', - script: 'python3', - args: './neurons/miner.py --netuid 1 --logging.debug --logging.trace --subtensor.chain_endpoint ws://127.0.0.1:9946 --wallet.name miner-dummy --wallet.hotkey default --axon.port 10000 --miner_type dummy' - }, - ], -}; diff --git a/neurons/miner.py b/neurons/miner.py index afaf0209..af30152f 100644 --- a/neurons/miner.py +++ b/neurons/miner.py @@ -23,7 +23,7 @@ # import base miner class which takes care of most of the boilerplate from simulation.base.miner import BaseMinerNeuron -from simulation.miner import generate_simulations, generate_fixed_simulation +from simulation.miner.simulations import generate_simulations from simulation.protocol import Simulation @@ -60,26 +60,19 @@ async def forward(self, synapse: Simulation) -> Simulation: f"Received prediction request from: {synapse.dendrite.hotkey} for timestamp: {simulation_input.start_time}" ) - bt.logging.info(f"Miner triggered with type: {self.config.miner_type}") - dt = simulation_input.start_time asset = simulation_input.asset time_increment = simulation_input.time_increment time_length = simulation_input.time_length num_simulations = simulation_input.num_simulations - if self.config.miner_type == "dummy": - prediction = generate_fixed_simulation( - start_time=dt, time_length=86400 - ) - else: - prediction = generate_simulations( - start_time=dt, - asset=asset, - time_increment=time_increment, - time_length=time_length, - num_simulations=num_simulations, - ) + prediction = generate_simulations( + start_time=dt, + asset=asset, + time_increment=time_increment, + time_length=time_length, + num_simulations=num_simulations, + ) synapse.simulation_output = prediction @@ -214,4 +207,4 @@ def print_info(self): with Miner() as miner: while True: miner.print_info() - time.sleep(15) + time.sleep(5) diff --git a/simulation/simulations/__init__.py b/simulation/miner/__init__.py similarity index 100% rename from simulation/simulations/__init__.py rename to simulation/miner/__init__.py diff --git a/simulation/simulations/price_simulation.py b/simulation/miner/price_simulation.py similarity index 53% rename from simulation/simulations/price_simulation.py rename to simulation/miner/price_simulation.py index c29d9793..0a921a88 100644 --- a/simulation/simulations/price_simulation.py +++ b/simulation/miner/price_simulation.py @@ -51,19 +51,6 @@ def simulate_single_price_path( return price_path -def generate_real_price_path( - current_price, time_increment, time_length, sigma -): - """ - Generate a 'real' price path. - """ - # No random seed set to ensure independent random numbers - real_price_path = simulate_single_price_path( - current_price, time_increment, time_length, sigma - ) - return real_price_path - - def simulate_crypto_price_paths( current_price, time_increment, time_length, num_simulations, sigma ): @@ -79,52 +66,3 @@ def simulate_crypto_price_paths( price_paths.append(price_path) return np.array(price_paths) - - -def calculate_price_changes(price_paths): - """ - Calculate the incremental price changes between consecutive time increments. - """ - return np.diff(price_paths, axis=1) - - -def calculate_crps_over_time(simulated_values, real_values): - """ - Calculate the CRPS over time. - """ - num_time_steps = simulated_values.shape[1] - crps_values = np.zeros(num_time_steps) - for t in range(num_time_steps): - forecasts = simulated_values[:, t] - observation = real_values[t] - crps_values[t] = crps_ensemble(observation, forecasts) - return crps_values - - -def calculate_cumulative_price_changes(price_paths): - """ - Calculate the cumulative price changes from the start time to each time increment. - """ - initial_prices = price_paths[:, [0]] # Shape: (num_paths, 1) - cumulative_changes = ( - price_paths - initial_prices - ) # Broadcasting subtraction - return cumulative_changes - - -def calculate_price_changes_over_intervals(price_paths, interval_steps): - """ - Calculate price changes over specified intervals. - - Parameters: - price_paths (numpy.ndarray): Array of simulated price paths. - interval_steps (int): Number of steps that make up the interval. - - Returns: - numpy.ndarray: Array of price changes over intervals. - """ - # Get the prices at the interval points - interval_prices = price_paths[:, ::interval_steps] - # Calculate price changes over intervals - price_changes = np.diff(interval_prices, axis=1) - return price_changes diff --git a/simulation/miner.py b/simulation/miner/simulations.py similarity index 53% rename from simulation/miner.py rename to simulation/miner/simulations.py index 1049873b..ff30e41d 100644 --- a/simulation/miner.py +++ b/simulation/miner/simulations.py @@ -1,11 +1,9 @@ -from simulation.simulations.price_simulation import ( +from simulation.miner.price_simulation import ( simulate_crypto_price_paths, get_asset_price, ) from simulation.utils.helpers import ( - get_current_time, convert_prices_to_time_format, - round_time_to_minutes, ) @@ -15,7 +13,6 @@ def generate_simulations( time_increment=300, time_length=86400, num_simulations=1, - sigma=0.01, ): """ Generate simulated price paths. @@ -26,7 +23,6 @@ def generate_simulations( time_increment (int): Time increment in seconds. time_length (int): Total time length in seconds. num_simulations (int): Number of simulation runs. - sigma (float): Standard deviation of the simulated price path. Returns: numpy.ndarray: Simulated price paths. @@ -38,6 +34,9 @@ def generate_simulations( if current_price is None: raise ValueError(f"Failed to fetch current price for asset: {asset}") + # Standard deviation of the simulated price path + sigma = 0.01 + simulations = simulate_crypto_price_paths( current_price=current_price, time_increment=time_increment, @@ -51,37 +50,3 @@ def generate_simulations( ) return predictions - - -def generate_fixed_simulation( - asset="BTC", - start_time=None, - time_increment=300, - time_length=86400, - num_simulations=1, - sigma=0.01, -): - """ - Generate constant results. Method is used just for test. Don't use in a real simulation. - - Parameters: - asset (str): The asset to simulate. Default is 'BTC'. - start_time (str): The start time of the simulation. Defaults to current time. - time_increment (int): Time increment in seconds. - time_length (int): Total time length in seconds. - num_simulations (int): Number of simulation runs. - sigma (float): Standard deviation of the simulated price path. - - Returns: - numpy.ndarray: Simulated price paths. - """ - - simulations = [ - [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000] - ] - - predictions = convert_prices_to_time_format( - simulations, start_time, time_increment - ) - - return predictions diff --git a/simulation/validator/crps_calculation.py b/simulation/validator/crps_calculation.py index 3275ead3..a6d3504c 100644 --- a/simulation/validator/crps_calculation.py +++ b/simulation/validator/crps_calculation.py @@ -1,10 +1,5 @@ import numpy as np -import pandas as pd from properscoring import crps_ensemble -from simulation.simulations.price_simulation import ( - calculate_price_changes_over_intervals, -) -import os def calculate_crps_for_miner(simulation_runs, real_price_path, time_increment): @@ -86,3 +81,21 @@ def get_interval_steps(scoring_interval, time_increment): # Return the sum of all scores return sum_all_scores, detailed_crps_data + + +def calculate_price_changes_over_intervals(price_paths, interval_steps): + """ + Calculate price changes over specified intervals. + + Parameters: + price_paths (numpy.ndarray): Array of simulated price paths. + interval_steps (int): Number of steps that make up the interval. + + Returns: + numpy.ndarray: Array of price changes over intervals. + """ + # Get the prices at the interval points + interval_prices = price_paths[:, ::interval_steps] + # Calculate price changes over intervals + price_changes = np.diff(interval_prices, axis=1) + return price_changes diff --git a/tests/test_generate_simulation.py b/tests/test_generate_simulation.py deleted file mode 100644 index f61ba40e..00000000 --- a/tests/test_generate_simulation.py +++ /dev/null @@ -1,19 +0,0 @@ -import unittest -from datetime import datetime - -from simulation.miner import generate_simulations - - -class TestGenerateSimulation(unittest.TestCase): - def setUp(self): - pass - - def tearDown(self): - pass - - def test_generate_simulation(self): - prediction_result = generate_simulations( - start_time=datetime.now().isoformat() - ) - - print(prediction_result) diff --git a/tests/test_price_simulation.py b/tests/test_price_simulation.py deleted file mode 100644 index fb3ab1ec..00000000 --- a/tests/test_price_simulation.py +++ /dev/null @@ -1,45 +0,0 @@ -import unittest -import numpy as np - -from simulation.simulations.price_simulation import simulate_crypto_price_paths - - -class TestPriceSimulation(unittest.TestCase): - def setUp(self): - pass - - def tearDown(self): - pass - - def test_simulate_crypto_price_paths(self): - # Simulation parameters - current_price = 100.0 - time_increment = 300 # 5 minutes - time_length = 1800 # 30 min - num_simulations = 1 - - # Real price path sigma - sigma_real = 0.01 - - price_paths = simulate_crypto_price_paths( - current_price, - time_increment, - time_length, - num_simulations, - sigma_real, - ) - - # Test the shape of the result - self.assertEqual( - price_paths.shape, - (num_simulations, time_length / time_increment + 1), - ) - - # Test that all values are finite (no NaN or Inf values) - self.assertTrue(np.all(np.isfinite(price_paths))) - - # Check that the initial price in each path matches the given current price - for path in price_paths: - self.assertAlmostEqual(path[0], current_price, delta=1e-6) - - # Additional property tests can go here (e.g., variance checks based on sigma)