plotguy 2.2.1__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: plotguy
3
- Version: 2.2.1
3
+ Version: 2.2.2
4
4
  Summary: Plotguy
5
5
  Home-page: https://pypi.org/project/plotguy/
6
6
  Author: Plotguy Team
@@ -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:
@@ -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 = []
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: plotguy
3
- Version: 2.2.1
3
+ Version: 2.2.2
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.2.1",
8
+ version="2.2.2",
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
File without changes