Contoh lain syntax highlighter
import numpy as np import matplotlib.pyplot as plt np.random.seed(42) harga_beras = np.random.normal(loc=10, scale=2, size=100) def monte_carlo_forecast(data, n_simulasi=1000, n_bulan=12): hasil_simulasi = [] rata_rata = np.mean(data) std_deviasi = np.std(data) for _ in range(n_simulasi): prediksi_bulan = [] harga_terakhir = data[-1] for _ in range(n_bulan): perubahan = np.random.normal(0, std_deviasi) harga_baru = harga_terakhir + perubahan prediksi_bulan.append(harga_baru) harga_terakhir = harga_baru hasil_simulasi.append(prediksi_bulan) hasil_simulasi = np.array(hasil_simulasi) return hasil_simulasi