import numpy as np import matplotlib.pyplot as plt import yfinance as yf from datetime import date, timedelta samsung = yf.download('005930.KS', start=date.today()-timedelta(10*365)) y = samsung['Adj Close'].values plt.figure(figsize=(10,6), dpi=100) plt.plot(samsung.index, y) plt.grid(True) plt.xlabel('Date') plt.ylabel('Adjusted close price') plt.title('Samsung Electronics Co., Ltd. (005930.KS)') plt.show() N = len(y) window = [7, 30, 90, 180] k = len(window) x = np.zeros((k,N)) for i in range(k): n = window[i] for j in range(N): start = max(0,j-n+1) data = y[start:j+1] n_data = len(data) #print(start, j, n_data, data) x[i,j] = np.sum(data)/n_data plt.figure(figsize=(10,6), dpi=100) plt.plot(y, alpha=0.4, label='Samsung Electronics') for i in range(k): plt.plot(x[i,:], label=f'Moving average with n={window[i]}') plt.grid() plt.xlabel('Date') plt.ylabel('Adjusted close price') plt.title('Samsung Electronics Co., Ltd. (005930.KS)') plt.legend() plt.show() import numpy as np import matplotlib.pyplot as plt # Generate some sample gravity data num_points = 50 np.random.seed(3001) x = np.random.rand(num_points) y = np.random.rand(num_points) gravity_values = np.sin(2*np.pi*x) + np.cos(2*np.pi*y) \ + np.random.randn(num_points)*0.1 # Plot the results plt.figure(figsize=(8, 6), dpi=100) plt.scatter(x, y, c=gravity_values, label='Gravity Measurements') plt.colorbar(label='Gravity Anomaly') plt.xlabel('X') plt.ylabel('Y') plt.title('Gravity Anomaly Interpolation using IDW') plt.legend() plt.grid() plt.show() # Define the interpolation grid grid_x, grid_y = np.mgrid[0:1:100j, 0:1:100j] # Perform IDW interpolation interpolated_gravity = np.zeros_like(grid_x) for i in range(grid_x.shape[0]): for j in range(grid_x.shape[1]): distances = np.sqrt((grid_x[i, j] - x)**2 + (grid_y[i, j] - y)**2) weights = 1 / distances**2 # Inverse distance squared weighting interpolated_gravity[i, j] = np.sum(gravity_values * weights) / np.sum(weights) #interpolated_gravity[i, j] = np.sin(2*np.pi*grid_x[i,j]) + np.cos(2*np.pi*grid_y[i,j]) # Plot the results plt.figure(figsize=(8, 6), dpi=100) plt.scatter(x, y, c=gravity_values, label='Gravity Measurements') plt.contourf(grid_x, grid_y, interpolated_gravity, alpha=0.7) plt.colorbar(label='Gravity Anomaly') plt.xlabel('X') plt.ylabel('Y') plt.title('Gravity Anomaly Interpolation using IDW') plt.legend() plt.grid() plt.show()