Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
freem
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Openai/693eaf5a-1494-8007-b1e3-00abefb11523
(section)
Add languages
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Assistant: It seems like I can’t do more advanced data analysis right now. === It seems like I can’t do more advanced data analysis right now. Please try again later. I wasn’t able to run the analysis and create the plots inside this session, but I’ll give you a complete, ready-to-run Python script (and precise instructions) that performs everything you asked for: * backtests the series, * creates the triangle/tetrahedron per day (origin, day, price; orthogonal distance → half-height), * computes volumetric and related geometric indicators, * computes simple Bayesian/posterior statistics by indicator bins, * fits a single-feature logistic for each indicator and reports AUC / correlation / lift, * produces the plots you requested (price series, tetrahedron example, indicator timeseries, posterior-by-quartile, ROC curves), * and prints a ranked summary of which indicators were best. Copy–paste the script below into a local Python environment / Jupyter notebook and run it. I included comments and explanations so you can tweak any detail (window sizes, binning, indicator choices). <syntaxhighlight lang="python">""" Tetrahedral volumetric indicators + Bayesian/backtest analysis Run locally (Python 3.8+). Required packages: numpy, pandas, matplotlib, scikit-learn. Saves plots to disk and prints a summary table ranking indicators by AUC. Author: ChatGPT (script for user) """ import numpy as np import pandas as pd import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D from sklearn.linear_model import LogisticRegression from sklearn.metrics import roc_auc_score, roc_curve, roc_auc_score import os === === PARAMETERS === === OUTDIR = "tetra_analysis_outputs" os.makedirs(OUTDIR, exist_ok=True) === Use the same synthetic data seed as earlier examples (to reproduce) === np.random.seed(42) === Generate daily dates for a year === dates = pd.date_range(start="2025-01-01", end="2025-12-31", freq="D") n = len(dates) === Example price series (random uniform), replace with your actual series if available === prices = np.random.uniform(50, 150, n) === Numeric time axis: days since start (1..365) === d_numeric = np.array([d.timetuple().tm_yday for d in dates], dtype=float) === Build DataFrame === df = pd.DataFrame({ "date": dates, "price": prices, "d": d_numeric }) === --- Geometric construction per-day --- === === Points in 2D for triangle: O=(0,0), A=(d,0), B=(0,p) === x1 = df["d"].values # A.x = d y1 = np.zeros(n) # A.y = 0 x2 = np.zeros(n) # B.x = 0 y2 = df["price"].values # B.y = p === Hypotenuse length between A and B (2D) === hyp_len = np.sqrt((x1 - x2)'''2 + (y1 - y2)'''2) === Distance from origin to line AB (2D) === === determinant numerator simplifies to x1''y2 - y1''x2 -> x1*y2 === num = np.abs(x1 '' y2 - y1 '' x2) # = x1*y2 den = np.sqrt((y2 - y1)'''2 + (x2 - x1)'''2) dist_origin_to_line = num / den === Per user: "Sending half the distance of an orthogonal from the origin to the hypotenuse" === h = dist_origin_to_line / 2.0 === 3D tetrahedron apex D = (d, p, h) === A = np.column_stack((x1, y1, np.zeros(n))) B = np.column_stack((x2, y2, np.zeros(n))) D = np.column_stack((x1, y2, h)) === Compute tetrahedron volume: V = |det([A, B, D])| / 6 === volumes = np.zeros(n) for i in range(n): M = np.vstack((A[i], B[i], D[i])).T # 3x3 matrix whose columns are A,B,D volumes[i] = abs(np.linalg.det(M)) / 6.0 === Triangle area (2D): area = |x1''y2 - x2''y1|/2 = x1*y2/2 === tri_area = (x1 * y2) / 2.0 === Additional indicator: rolling volatility of returns (10-day) === returns = np.concatenate([[0.0], np.diff(df["price"].values) / df["price"].values[:-1]]) vol10 = pd.Series(returns).rolling(window=10, min_periods=1).std().values === Put indicators into df === df["hyp_len"] = hyp_len df["dist_origin_to_line"] = dist_origin_to_line df["h"] = h df["tetra_vol"] = volumes df["tri_area"] = tri_area df["ret"] = returns df["vol10"] = vol10 === Target: next-day increase === df["next_price"] = df["price"].shift(-1) df["up_next"] = (df["next_price"] > df["price"]).astype(int) df = df.iloc[:-1].copy() # drop last day (no target) === Indicators to evaluate === indicators = ["tetra_vol", "h", "hyp_len", "tri_area", "vol10"] === Helper to fit single-feature logistic and compute AUC === def evaluate_indicator(feature_array, target_array): X = feature_array.reshape(-1,1) y = target_array # If constant feature, return nans if np.allclose(X, X.mean()): return {"auc": np.nan, "corr": np.nan, "fpr": None, "tpr": None} clf = LogisticRegression(solver="liblinear") clf.fit(X, y) probs = clf.predict_proba(X)[:,1] try: auc = roc_auc_score(y, probs) fpr, tpr, _ = roc_curve(y, probs) except Exception: auc = np.nan fpr, tpr = None, None corr = np.corrcoef(feature_array, y)[0,1] return {"auc": auc, "corr": corr, "fpr": fpr, "tpr": tpr, "probs": probs} === Evaluate all indicators === results = [] roc_curves = {} for ind in indicators: res = evaluate_indicator(df[ind].values, df["up_next"].values) # Bayesian posterior by quartile try: df["quartile"] = pd.qcut(df[ind], 4, labels=False, duplicates="drop") post = df.groupby("quartile")["up_next"].mean() except Exception: post = None prior = df["up_next"].mean() max_post = post.max() if post is not None else np.nan max_lift = max_post - prior if post is not None else np.nan results.append({ "indicator": ind, "auc": res["auc"], "corr_with_up": res["corr"], "prior_p_up": prior, "max_quartile_post_p_up": max_post, "max_lift_over_prior": max_lift }) roc_curves[ind] = (res["fpr"], res["tpr"]) res_df = pd.DataFrame(results).sort_values(by="auc", ascending=False) === Print ranking table === print("\nIndicator ranking (by AUC):") print(res_df.to_string(index=False, float_format=lambda x: f"{x:.4f}")) === ========== PLOTTING ========== === === Plot 1: Price series === plt.figure(figsize=(12,4)) plt.plot(df["date"], df["price"]) plt.xlabel("Date") plt.ylabel("Price") plt.title("Price series") plt.xticks(rotation=45) plt.tight_layout() plt.savefig(os.path.join(OUTDIR, "price_series.png")) plt.show() === Plot 2: Example tetrahedron for the final point in df === i = -1 p = df["price"].iloc[i] d = df["d"].iloc[i] h_i = df["h"].iloc[i] O = np.array([0,0,0]) A_i = np.array([d,0,0]) B_i = np.array([0,p,0]) D_i = np.array([d,p,h_i]) fig = plt.figure(figsize=(8,6)) ax = fig.add_subplot(111, projection='3d') === Edges === ax.plot([O[0],A_i[0]],[O[1],A_i[1]],[O[2],A_i[2]]) ax.plot([O[0],B_i[0]],[O[1],B_i[1]],[O[2],B_i[2]]) ax.plot([O[0],D_i[0]],[O[1],D_i[1]],[O[2],D_i[2]]) ax.plot([A_i[0],B_i[0]],[A_i[1],B_i[1]],[A_i[2],B_i[2]]) ax.plot([A_i[0],D_i[0]],[A_i[1],D_i[1]],[A_i[2],D_i[2]]) ax.plot([B_i[0],D_i[0]],[B_i[1],D_i[1]],[B_i[2],D_i[2]]) ax.scatter([O[0],A_i[0],B_i[0],D_i[0]],[O[1],A_i[1],B_i[1],D_i[1]],[O[2],A_i[2],B_i[2],D_i[2]]) ax.set_xlabel("Day-of-year") ax.set_ylabel("Price") ax.set_zlabel("Height h") ax.set_title("Tetrahedron for final point") plt.tight_layout() plt.savefig(os.path.join(OUTDIR, "example_tetrahedron.png")) plt.show() === Plot 3: Tetrahedral volume over time === plt.figure(figsize=(12,4)) plt.plot(df["date"], df["tetra_vol"]) plt.xlabel("Date") plt.ylabel("Tetrahedron volume") plt.title("Tetrahedral Volume Over Time") plt.xticks(rotation=45) plt.tight_layout() plt.savefig(os.path.join(OUTDIR, "tetra_vol_time.png")) plt.show() === Plot 4: Height h over time === plt.figure(figsize=(12,4)) plt.plot(df["date"], df["h"]) plt.xlabel("Date") plt.ylabel("h (half orthogonal distance)") plt.title("Tetrahedral Height (h) Over Time") plt.xticks(rotation=45) plt.tight_layout() plt.savefig(os.path.join(OUTDIR, "h_time.png")) plt.show() === Plot 5: Posterior P(up next) by quartile for the top two indicators (by AUC) === top_two = res_df["indicator"].tolist()[:2] for ind in top_two: try: df["quartile"] = pd.qcut(df[ind], 4, labels=False, duplicates="drop") post = df.groupby("quartile")["up_next"].mean() plt.figure(figsize=(6,4)) plt.plot(post.index.astype(float)+1, post.values, marker='o') plt.xlabel("Quartile (1=lowest -> 4=highest)") plt.ylabel("P(next-day up)") plt.title(f"P(next-day up) by {ind} quartile") plt.tight_layout() plt.savefig(os.path.join(OUTDIR, f"posterior_by_quartile_{ind}.png")) plt.show() except Exception as e: print("Could not compute quartiles for", ind, ":", e) === Plot 6: ROC curves for all indicators === plt.figure(figsize=(8,6)) for ind in indicators: fpr_tpr = roc_curves.get(ind, (None,None)) fpr, tpr = fpr_tpr if fpr is None or tpr is None: continue plt.plot(fpr, tpr, label=f"{ind} (AUC={res_df.loc[res_df.indicator==ind,'auc'].values[0]:.3f})") plt.plot([0,1],[0,1], linestyle='--') plt.xlabel("False positive rate") plt.ylabel("True positive rate") plt.title("ROC curves (single-feature logistic models)") plt.legend() plt.tight_layout() plt.savefig(os.path.join(OUTDIR, "roc_curves.png")) plt.show() print("\nSaved plots to:", OUTDIR) </syntaxhighlight> ===== 1. Geometric indicators - tetra_vol: the volume of the 3D tetrahedron formed by O, A=(day,0), B=(0,price) and apex D=(day, price, h) where h = (perpendicular distance from O to hypotenuse)/2. - h: half the orthogonal distance from O to the triangle’s hypotenuse (as you specified). - hyp_len: the 2D hypotenuse length between A and B. - tri_area: area of the triangle O-A-B. - vol10: rolling volatility (baseline non-geometric comparator). ===== # Predictive evaluation - For each indicator, the script fits a single-feature logistic regression that predicts up_next (1 if next day price is higher). - It reports correlation with the up_next binary, AUC (how well the indicator ranks the days by future up probability), and quartile-based Bayesian posterior probabilities (P(up_next | indicator quartile)). - The table printed at the top ranks indicators by AUC. Indicators with higher AUC and positive correlation are better single-feature predictors of next-day increases. # Bayesian / posterior lift - The posterior_by_quartile plots show empirical posterior probabilities for each quartile of the indicator value; compare these to the prior probability (overall fraction of days that go up). A strong indicator will show monotonic posteriors and some quartiles with significantly higher posterior than the prior. # Visual outputs - price_series.png: the price series itself. - example_tetrahedron.png: 3D view of one constructed tetrahedron (final day). - tetra_vol_time.png and h_time.png: indicator time series. - posterior_by_quartile_*.png: posterior vs quartile for top indicators. - roc_curves.png: ROC for each indicator. ===== - Primary ranking: AUC from single-feature logistic. (AUC near 0.5 is random; >0.6 modest; >0.7 decent.) ===== * Secondary checks: - Positive correlation with next-day up (more robust if stable across time). - Max lift over prior in quartiles (how much better the best quartile is vs prior). - Consistency across rolling windows (you can extend the script to perform walk-forward validation and re-evaluate AUC in each fold — recommended for real data). ===== I tried to run the plots for you but the environment couldn’t execute advanced data analysis in this session. If you want, I can re-run these exact steps and produce plots inside this conversation when the environment becomes available — tell me “run the analysis now” and I’ll attempt it. (If you prefer, run the script locally — it will run in any standard Python environment.) ===== ===== - If you have real price data, replace the synthetic prices array with your series (same index length as dates or adjust dates accordingly). ===== * Add more features to test (e.g., moving-average gaps, momentum, volume if available). * Use walk-forward retraining to avoid look-ahead and better estimate real-world performance. * If tetrahedral volume is predictive on your data, consider combining it in a small ensemble with volatility and momentum for improved stability. Would you like: * A tighter script that performs walk-forward cross-validation and reports time-varying AUCs? * Or do you want me to re-run this analysis now (I’ll try again to execute and produce the actual plots for you)?
Summary:
Please note that all contributions to freem are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 (see
Freem:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)