plotguy 2.2.0__tar.gz → 2.2.2__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.
- {plotguy-2.2.0 → plotguy-2.2.2}/PKG-INFO +1 -1
- {plotguy-2.2.0 → plotguy-2.2.2}/plotguy/__init__.py +62 -0
- {plotguy-2.2.0 → plotguy-2.2.2}/plotguy/components.py +6 -2
- {plotguy-2.2.0 → plotguy-2.2.2}/plotguy.egg-info/PKG-INFO +1 -1
- {plotguy-2.2.0 → plotguy-2.2.2}/setup.py +1 -1
- {plotguy-2.2.0 → plotguy-2.2.2}/README.md +0 -0
- {plotguy-2.2.0 → plotguy-2.2.2}/plotguy/aggregate.py +0 -0
- {plotguy-2.2.0 → plotguy-2.2.2}/plotguy/equity_curves.py +0 -0
- {plotguy-2.2.0 → plotguy-2.2.2}/plotguy/signals.py +0 -0
- {plotguy-2.2.0 → plotguy-2.2.2}/plotguy.egg-info/SOURCES.txt +0 -0
- {plotguy-2.2.0 → plotguy-2.2.2}/plotguy.egg-info/dependency_links.txt +0 -0
- {plotguy-2.2.0 → plotguy-2.2.2}/plotguy.egg-info/requires.txt +0 -0
- {plotguy-2.2.0 → plotguy-2.2.2}/plotguy.egg-info/top_level.txt +0 -0
- {plotguy-2.2.0 → plotguy-2.2.2}/setup.cfg +0 -0
|
@@ -200,6 +200,8 @@ def save_backtest_result(df, para_combination_item):
|
|
|
200
200
|
elif len(df_count) > 0:
|
|
201
201
|
|
|
202
202
|
########### by year count, win rate and return ###############
|
|
203
|
+
start_year = df.index[0].year
|
|
204
|
+
end_year = df.index[-1].year
|
|
203
205
|
|
|
204
206
|
num_of_trade = len(df_count)
|
|
205
207
|
df_count = pd.concat([df_count, df[df['trd_side'] != ''].tail(1)])
|
|
@@ -217,6 +219,23 @@ def save_backtest_result(df, para_combination_item):
|
|
|
217
219
|
yearly_stats['year_return'] = 100 * (yearly_stats['year_pnl'] / yearly_stats['year_start_equity_value'])
|
|
218
220
|
yearly_stats['year_win_rate'] = 100 * (yearly_stats['year_win_count'] / yearly_stats['year_trade_count'])
|
|
219
221
|
|
|
222
|
+
all_years = range(start_year, end_year + 1)
|
|
223
|
+
current_years = yearly_stats.index
|
|
224
|
+
missing_years = [year for year in all_years if year not in current_years]
|
|
225
|
+
|
|
226
|
+
#if year_start_equity_value = df.at[df.index[0], 'equity_value'
|
|
227
|
+
missing_rows = pd.DataFrame(
|
|
228
|
+
{ "year_pnl": 0,
|
|
229
|
+
"year_win_count": 0,
|
|
230
|
+
"year_trade_count": 0,
|
|
231
|
+
"year_start_equity_value": 0,
|
|
232
|
+
"year_return": 0,
|
|
233
|
+
"year_win_rate": 0,
|
|
234
|
+
}, index=missing_years)
|
|
235
|
+
missing_rows.index.name = "datetime"
|
|
236
|
+
|
|
237
|
+
yearly_stats = pd.concat([yearly_stats, missing_rows]).sort_index()
|
|
238
|
+
|
|
220
239
|
cov_return = yearly_stats['year_return'].std() / yearly_stats['year_return'].mean() if yearly_stats['year_return'].mean() != 0 else 0
|
|
221
240
|
cov_count = yearly_stats['year_trade_count'].std() / yearly_stats['year_trade_count'].mean() if yearly_stats['year_trade_count'].mean() != 0 else 0
|
|
222
241
|
|
|
@@ -227,6 +246,8 @@ def save_backtest_result(df, para_combination_item):
|
|
|
227
246
|
axis=1)
|
|
228
247
|
|
|
229
248
|
yearly_stats_string = "|".join(formatted_rows)
|
|
249
|
+
print(yearly_stats_string)
|
|
250
|
+
print(yearly_stats)
|
|
230
251
|
|
|
231
252
|
######## resample to daily #############
|
|
232
253
|
if 'summary_mode' in para_combination:
|
|
@@ -443,3 +464,44 @@ def get_geometric_mean_of_yearly_rate_backup(start_year, end_year):
|
|
|
443
464
|
|
|
444
465
|
return fed_fund_rate_geometric_mean
|
|
445
466
|
|
|
467
|
+
def su_table_converter():
|
|
468
|
+
all_str_dir = []
|
|
469
|
+
for folder_name in os.listdir():
|
|
470
|
+
if os.path.isfile(os.path.join(folder_name, 'saved_strategies.parquet')):
|
|
471
|
+
all_str_dir.append(folder_name)
|
|
472
|
+
|
|
473
|
+
su_dict = {'backtest_name': [], 'code': [], 'freq': [], 'para_items_str': [], 'initial_capital': [],
|
|
474
|
+
'equity_mdd_pct': []}
|
|
475
|
+
|
|
476
|
+
for str_dir in all_str_dir:
|
|
477
|
+
saved_strategies_path = os.path.join(str_dir, 'saved_strategies.parquet')
|
|
478
|
+
saved_strategies_df = pd.read_parquet(saved_strategies_path)
|
|
479
|
+
saved_strategies_df = saved_strategies_df.reset_index(drop=True)
|
|
480
|
+
|
|
481
|
+
if len(saved_strategies_df.columns) > 1:
|
|
482
|
+
for i, row in saved_strategies_df.iterrows():
|
|
483
|
+
backtest_name = row['backtest_name']
|
|
484
|
+
freq = row['freq']
|
|
485
|
+
para_keys_str = row['para_keys_str']
|
|
486
|
+
equity_mdd_pct = row['equity_mdd_pct']
|
|
487
|
+
initial_capital = row['initial_capital']
|
|
488
|
+
|
|
489
|
+
para_items_str = ''
|
|
490
|
+
para_keys_str_list = para_keys_str.split('|')
|
|
491
|
+
for para_key in para_keys_str_list:
|
|
492
|
+
para_value = str(saved_strategies_df.at[i, para_key])
|
|
493
|
+
if para_key == 'code':
|
|
494
|
+
code = para_value
|
|
495
|
+
else:
|
|
496
|
+
para_items_str += para_key + '=' + para_value + '|'
|
|
497
|
+
para_items_str = para_items_str[:-1]
|
|
498
|
+
|
|
499
|
+
su_dict['backtest_name'].append(backtest_name)
|
|
500
|
+
su_dict['code'].append(code)
|
|
501
|
+
su_dict['freq'].append(freq)
|
|
502
|
+
su_dict['para_items_str'].append(para_items_str)
|
|
503
|
+
su_dict['equity_mdd_pct'].append(equity_mdd_pct)
|
|
504
|
+
su_dict['initial_capital'].append(initial_capital)
|
|
505
|
+
|
|
506
|
+
su_table = pd.DataFrame(su_dict)
|
|
507
|
+
return su_table
|
|
@@ -258,6 +258,8 @@ class Components:
|
|
|
258
258
|
ref_code = result_df.loc[line_selected].ref_code
|
|
259
259
|
|
|
260
260
|
yearly_stats_string = result_df.loc[line_selected]['yearly_stats_string']
|
|
261
|
+
print(result_df)
|
|
262
|
+
print(yearly_stats_string)
|
|
261
263
|
|
|
262
264
|
per_col1 =[]
|
|
263
265
|
per_col2 = []
|
|
@@ -630,7 +632,9 @@ class Components:
|
|
|
630
632
|
fig_line.add_trace(go.Scatter(mode='lines', hovertemplate=hovertemplate,
|
|
631
633
|
x=df_daily.index.date, y=df_daily['equity_value'],
|
|
632
634
|
line=dict(color=line_colour, width=1.5), name=''), )
|
|
633
|
-
|
|
635
|
+
fig_line.update_layout(
|
|
636
|
+
hoverlabel=dict(align="left", font_size=12, bgcolor="white")
|
|
637
|
+
)
|
|
634
638
|
|
|
635
639
|
return fig_line
|
|
636
640
|
|
|
@@ -791,6 +795,7 @@ class Components:
|
|
|
791
795
|
for folder_name in os.listdir():
|
|
792
796
|
if os.path.isfile(os.path.join(folder_name, 'saved_strategies.parquet')):
|
|
793
797
|
all_str_dir.append(folder_name)
|
|
798
|
+
|
|
794
799
|
all_str_dir.sort()
|
|
795
800
|
equity_curves_dict_list = []
|
|
796
801
|
|
|
@@ -801,7 +806,6 @@ class Components:
|
|
|
801
806
|
if len(saved_strategies_df.columns) > 1:
|
|
802
807
|
for i, row in saved_strategies_df.iterrows():
|
|
803
808
|
equity_path = os.path.join(str_dir, row['equity_curve_folder'], str(row['ref_code']) + '.parquet')
|
|
804
|
-
#df_equity = pd.read_parquet(equity_path)
|
|
805
809
|
|
|
806
810
|
yearly_stats_string = row['yearly_stats_string']
|
|
807
811
|
para_keys_str = row['para_keys_str']
|
|
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
|