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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: plotguy
3
- Version: 2.3.8
3
+ Version: 2.4.0
4
4
  Summary: Plotguy
5
5
  Home-page: https://pypi.org/project/plotguy/
6
6
  Author: Plotguy Team
@@ -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
- df_count['realized_pnl'] = df_count['equity_value'] - df_count['equity_value'].shift(1)
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
- #if year_start_equity_value = df.at[df.index[0], 'equity_value'
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
- risk_free_rate_history_yearly = df.resample("A", on="date").mean()
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
- from .components import *
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
- try:
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
- except:
345
- risk_free_rate = 1
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(round((252 - 252 * degree)/3)))
514
- elif profile == 3: rgb = (0, 252, int(round((252 - 252 * degree)/3)))
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):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: plotguy
3
- Version: 2.3.8
3
+ Version: 2.4.0
4
4
  Summary: Plotguy
5
5
  Home-page: https://pypi.org/project/plotguy/
6
6
  Author: Plotguy Team
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
5
5
 
6
6
  setuptools.setup(
7
7
  name="plotguy",
8
- version="2.3.8",
8
+ version="2.4.0",
9
9
  author="Plotguy Team",
10
10
  author_email="plotguy.info@gmail.com",
11
11
  description="Plotguy",
File without changes
File without changes
File without changes