Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions miner-dummy.local.config.js

This file was deleted.

25 changes: 9 additions & 16 deletions neurons/miner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -214,4 +207,4 @@ def print_info(self):
with Miner() as miner:
while True:
miner.print_info()
time.sleep(15)
time.sleep(5)
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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
):
Expand All @@ -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
43 changes: 4 additions & 39 deletions simulation/miner.py → simulation/miner/simulations.py
Original file line number Diff line number Diff line change
@@ -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,
)


Expand All @@ -15,7 +13,6 @@ def generate_simulations(
time_increment=300,
time_length=86400,
num_simulations=1,
sigma=0.01,
):
"""
Generate simulated price paths.
Expand All @@ -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.
Expand All @@ -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,
Expand All @@ -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
23 changes: 18 additions & 5 deletions simulation/validator/crps_calculation.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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
19 changes: 0 additions & 19 deletions tests/test_generate_simulation.py

This file was deleted.

45 changes: 0 additions & 45 deletions tests/test_price_simulation.py

This file was deleted.

Loading