User Tools

Site Tools


compare_strategies_w_graph_3d

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
compare_strategies_w_graph_3d [2025/03/02 23:27] brunocompare_strategies_w_graph_3d [2025/03/14 11:20] (current) bruno
Line 7: Line 7:
 # https://www.geeksforgeeks.org/plot-single-3d-point-on-top-of-plot_surface-in-python-matplotlib/ # https://www.geeksforgeeks.org/plot-single-3d-point-on-top-of-plot_surface-in-python-matplotlib/
  
-import pandas as pd 
- 
-#df = kbt_init('XXBTZEUR',1440) 
-df = pd.read_csv('XXBTZEUR_1440.csv') 
-#df = df[int(-3*365):] 
- 
-def fct (df, slow, fast): 
-    df['slow'] = ta.EMA(df.close, timeperiod=slow) 
-    df['fast'] = ta.EMA(df.close, timeperiod=fast) 
-    df['position'] = df.slow < df.fast 
-    df = kbt_compute(df) 
-    return df['R_net'].iloc[-1] 
- 
-SLOW = np.arange(5, 500, 5) 
-FAST = np.arange(5, 500, 5) 
-SLOW, FAST = np.meshgrid(SLOW, FAST) 
-Z = np.zeros_like(SLOW) 
-# https://blog.finxter.com/applying-functions-to-python-meshgrid-5-effective-techniques/ 
-for i in range(SLOW.shape[0]): 
-    for j in range(SLOW.shape[1]): 
-        Z[i, j] = fct (df, SLOW[i, j], FAST[i, j]) 
-        print(f"{SLOW[i,j]}, {FAST[i,j]} -> {Z[i,j]}                 ",end="\r") 
- 
-import matplotlib.pyplot as plt 
-from matplotlib import cm 
-from mpl_toolkits.mplot3d import axes3d 
- 
-fig = plt.figure() 
-ax = fig.add_subplot(projection='3d') 
- 
- 
-               
-# Plot a basic wireframe. 
-ax.plot_surface(SLOW, FAST, Z, cmap=cm.coolwarm) 
- 
-ax.view_init(elev=20, azim=115, roll=0) 
- 
-ax.set_xlabel('SLOW') 
-ax.set_ylabel('FAST') 
-ax.set_zlabel('Z') 
-ax.set_title('Single Point in 3D') 
- 
-# https://numpy.org/doc/stable/reference/generated/numpy.argmax.html#numpy.argmax 
-ind = np.unravel_index(np.argmax(Z, axis=None), Z.shape) 
-print(ind, SLOW[ind], FAST[ind], Z[ind]) 
- 
-plt.show() 
-</code> 
- 
-<code python> 
 import numpy as np import numpy as np
 import pandas as pd import pandas as pd
 import talib as ta import talib as ta
-  + 
-#df = pd.read_csv('https://raw.githubusercontent.com/brulint/backtesting/main/btceur-2h.csv') +Donwload data 
-df = pd.read_csv('http://lintermans.all2all.org/cgi-bin/get-chart.php?chart=XXBTZEUR_1440.csv')+https://support.kraken.com/hc/en-us/articles/360047124832 
 +df = pd.read_csv('XBTEUR_1440.csv', names=['time', 'open', 'high', 'low', 'close', 'volume', 'count']
 df = df[int(-10.5*365):] df = df[int(-10.5*365):]
 df['close'] = df.close.replace(to_replace=0, method='ffill') df['close'] = df.close.replace(to_replace=0, method='ffill')
Line 75: Line 26:
     df['r_net'] = df['r_strat'] - df['r_fee']     df['r_net'] = df['r_strat'] - df['r_fee']
     df['R_net'] = df['r_net'].cumsum()     df['R_net'] = df['r_net'].cumsum()
-    print(df['R_net'].iloc[-1]) +    return np.exp(df['R_net'].iloc[-1])-1
-    return df['R_net'].iloc[-1]+
  
 def fct2 (df, slow, fast): def fct2 (df, slow, fast):
compare_strategies_w_graph_3d.1740958079.txt.gz · Last modified: 2025/03/02 23:27 by bruno