virgo-modules 0.0.76__py3-none-any.whl → 0.0.78__py3-none-any.whl

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.

@@ -1389,6 +1389,7 @@ def save_edge_model(data, save_path = False, save_aws = False, show_result = Fal
1389
1389
  if show_result:
1390
1390
  print(curent_edge)
1391
1391
 
1392
+ ## this function is going to be split and deprecated
1392
1393
  def create_feature_edge(model, data,feature_name, threshold, target_variables):
1393
1394
  '''
1394
1395
  get latest edge execution and edge probability
@@ -1417,4 +1418,74 @@ def create_feature_edge(model, data,feature_name, threshold, target_variables):
1417
1418
  result_df[f'signal_{type_use}_{feature_name}'] = np.where(result_df[pred_col] >= threshold,1,0)
1418
1419
  result_df[f'acc_{type_use}_{feature_name}'] = np.where(result_df[f'signal_{type_use}_{feature_name}'] == result_df[pred_col.replace('proba_','')],1,0)
1419
1420
 
1420
- return result_df
1421
+ return result_df
1422
+
1423
+ def produce_probas(model,data, target_variables):
1424
+ """
1425
+ produce probabilities given a model
1426
+
1427
+ Parameters:
1428
+ model (obj): edge model artifact
1429
+ data (pd.DataFrame): asset data
1430
+ target_variables (list): names of the target columns
1431
+
1432
+ Returns:
1433
+ result_df (pd.DataFrame): result dataframe with edges
1434
+ label_prediction (list): list of resulting label columns
1435
+ """
1436
+ label_prediction = ['proba_'+x for x in target_variables]
1437
+ predictions = model.predict_proba(data)
1438
+ predictions = pd.DataFrame(predictions, columns = label_prediction, index = data.index)
1439
+
1440
+ result_df = pd.concat([data, predictions], axis=1)
1441
+ result_df = result_df[['Date'] + target_variables + label_prediction]
1442
+
1443
+ return result_df, label_prediction
1444
+
1445
+ def produce_signals(result_df, feature_name, threshold, label_prediction):
1446
+ """
1447
+ produce signals from probabilities
1448
+
1449
+ Parameters:
1450
+ result_df (pd.DataFrame): asset data with probabilities
1451
+ feature_name (str): edge feature name
1452
+ threshold (float): edge threshold
1453
+ label_prediction (list): list of resulting label columns
1454
+
1455
+ Returns:
1456
+ result_df (pd.DataFrame): result dataframe with edges and signals
1457
+ """
1458
+ for pred_col in label_prediction:
1459
+ type_use = 'low'
1460
+ if 'down' in pred_col:
1461
+ type_use = 'up'
1462
+
1463
+ result_df[f'signal_{type_use}_{feature_name}'] = np.where(result_df[pred_col] >= threshold,1,0)
1464
+ result_df[f'acc_{type_use}_{feature_name}'] = np.where(result_df[f'signal_{type_use}_{feature_name}'] == result_df[pred_col.replace('proba_','')],1,0)
1465
+
1466
+ return result_df
1467
+
1468
+ def edge_probas_lines(data, threshold, plot = False, look_back = 750):
1469
+ """
1470
+ produce a plotly plot of edges and closing prices
1471
+
1472
+ Parameters:
1473
+ data (pd.DataFrame): asset data with edge probabilities
1474
+ plot (boolean): if true, display plot
1475
+ threshold (float): edge threshold
1476
+ look_back (int): number of rows back to display
1477
+
1478
+ Returns:
1479
+ fig (obj): plotly go object
1480
+ """
1481
+ df = data[['Date','Close','proba_target_down','proba_target_up']].iloc[-look_back:]
1482
+
1483
+ fig = make_subplots(specs=[[{"secondary_y": True}]])
1484
+ fig.add_trace(go.Scatter(x=df.Date, y=df.Close,mode='lines+markers',name='Close price'))
1485
+ fig.add_trace(go.Scatter(x=df.Date, y=df.proba_target_down,mode='lines',marker = dict(color = 'coral'),name='go down'),secondary_y=True)
1486
+ fig.add_trace(go.Scatter(x=df.Date, y=df.proba_target_up,mode='lines',marker = dict(opacity=0.1,size=80), name='go up'),secondary_y=True)
1487
+ fig.add_shape(type="line", xref="paper", yref="y2",x0=0.02, y0=threshold, x1=0.9, y1=threshold,line=dict(color="red",dash="dash"),)
1488
+ fig.update_layout(title_text="sirius - edge probabilities",width=1200,height = 500)
1489
+ if plot:
1490
+ fig.show()
1491
+ return fig
@@ -2734,11 +2734,11 @@ class signal_analyser_object:
2734
2734
  )
2735
2735
  )
2736
2736
  df = df[~df.signal_type.isna()]
2737
- # df['Date'] = df.index
2738
2737
  df['lag_Date'] = df['Date'].shift(1)
2738
+ df['lag_signal_type'] = df['signal_type'].shift(1)
2739
2739
  df['span'] = (pd.to_datetime(df['Date']) - pd.to_datetime(df['lag_Date'])).dt.days - 1
2740
- df['break'] = np.where(df['span'] > 3, 1, 0)
2741
- df['break'] = np.where(df['span'].isna(), 1, df['break'])
2740
+ df['break'] = np.where((df['span'] > 3) & (df['lag_signal_type'] == df['signal_type']), 1, 0)
2741
+ df['break'] = np.where((df['lag_signal_type'] != df['signal_type']), 1, df['break'])
2742
2742
 
2743
2743
  df['chain_id'] = df.sort_values(['Date']).groupby(['break']).cumcount() + 1
2744
2744
  df['chain_id'] = np.where(df['break'] == 1, df['chain_id'], np.nan )
@@ -2861,11 +2861,11 @@ class signal_analyser_object:
2861
2861
  )
2862
2862
  )
2863
2863
  df2 = df2[~df2.signal_type.isna()]
2864
- # df2['Date_'] = df2.index
2865
2864
  df2['lag_Date'] = df2['Date'].shift(1)
2865
+ df2['lag_signal_type'] = df2['signal_type'].shift(1)
2866
2866
  df2['span'] = (pd.to_datetime(df2['Date']) - pd.to_datetime(df2['lag_Date'])).dt.days - 1
2867
- df2['break'] = np.where(df2['span'] > 3, 1, 0)
2868
- df2['break'] = np.where(df2['span'].isna(), 1, df2['break'])
2867
+ df2['break'] = np.where((df2['span'] > 3) & (df2['lag_signal_type'] == df2['signal_type']), 1, 0)
2868
+ df2['break'] = np.where((df2['lag_signal_type'] != df2['signal_type']), 1, df2['break'])
2869
2869
 
2870
2870
  df2['chain_id'] = df2.sort_values(['Date']).groupby(['break']).cumcount() + 1
2871
2871
  df2['chain_id'] = np.where(df2['break'] == 1, df2['chain_id'], np.nan )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: virgo-modules
3
- Version: 0.0.76
3
+ Version: 0.0.78
4
4
  Summary: data processing and statistical modeling using stock market data
5
5
  Home-page: https://github.com/miguelmayhem92/virgo_module
6
6
  Author: Miguel Mayhuire
@@ -3,10 +3,10 @@ virgo_modules/src/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU
3
3
  virgo_modules/src/aws_utils.py,sha256=q0l7D7ofo09Lu1QQjv-esheQ06uiSy1Pdq3xMul8zvk,2571
4
4
  virgo_modules/src/edge_utils.py,sha256=ll5pRs9EE20IsE5A1vA589TKzobkeA-b0d68jNTsu1U,13268
5
5
  virgo_modules/src/pull_artifacts.py,sha256=5OPrgR7pcMSdpbevDRhf0ebk7g7ZRjff4NpTIIWAKjE,1989
6
- virgo_modules/src/re_utils.py,sha256=fprzdQPKXdfZhWaWjuAHmTzc7BXuoPSWFny2ng-Qea0,64053
7
- virgo_modules/src/ticketer_source.py,sha256=U7_j31RosDpLln8w5TBW8bgJE1BDn6rcAQhgeXs_AUU,142521
8
- virgo_modules-0.0.76.dist-info/LICENSE,sha256=pNgFyCYgmimaw0o6V20JupZLROycAnOA_HDDh1tX2V4,1097
9
- virgo_modules-0.0.76.dist-info/METADATA,sha256=NidPaLN4CHf3G2TEe3higIR9S_-HXlEl1DvdvHK9cCU,1429
10
- virgo_modules-0.0.76.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
11
- virgo_modules-0.0.76.dist-info/top_level.txt,sha256=ZjI-qEkDtT-8mFwGAWnXfqPOKEGlIhWRW1es1VyXc60,14
12
- virgo_modules-0.0.76.dist-info/RECORD,,
6
+ virgo_modules/src/re_utils.py,sha256=1nECCNs5Y0jhKfR1X2iYPCq2dB2TY7TuG9I-iDC4EhY,67272
7
+ virgo_modules/src/ticketer_source.py,sha256=4J0y51Tv0dGzFU7qZarGBIJSFsFWfY_NDNWZI6VN2Ws,142729
8
+ virgo_modules-0.0.78.dist-info/LICENSE,sha256=pNgFyCYgmimaw0o6V20JupZLROycAnOA_HDDh1tX2V4,1097
9
+ virgo_modules-0.0.78.dist-info/METADATA,sha256=6FLuFG4Cu7PJzIGNRn5zwoProYuPR_qTch741pmGE_A,1429
10
+ virgo_modules-0.0.78.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
11
+ virgo_modules-0.0.78.dist-info/top_level.txt,sha256=ZjI-qEkDtT-8mFwGAWnXfqPOKEGlIhWRW1es1VyXc60,14
12
+ virgo_modules-0.0.78.dist-info/RECORD,,