fork download
  1. import pandas as pd
  2. import numpy as np
  3.  
  4. # Sample data: past performance simulation
  5. data = {
  6. 'Date': pd.date_range(start='1/1/2023', periods=100, freq='D'),
  7. 'Close': np.random.uniform(low=1.1000, high=1.1500, size=100)
  8. }
  9. df = pd.DataFrame(data)
  10.  
  11. # Gann Angle Calculation
  12. def calculate_gann_angle(close_prices, angle_degree=45):
  13. angle_radian = np.radians(angle_degree)
  14. return close_prices * np.tan(angle_radian)
  15.  
  16. # Simple Gann Strategy Simulation
  17. df['GannAngle'] = calculate_gann_angle(df['Close'])
  18. df['Signal'] = np.where(df['Close'] > df['Close'].shift(1) + df['GannAngle'], 'Buy',
  19. np.where(df['Close'] < df['Close'].shift(1) - df['GannAngle'], 'Sell', 'Hold'))
  20.  
  21. # Output the signals
  22. print(df[['Date', 'Close', 'GannAngle', 'Signal']])
Success #stdin #stdout 0.75s 63604KB
stdin
Standard input is empty
stdout
         Date     Close  GannAngle Signal
0  2023-01-01  1.102519   1.102519   Hold
1  2023-01-02  1.135049   1.135049   Hold
2  2023-01-03  1.112496   1.112496   Hold
3  2023-01-04  1.113738   1.113738   Hold
4  2023-01-05  1.137158   1.137158   Hold
5  2023-01-06  1.149175   1.149175   Hold
6  2023-01-07  1.141012   1.141012   Hold
7  2023-01-08  1.101822   1.101822   Hold
8  2023-01-09  1.113642   1.113642   Hold
9  2023-01-10  1.133194   1.133194   Hold
10 2023-01-11  1.133754   1.133754   Hold
11 2023-01-12  1.100103   1.100103   Hold
12 2023-01-13  1.122383   1.122383   Hold
13 2023-01-14  1.127982   1.127982   Hold
14 2023-01-15  1.149273   1.149273   Hold
15 2023-01-16  1.107471   1.107471   Hold
16 2023-01-17  1.145371   1.145371   Hold
17 2023-01-18  1.131408   1.131408   Hold
18 2023-01-19  1.123457   1.123457   Hold
19 2023-01-20  1.129528   1.129528   Hold
20 2023-01-21  1.124774   1.124774   Hold
21 2023-01-22  1.122875   1.122875   Hold
22 2023-01-23  1.149783   1.149783   Hold
23 2023-01-24  1.122448   1.122448   Hold
24 2023-01-25  1.121718   1.121718   Hold
25 2023-01-26  1.125236   1.125236   Hold
26 2023-01-27  1.107724   1.107724   Hold
27 2023-01-28  1.140354   1.140354   Hold
28 2023-01-29  1.126551   1.126551   Hold
29 2023-01-30  1.118339   1.118339   Hold
..        ...       ...        ...    ...
70 2023-03-12  1.115287   1.115287   Hold
71 2023-03-13  1.108087   1.108087   Hold
72 2023-03-14  1.116675   1.116675   Hold
73 2023-03-15  1.127498   1.127498   Hold
74 2023-03-16  1.115360   1.115360   Hold
75 2023-03-17  1.115641   1.115641   Hold
76 2023-03-18  1.100301   1.100301   Hold
77 2023-03-19  1.139522   1.139522   Hold
78 2023-03-20  1.148346   1.148346   Hold
79 2023-03-21  1.123028   1.123028   Hold
80 2023-03-22  1.143023   1.143023   Hold
81 2023-03-23  1.108078   1.108078   Hold
82 2023-03-24  1.100009   1.100009   Hold
83 2023-03-25  1.112911   1.112911   Hold
84 2023-03-26  1.149426   1.149426   Hold
85 2023-03-27  1.137376   1.137376   Hold
86 2023-03-28  1.146398   1.146398   Hold
87 2023-03-29  1.134064   1.134064   Hold
88 2023-03-30  1.104519   1.104519   Hold
89 2023-03-31  1.104512   1.104512   Hold
90 2023-04-01  1.128307   1.128307   Hold
91 2023-04-02  1.141842   1.141842   Hold
92 2023-04-03  1.132741   1.132741   Hold
93 2023-04-04  1.136284   1.136284   Hold
94 2023-04-05  1.134486   1.134486   Hold
95 2023-04-06  1.114850   1.114850   Hold
96 2023-04-07  1.136086   1.136086   Hold
97 2023-04-08  1.147429   1.147429   Hold
98 2023-04-09  1.121908   1.121908   Hold
99 2023-04-10  1.103439   1.103439   Hold

[100 rows x 4 columns]