Skip to content

Commit

Permalink
Merge pull request #14 from Matteo-Giorgetti/master
Browse files Browse the repository at this point in the history
New metric: udd stop count
  • Loading branch information
ysdede authored Nov 18, 2022
2 parents 4d9153c + 39bd118 commit 7926b8b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 24 deletions.
49 changes: 26 additions & 23 deletions jessetk2/RefineSeq.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ def print_tops_formatted(self, sorted_results=None, n:int = 50):
p['total_profit'],
p['udd'],
p['ppudd'],
p['udd_stop_count'],
p['max_margin_ratio'],
p['pmr'],
p['lpr'],
Expand All @@ -309,6 +310,30 @@ def print_tops_formatted(self, sorted_results=None, n:int = 50):
p['bench_vol']
))


def save_dnas(self, sorted_results, dna_fn=None):

if not dna_fn:
dna_fn = f'{self.jessetkdir}/dnafiles/{self.pair} {self.start_date} {self.finish_date}.py'

jessetk2.utils.remove_file(dna_fn)

with open(dna_fn, 'w', encoding='utf-8') as f:
self.write_dna_file(f, sorted_results)

def write_dna_file(self, f, sorted_results):
f.write('dnas = [\n')

for srr in sorted_results:
for dnac in self.dnas:
if srr['dna'] == dnac[0]:
f.write(str(dnac) + ',\n')

f.write(']\n')
f.flush()
os.fsync(f.fileno())


# def print_tops_formatted(self):
# print(
# Vars.refine_console_formatter.format(*Vars.refine_console_header1))
Expand Down Expand Up @@ -355,26 +380,4 @@ def print_tops_formatted(self, sorted_results=None, n:int = 50):
# p['n_of_wins'],
# p['n_of_loses'],
# p['paid_fees'],
# p['market_change']))

def save_dnas(self, sorted_results, dna_fn=None):

if not dna_fn:
dna_fn = f'{self.jessetkdir}/dnafiles/{self.pair} {self.start_date} {self.finish_date}.py'

jessetk2.utils.remove_file(dna_fn)

with open(dna_fn, 'w', encoding='utf-8') as f:
self.write_dna_file(f, sorted_results)

def write_dna_file(self, f, sorted_results):
f.write('dnas = [\n')

for srr in sorted_results:
for dnac in self.dnas:
if srr['dna'] == dnac[0]:
f.write(str(dnac) + ',\n')

f.write(']\n')
f.flush()
os.fsync(f.fileno())
# p['market_change']))
6 changes: 5 additions & 1 deletion jessetk2/Vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
'total_profit': 0.0,
'udd': None,
'ppudd': None,
'udd_stop_count': None,
'max_dd': 0.0,
'annual_return': 0.0,
'max_margin_ratio': None,
Expand Down Expand Up @@ -65,6 +66,7 @@
'Insf. Margin Count',
'uDD',
'pudd',
'udd stop count',
'Max.DD',
'Benchmark Volatility',
'Winrate',
Expand All @@ -88,6 +90,7 @@
'Total Net',
'uDD',
'ppuDD',
'udd stop',
'Max.',
'PMR',
'LP',
Expand Down Expand Up @@ -117,6 +120,7 @@
'Profit %',
'%',
'ratio',
'Count',
'Margin %',
'%',
'Rate',
Expand All @@ -139,7 +143,7 @@
'Volat. %'
]

refine_console_formatter = '{: <22} {: <6} {: <5} {: <7} {: <12} {: <8} {: <8} {: <8} {: <8} {: <8} {: <8} {: <8} {: <8} {: <10} {: <8} {: <8} {: <8} {: <8} {: <8} {: <8} ' \
refine_console_formatter = '{: <22} {: <6} {: <5} {: <7} {: <12} {: <8} {: <8} {: <8} {: <8} {: <8} {: <8} {: <8} {: <8} {: <8} {: <10} {: <8} {: <8} {: <8} {: <8} {: <8} {: <8} ' \
'{: <12} {: <12} {: <10} {: <8} {: <8} {: <8} {: <9}'

random_console_formatter = '{: <12} {: <12} {: <6} {: <5} {: <7} {: <12} {: <8} {: <8} {: <8} {: <8} {: <8} {: <8} {: <10} {: <8} {: <8} {: <8} {: <8} {: <8} {: <8} ' \
Expand Down
5 changes: 5 additions & 0 deletions jessetk2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ def print_tops_formatted(frmt, header1, header2, tr):
r['total_profit'],
r['udd'],
r['ppudd'],
r['udd_stop_count'],
r['max_margin_ratio'],
r['pmr'],
r['lpr'],
Expand Down Expand Up @@ -366,6 +367,7 @@ def print_random_tops(sr, top_n):
r['n_of_shorts'],
r['total_profit'],
r['udd'],
r['udd_stop_count'],
r['max_margin_ratio'],
r['pmr'],
r['lpr'],
Expand Down Expand Up @@ -579,6 +581,9 @@ def get_metrics3(console_output) -> dict:
if 'ppudd Ratio ' in line and '|' in line:
metrics['ppudd'] = round(float(split(line)), 2)

if 'udd stop Count ' in line and '|' in line:
metrics['udd_stop_count'] = round(float(split(line)))

return metrics


Expand Down

0 comments on commit 7926b8b

Please sign in to comment.