plotguy 2.3.8__tar.gz → 2.4.0__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.3.8 → plotguy-2.4.0}/PKG-INFO +1 -1
- {plotguy-2.3.8 → plotguy-2.4.0}/plotguy/__init__.py +9 -3
- {plotguy-2.3.8 → plotguy-2.4.0}/plotguy/aggregate.py +16 -11
- {plotguy-2.3.8 → plotguy-2.4.0}/plotguy/components.py +4 -4
- {plotguy-2.3.8 → plotguy-2.4.0}/plotguy.egg-info/PKG-INFO +1 -1
- {plotguy-2.3.8 → plotguy-2.4.0}/setup.py +1 -1
- {plotguy-2.3.8 → plotguy-2.4.0}/README.md +0 -0
- {plotguy-2.3.8 → plotguy-2.4.0}/plotguy/equity_curves.py +0 -0
- {plotguy-2.3.8 → plotguy-2.4.0}/plotguy/signals.py +0 -0
- {plotguy-2.3.8 → plotguy-2.4.0}/plotguy.egg-info/SOURCES.txt +0 -0
- {plotguy-2.3.8 → plotguy-2.4.0}/plotguy.egg-info/dependency_links.txt +0 -0
- {plotguy-2.3.8 → plotguy-2.4.0}/plotguy.egg-info/requires.txt +0 -0
- {plotguy-2.3.8 → plotguy-2.4.0}/plotguy.egg-info/top_level.txt +0 -0
- {plotguy-2.3.8 → plotguy-2.4.0}/setup.cfg +0 -0
|
@@ -246,7 +246,9 @@ def save_backtest_result(df, para_combination_item):
|
|
|
246
246
|
|
|
247
247
|
num_of_trade = len(df_count)
|
|
248
248
|
df_count = pd.concat([df_count, df[df['trd_side'] != ''].tail(1)])
|
|
249
|
-
|
|
249
|
+
|
|
250
|
+
df_count['realized_pnl'] = df_count['equity_value'].shift(-1) - df_count['equity_value']
|
|
251
|
+
df_count = df_count[df_count['realized_pnl'].notna()]
|
|
250
252
|
df_count['win_trade'] = df_count['realized_pnl'] >= 0
|
|
251
253
|
|
|
252
254
|
num_of_win = df_count['win_trade'].sum()
|
|
@@ -264,7 +266,7 @@ def save_backtest_result(df, para_combination_item):
|
|
|
264
266
|
current_years = yearly_stats.index
|
|
265
267
|
missing_years = [year for year in all_years if year not in current_years]
|
|
266
268
|
|
|
267
|
-
|
|
269
|
+
|
|
268
270
|
missing_rows = pd.DataFrame(
|
|
269
271
|
{ "year_pnl": 0,
|
|
270
272
|
"year_win_count": 0,
|
|
@@ -496,7 +498,11 @@ def get_geometric_mean_of_yearly_rate(start_year, end_year):
|
|
|
496
498
|
df.dropna(subset=['risk_free_rate'], inplace=True)
|
|
497
499
|
print('Got Federal Funds Rate from stlouisfed.org')
|
|
498
500
|
|
|
499
|
-
|
|
501
|
+
try:
|
|
502
|
+
risk_free_rate_history_yearly = df.resample("YE", on="date").mean()
|
|
503
|
+
except:
|
|
504
|
+
risk_free_rate_history_yearly = df.resample("A", on="date").mean()
|
|
505
|
+
|
|
500
506
|
risk_free_rate_history_yearly = risk_free_rate_history_yearly.round(3)
|
|
501
507
|
|
|
502
508
|
# show only start between start_year and end_year
|
|
@@ -3,12 +3,13 @@ warnings.simplefilter("ignore", UserWarning)
|
|
|
3
3
|
|
|
4
4
|
from dash import Dash, dcc, html, Input, Output, State, ALL
|
|
5
5
|
import dash_daq as daq
|
|
6
|
-
|
|
7
|
-
import time
|
|
6
|
+
import dash_dangerously_set_inner_html
|
|
8
7
|
|
|
8
|
+
import time
|
|
9
9
|
import pandas as pd
|
|
10
|
-
import dash_dangerously_set_inner_html
|
|
11
10
|
|
|
11
|
+
from .components import *
|
|
12
|
+
import plotguy
|
|
12
13
|
|
|
13
14
|
pd.set_option('display.max_rows',None)
|
|
14
15
|
pd.set_option('display.max_columns',None)
|
|
@@ -34,6 +35,7 @@ class Aggregate:
|
|
|
34
35
|
self.df_equity_dict = {}
|
|
35
36
|
self.fig_line_dict = {}
|
|
36
37
|
self.aggregate_performance_dict = {}
|
|
38
|
+
self.risk_free_rate_dict = {}
|
|
37
39
|
|
|
38
40
|
app = Dash(__name__, external_stylesheets=[dbc.themes.SUPERHERO], suppress_callback_exceptions=True)
|
|
39
41
|
|
|
@@ -239,9 +241,6 @@ class Aggregate:
|
|
|
239
241
|
aggregate_performance = self.aggregate_performance_dict[all_dict_key]
|
|
240
242
|
else:
|
|
241
243
|
df_show_agg_checked = self.df_show_agg.loc[curve_checklist]
|
|
242
|
-
# folder_list = list(df_show_agg_checked['folder'])
|
|
243
|
-
# backtest_name_list = list(df_show_agg_checked['backtest_name'])
|
|
244
|
-
# equity_path_list = list(df_show_agg_checked['equity_path'])
|
|
245
244
|
|
|
246
245
|
df_show_agg_checked = df_show_agg_checked.drop_duplicates('ref_code')
|
|
247
246
|
|
|
@@ -249,11 +248,9 @@ class Aggregate:
|
|
|
249
248
|
df_list = []
|
|
250
249
|
|
|
251
250
|
for i, row in df_show_agg_checked.iterrows():
|
|
252
|
-
#parameters = df_show_agg_checked.at[i+1, 'parameters']
|
|
253
251
|
ref_code = df_show_agg_checked.at[i, 'ref_code']
|
|
254
252
|
equity_path = df_show_agg_checked.at[i, 'equity_path']
|
|
255
253
|
|
|
256
|
-
|
|
257
254
|
if ref_code in self.df_equity_dict:
|
|
258
255
|
df = self.df_equity_dict[ref_code]
|
|
259
256
|
else:
|
|
@@ -338,11 +335,19 @@ class Aggregate:
|
|
|
338
335
|
first_equity_value = last_equity_value
|
|
339
336
|
|
|
340
337
|
|
|
338
|
+
|
|
341
339
|
######### *********** ##########
|
|
342
|
-
|
|
340
|
+
df_year['year'] = df_year['year'].astype(str)
|
|
341
|
+
start_date = df_year['year'].min() + '0101'
|
|
342
|
+
end_date = df_year['year'].max() + '1231'
|
|
343
|
+
start_end_date = start_date + '_' + end_date
|
|
344
|
+
|
|
345
|
+
if start_end_date not in self.risk_free_rate_dict:
|
|
343
346
|
risk_free_rate = plotguy.get_risk_free_rate(start_date, end_date)
|
|
344
|
-
|
|
345
|
-
|
|
347
|
+
self.risk_free_rate_dict[start_end_date] = risk_free_rate
|
|
348
|
+
else:
|
|
349
|
+
risk_free_rate = self.risk_free_rate_dict[start_end_date]
|
|
350
|
+
|
|
346
351
|
aggregate_performance = components.aggregate_performance(total_dict, year_list, risk_free_rate)
|
|
347
352
|
self.aggregate_performance_dict[all_dict_key] = aggregate_performance
|
|
348
353
|
#################################
|
|
@@ -508,11 +508,11 @@ class Components:
|
|
|
508
508
|
return df_checked
|
|
509
509
|
|
|
510
510
|
def assign_colour(self, profile, degree):
|
|
511
|
-
if profile == 0: rgb = (0, int(252 - 252 * degree), 0)
|
|
511
|
+
if profile == 0: rgb = (0, max(100, int(252 - 252 * degree)), 0)
|
|
512
512
|
elif profile == 1: rgb = (int(252 - 252 * degree), 252, 0)
|
|
513
|
-
elif profile == 2: rgb = (252, 0, int(
|
|
514
|
-
elif profile == 3: rgb = (0, 252, int(
|
|
515
|
-
elif profile >= 4: rgb = (252, int(252 * degree), 0)
|
|
513
|
+
elif profile == 2: rgb = (252, 0, min(50, int((252 - 252 * degree)/3)))
|
|
514
|
+
elif profile == 3: rgb = (0, 252, int((252 - 252 * degree)/3))
|
|
515
|
+
elif profile >= 4: rgb = (252, max(60, int(252 * degree)), 0)
|
|
516
516
|
return 'rgb' + str(rgb)
|
|
517
517
|
|
|
518
518
|
def generate_main_chart(self, graph_df, backtest_name, equity_curve_folder, para_keys_list):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|