| | import pandas as pd |
| | import numpy as np |
| | import openpyxl |
| | from openpyxl.utils.dataframe import dataframe_to_rows |
| | from openpyxl.styles import Font |
| |
|
| | |
| | sample_data = { |
| | "Timestamp": pd.date_range(start="2024-01-01", periods=10, freq="T"), |
| | "Open": np.random.uniform(30000, 40000, 10), |
| | "High": np.random.uniform(30000, 40000, 10), |
| | "Low": np.random.uniform(30000, 40000, 10), |
| | "Close": np.random.uniform(30000, 40000, 10), |
| | "Volume": np.random.uniform(100, 500, 10) |
| | } |
| |
|
| | |
| | df_raw_data = pd.DataFrame(sample_data) |
| |
|
| | |
| | sma_period = 5 |
| | ema_period = 5 |
| | df_raw_data['SMA'] = df_raw_data['Close'].rolling(window=sma_period).mean() |
| | df_raw_data['EMA'] = df_raw_data['Close'].ewm(span=ema_period, adjust=False).mean() |
| |
|
| | |
| | wb = openpyxl.Workbook() |
| | wb.remove(wb.active) |
| |
|
| | |
| | ws_raw = wb.create_sheet("Raw Data") |
| | for r in dataframe_to_rows(df_raw_data, index=False, header=True): |
| | ws_raw.append(r) |
| |
|
| | |
| | ws_feature = wb.create_sheet("Feature Engineering") |
| | ws_feature["A1"].value = "Adjustable SMA and EMA" |
| | ws_feature["A1"].font = Font(bold=True) |
| | ws_feature["A2"].value = "SMA Period:" |
| | ws_feature["B2"].value = sma_period |
| | ws_feature["A3"].value = "EMA Period:" |
| | ws_feature["B3"].value = ema_period |
| |
|
| | |
| | ws_feature["D2"].value = "Close Price" |
| | ws_feature["E2"].value = "SMA (Dynamic)" |
| | ws_feature["F2"].value = "EMA (Dynamic)" |
| |
|
| | |
| | for i in range(3, len(df_raw_data) + 3): |
| | ws_feature[f"D{i}"] = f"=Raw Data!E{i}" |
| | ws_feature[f"E{i}"] = f"=AVERAGE(OFFSET(D{i}-$B$2+1,0,0,$B$2,1))" |
| | ws_feature[f"F{i}"] = f"=EXPONENTIALMOVINGAVERAGE(D{i}, $B$3)" |
| |
|
| | |
| | ws_synthetic = wb.create_sheet("Synthetic Relationships") |
| | ws_synthetic["A1"].value = "Synthetic Relationships - Parameter Adjustments" |
| | ws_synthetic["A1"].font = Font(bold=True) |
| |
|
| | |
| | ws_synthetic.append(["Query Date", "Found Close Price", "Adjusted SMA", "Adjusted EMA"]) |
| | for i in range(3, len(df_raw_data) + 3): |
| | ws_synthetic[f"A{i}"] = ws_raw[f"A{i}"].value |
| | ws_synthetic[f"B{i}"] = f"=Raw Data!E{i}" |
| | ws_synthetic[f"C{i}"] = f"=Feature Engineering!E{i}" |
| | ws_synthetic[f"D{i}"] = f"=Feature Engineering!F{i}" |
| |
|
| | |
| | file_path = "ActiveGraphTheory.xlsx" |
| | wb.save(file_path) |
| |
|
| | file_path |
| |
|