virgo-modules 0.0.80__tar.gz → 0.0.82__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of virgo-modules might be problematic. Click here for more details.
- {virgo_modules-0.0.80 → virgo_modules-0.0.82}/PKG-INFO +1 -1
- {virgo_modules-0.0.80 → virgo_modules-0.0.82}/setup.py +1 -1
- {virgo_modules-0.0.80 → virgo_modules-0.0.82}/virgo_app/virgo_modules/src/re_utils.py +1 -1
- {virgo_modules-0.0.80 → virgo_modules-0.0.82}/virgo_app/virgo_modules/src/ticketer_source.py +45 -21
- {virgo_modules-0.0.80 → virgo_modules-0.0.82}/virgo_app/virgo_modules.egg-info/PKG-INFO +1 -1
- {virgo_modules-0.0.80 → virgo_modules-0.0.82}/LICENSE +0 -0
- {virgo_modules-0.0.80 → virgo_modules-0.0.82}/README.md +0 -0
- {virgo_modules-0.0.80 → virgo_modules-0.0.82}/setup.cfg +0 -0
- {virgo_modules-0.0.80 → virgo_modules-0.0.82}/virgo_app/virgo_modules/__init__.py +0 -0
- {virgo_modules-0.0.80 → virgo_modules-0.0.82}/virgo_app/virgo_modules/src/__init__.py +0 -0
- {virgo_modules-0.0.80 → virgo_modules-0.0.82}/virgo_app/virgo_modules/src/aws_utils.py +0 -0
- {virgo_modules-0.0.80 → virgo_modules-0.0.82}/virgo_app/virgo_modules/src/edge_utils.py +0 -0
- {virgo_modules-0.0.80 → virgo_modules-0.0.82}/virgo_app/virgo_modules/src/pull_artifacts.py +0 -0
- {virgo_modules-0.0.80 → virgo_modules-0.0.82}/virgo_app/virgo_modules.egg-info/SOURCES.txt +0 -0
- {virgo_modules-0.0.80 → virgo_modules-0.0.82}/virgo_app/virgo_modules.egg-info/dependency_links.txt +0 -0
- {virgo_modules-0.0.80 → virgo_modules-0.0.82}/virgo_app/virgo_modules.egg-info/requires.txt +0 -0
- {virgo_modules-0.0.80 → virgo_modules-0.0.82}/virgo_app/virgo_modules.egg-info/top_level.txt +0 -0
|
@@ -5,7 +5,7 @@ with open("virgo_app/README.md", "r") as f:
|
|
|
5
5
|
|
|
6
6
|
setup(
|
|
7
7
|
name="virgo_modules",
|
|
8
|
-
version="0.0.
|
|
8
|
+
version="0.0.82",
|
|
9
9
|
description="data processing and statistical modeling using stock market data",
|
|
10
10
|
package_dir={"": "virgo_app"},
|
|
11
11
|
packages=find_packages(where="virgo_app"),
|
|
@@ -453,7 +453,7 @@ def ranking(data, weighted_features, top = 5, window = 5):
|
|
|
453
453
|
top_up = list(df.sort_values('up_signas', ascending = False).index)[:top]
|
|
454
454
|
top_low = list(df.sort_values('low_signas', ascending = False).index)[:top]
|
|
455
455
|
|
|
456
|
-
return top_up, top_low
|
|
456
|
+
return top_up, top_low, df
|
|
457
457
|
|
|
458
458
|
def ranking_first(data, weighted_features, top = 5, window = 5):
|
|
459
459
|
'''
|
{virgo_modules-0.0.80 → virgo_modules-0.0.82}/virgo_app/virgo_modules/src/ticketer_source.py
RENAMED
|
@@ -2704,7 +2704,7 @@ class signal_analyser_object:
|
|
|
2704
2704
|
days_list (list): list of integers [3,8,10] to assess
|
|
2705
2705
|
threshold (float): alpha or z threshold
|
|
2706
2706
|
verbose (boolean): print metrics
|
|
2707
|
-
signal_position (int): if true, the signal is taken at the given step
|
|
2707
|
+
signal_position (int): if true, the signal is taken at the given step after the signal end
|
|
2708
2708
|
|
|
2709
2709
|
Returns
|
|
2710
2710
|
-------
|
|
@@ -2721,6 +2721,7 @@ class signal_analyser_object:
|
|
|
2721
2721
|
for days in days_list:
|
|
2722
2722
|
|
|
2723
2723
|
feature_ = f'return_{days}d'
|
|
2724
|
+
days = days + signal_position if signal_position else days
|
|
2724
2725
|
df[feature_] = (df['Close'].shift(-days)/df['Close']-1)*100
|
|
2725
2726
|
returns_list.append(feature_)
|
|
2726
2727
|
|
|
@@ -2758,9 +2759,16 @@ class signal_analyser_object:
|
|
|
2758
2759
|
p_scores = list()
|
|
2759
2760
|
medians_down = list()
|
|
2760
2761
|
validations = list()
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2762
|
+
|
|
2763
|
+
if signal_position:
|
|
2764
|
+
df['open_long'] = np.where(df.last_in_chain == True, True, np.nan)
|
|
2765
|
+
df['open_long'] = df['open_long'].shift(signal_position)
|
|
2766
|
+
else:
|
|
2767
|
+
df['open_long'] = np.where(df.last_in_chain == True, True, np.nan)
|
|
2768
|
+
|
|
2769
|
+
# df_melt = df[df.last_in_chain == True].melt(id_vars=['signal_type'], value_vars=returns_list, var_name='time', value_name='value')
|
|
2770
|
+
df_melt = df[df.open_long == True].melt(id_vars=['signal_type'], value_vars=returns_list, var_name='time', value_name='value')
|
|
2771
|
+
df_melt = df_melt.dropna()
|
|
2764
2772
|
|
|
2765
2773
|
for evalx in returns_list:
|
|
2766
2774
|
|
|
@@ -2794,7 +2802,7 @@ class signal_analyser_object:
|
|
|
2794
2802
|
self.mean_median_return = np.nan
|
|
2795
2803
|
|
|
2796
2804
|
df2 = df.copy()
|
|
2797
|
-
df2 = df2[df2.
|
|
2805
|
+
df2 = df2[df2.open_long == True]
|
|
2798
2806
|
|
|
2799
2807
|
|
|
2800
2808
|
df2['lagdate'] = df2.Date.shift(1)
|
|
@@ -2802,12 +2810,17 @@ class signal_analyser_object:
|
|
|
2802
2810
|
|
|
2803
2811
|
fig, axs = plt.subplots(1, 3, figsize = (15,5))
|
|
2804
2812
|
|
|
2805
|
-
sns.
|
|
2813
|
+
sns.violinplot(data=df2, y="span",ax = axs[0], color = 'lightblue', linewidth=0.7,inner="quart")
|
|
2814
|
+
sns.stripplot(data=df2, y="span",ax = axs[0], jitter=True, zorder=1)
|
|
2806
2815
|
axs[0].set_title('span between last signals')
|
|
2807
2816
|
del df2
|
|
2808
|
-
sns.
|
|
2817
|
+
sns.violinplot(data=df[df.last_in_chain == True], y="internal_rn",ax = axs[1], color = 'lightblue', linewidth=0.7,inner="quart")
|
|
2818
|
+
sns.stripplot(data=df[df.last_in_chain == True], y="internal_rn",ax = axs[1], jitter=True, zorder=1)
|
|
2809
2819
|
axs[1].set_title('signal duration distribution')
|
|
2810
|
-
|
|
2820
|
+
|
|
2821
|
+
palette ={"go down": "tomato", "go up": "lightblue"}
|
|
2822
|
+
df_melt.signal_type = df_melt.signal_type.map({'up':'go down', 'down': 'go up'})
|
|
2823
|
+
sns.violinplot(data=df_melt, x="time", y="value", hue="signal_type",ax = axs[2], split=True, gap=0.1, inner="quart",palette = palette, linewidth=0.8)
|
|
2811
2824
|
axs[2].axhline(y=0, color='grey', linestyle='--')
|
|
2812
2825
|
axs[2].set_title('signal type expected returns distribution at different time lapses')
|
|
2813
2826
|
|
|
@@ -2830,7 +2843,7 @@ class signal_analyser_object:
|
|
|
2830
2843
|
if self.return_fig:
|
|
2831
2844
|
return fig
|
|
2832
2845
|
|
|
2833
|
-
def create_backtest_signal(self,days_strategy, test_size, feature_name, high_exit = False, low_exit = False):
|
|
2846
|
+
def create_backtest_signal(self,days_strategy, test_size, feature_name, high_exit = False, low_exit = False, signal_position = False):
|
|
2834
2847
|
"""
|
|
2835
2848
|
perform backtest signal analysis
|
|
2836
2849
|
|
|
@@ -2841,7 +2854,8 @@ class signal_analyser_object:
|
|
|
2841
2854
|
feature_name (str): name of the feature to assess
|
|
2842
2855
|
high_exit (float): high exit thrshold return in backtest
|
|
2843
2856
|
low_exit (float): loss exit thrshold return in backtest
|
|
2844
|
-
|
|
2857
|
+
signal_position (int): if true, the signal is taken at the given step after the signal end
|
|
2858
|
+
|
|
2845
2859
|
Returns
|
|
2846
2860
|
-------
|
|
2847
2861
|
fig (obj): plots
|
|
@@ -2887,19 +2901,28 @@ class signal_analyser_object:
|
|
|
2887
2901
|
dft['chain_id'] = dft['chain_id'].fillna(method = 'ffill')
|
|
2888
2902
|
|
|
2889
2903
|
dft['internal_rn'] = dft.sort_values(['Date']).groupby(['chain_id']).cumcount() + 1
|
|
2890
|
-
|
|
2891
|
-
|
|
2904
|
+
|
|
2892
2905
|
dft['lrets_bench'] = np.log(dft[asset_1]/dft[asset_1].shift(1))
|
|
2893
2906
|
dft['bench_prod'] = dft['lrets_bench'].cumsum()
|
|
2894
2907
|
dft['bench_prod_exp'] = np.exp(dft['bench_prod']) - 1
|
|
2895
2908
|
|
|
2909
|
+
if signal_position:
|
|
2910
|
+
dft['open_long'] = np.where(dft.last_in_chain == True, True, np.nan)
|
|
2911
|
+
dft['open_long'] = dft.groupby(['chain_id'])['open_long'].shift(signal_position)
|
|
2912
|
+
dft['flag'] = np.where(dft['internal_rn'] < days_strategy + signal_position, 1,0)
|
|
2913
|
+
dft['flag'] = dft.groupby(['chain_id'])['flag'].shift(signal_position)
|
|
2914
|
+
else:
|
|
2915
|
+
dft['open_long'] = np.where(dft.last_in_chain == True, True, np.nan)
|
|
2916
|
+
dft['flag'] = np.where(dft['internal_rn'] < days_strategy, 1,0)
|
|
2917
|
+
|
|
2896
2918
|
if high_exit and low_exit:
|
|
2897
|
-
dft['open_strat'] = np.where(dft.
|
|
2919
|
+
dft['open_strat'] = np.where(dft.open_long == True, dft.Open, np.nan)
|
|
2898
2920
|
dft['open_strat'] = dft['open_strat'].fillna(method = 'ffill')
|
|
2899
2921
|
dft['open_strat'] = np.where(dft.flag == 1, dft.open_strat, np.nan)
|
|
2900
2922
|
dft['high_strat_ret'] = (dft['High']/dft['open_strat']-1)*100
|
|
2901
2923
|
dft['low_strat_ret'] = (dft['Low']/dft['open_strat']-1)*100
|
|
2902
|
-
dft['
|
|
2924
|
+
dft['max_step_chain'] = dft.groupby(['chain_id'])['internal_rn'].transform('max')
|
|
2925
|
+
dft['high_exit'] = np.where(((dft['high_strat_ret'] >= high_exit) | (dft['internal_rn'] == days_strategy) | (dft['max_step_chain'] == dft['internal_rn'])), 1, np.nan)
|
|
2903
2926
|
dft['low_exit'] = np.where((dft['low_strat_ret'] <= low_exit), -1, np.nan)
|
|
2904
2927
|
|
|
2905
2928
|
dft["exit_type"] = dft[["high_exit", "low_exit"]].max(axis=1)
|
|
@@ -2916,8 +2939,10 @@ class signal_analyser_object:
|
|
|
2916
2939
|
dft['exit_step'] = np.where(dft.exit == 1, dft.internal_rn, np.nan)
|
|
2917
2940
|
dft['exit_step'] = dft.sort_values(['Date']).groupby(['chain_id']).exit_step.transform('max')
|
|
2918
2941
|
|
|
2919
|
-
|
|
2920
|
-
|
|
2942
|
+
if signal_position:
|
|
2943
|
+
dft['flag'] = np.where( (dft.internal_rn >= signal_position + 1) & (dft.internal_rn <= dft.exit_step) , 1,0)
|
|
2944
|
+
else:
|
|
2945
|
+
dft['flag'] = np.where(dft.internal_rn <= dft.exit_step, 1, 0)
|
|
2921
2946
|
|
|
2922
2947
|
dft['lrets_strat'] = np.log(dft[asset_1].shift(-1)/dft[asset_1]) * dft['flag']
|
|
2923
2948
|
dft['lrets_strat'] = np.where(dft['lrets_strat'].isna(),-0.0,dft['lrets_strat'])
|
|
@@ -2945,9 +2970,11 @@ class signal_analyser_object:
|
|
|
2945
2970
|
print('----------------------------')
|
|
2946
2971
|
|
|
2947
2972
|
fig = plt.figure(1)
|
|
2948
|
-
plt.plot(dft.bench_prod_exp.values, label = 'benchmark')
|
|
2973
|
+
plt.plot(dft.bench_prod_exp.values, label = 'benchmark', color = 'steelblue')
|
|
2949
2974
|
plt.scatter(range(len(dft)),np.where(dft[low_signal] == 1,dft.bench_prod_exp.values,np.nan),color = 'red', label = 'signal')
|
|
2950
|
-
plt.plot(dft.strat_prod_exp.values, label = 'strategy')
|
|
2975
|
+
plt.plot(dft.strat_prod_exp.values, label = 'strategy', color = 'darksalmon')
|
|
2976
|
+
plt.xlabel("index")
|
|
2977
|
+
plt.ylabel("comulative return")
|
|
2951
2978
|
plt.legend()
|
|
2952
2979
|
plt.title('strategy and cumulative returns based on signal strategy')
|
|
2953
2980
|
if self.show_plot:
|
|
@@ -2958,14 +2985,11 @@ class signal_analyser_object:
|
|
|
2958
2985
|
result_plot_name = f'signals_strategy_return_{feature_name}.png'
|
|
2959
2986
|
|
|
2960
2987
|
plt.savefig(self.save_path+result_plot_name)
|
|
2961
|
-
# pickle.dump(fig, open(self.save_path+result_plot_name, 'wb'))
|
|
2962
2988
|
|
|
2963
2989
|
with open(self.save_path+result_json_name, "w") as outfile:
|
|
2964
2990
|
json.dump(messages, outfile)
|
|
2965
2991
|
|
|
2966
2992
|
if self.save_path and self.save_aws:
|
|
2967
|
-
# upload_file_to_aws(bucket = 'VIRGO_BUCKET', key = f'market_plots/{self.ticket_name}/'+result_json_name ,input_path = self.save_path+result_json_name)
|
|
2968
|
-
# upload_file_to_aws(bucket = 'VIRGO_BUCKET', key = f'market_plots/{self.ticket_name}/'+result_plot_name,input_path = self.save_path+result_plot_name)
|
|
2969
2993
|
|
|
2970
2994
|
upload_file_to_aws(bucket = 'VIRGO_BUCKET', key = self.save_aws + result_json_name, input_path = self.save_path + result_json_name, aws_credentials = self.aws_credentials)
|
|
2971
2995
|
upload_file_to_aws(bucket = 'VIRGO_BUCKET', key = self.save_aws + result_plot_name, input_path = self.save_path + result_plot_name, aws_credentials = self.aws_credentials)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{virgo_modules-0.0.80 → virgo_modules-0.0.82}/virgo_app/virgo_modules.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
{virgo_modules-0.0.80 → virgo_modules-0.0.82}/virgo_app/virgo_modules.egg-info/top_level.txt
RENAMED
|
File without changes
|