mirror of
https://github.com/wassname/catalyst.git
synced 2026-09-12 12:12:04 +08:00
BUG: fixed stats output issue #171 by adding orders and transactions in the header
This commit is contained in:
@@ -44,7 +44,7 @@ def crossover(source, target):
|
|||||||
"""
|
"""
|
||||||
if isinstance(target, numbers.Number):
|
if isinstance(target, numbers.Number):
|
||||||
if source[-1] is np.nan or source[-2] is np.nan \
|
if source[-1] is np.nan or source[-2] is np.nan \
|
||||||
or target is np.nan:
|
or target is np.nan:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if source[-1] >= target > source[-2]:
|
if source[-1] >= target > source[-2]:
|
||||||
@@ -54,7 +54,7 @@ def crossover(source, target):
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
if source[-1] is np.nan or source[-2] is np.nan \
|
if source[-1] is np.nan or source[-2] is np.nan \
|
||||||
or target[-1] is np.nan or target[-2] is np.nan:
|
or target[-1] is np.nan or target[-2] is np.nan:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if source[-1] > target[-1] and source[-2] < target[-2]:
|
if source[-1] > target[-1] and source[-2] < target[-2]:
|
||||||
@@ -81,7 +81,7 @@ def crossunder(source, target):
|
|||||||
"""
|
"""
|
||||||
if isinstance(target, numbers.Number):
|
if isinstance(target, numbers.Number):
|
||||||
if source[-1] is np.nan or source[-2] is np.nan \
|
if source[-1] is np.nan or source[-2] is np.nan \
|
||||||
or target is np.nan:
|
or target is np.nan:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if source[-1] < target <= source[-2]:
|
if source[-1] < target <= source[-2]:
|
||||||
@@ -90,7 +90,7 @@ def crossunder(source, target):
|
|||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
if source[-1] is np.nan or source[-2] is np.nan \
|
if source[-1] is np.nan or source[-2] is np.nan \
|
||||||
or target[-1] is np.nan or target[-2] is np.nan:
|
or target[-1] is np.nan or target[-2] is np.nan:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if source[-1] < target[-1] and source[-2] >= target[-2]:
|
if source[-1] < target[-1] and source[-2] >= target[-2]:
|
||||||
@@ -229,7 +229,10 @@ def prepare_stats(stats, recorded_cols=list()):
|
|||||||
asset_values)
|
asset_values)
|
||||||
|
|
||||||
df = pd.DataFrame(stats)
|
df = pd.DataFrame(stats)
|
||||||
|
df['orders'] = df['orders'].apply(lambda orders: len(orders))
|
||||||
|
df['transactions'] = df['transactions'].apply(
|
||||||
|
lambda transactions: len(transactions)
|
||||||
|
)
|
||||||
index_cols = [
|
index_cols = [
|
||||||
'period_close', 'starting_cash', 'ending_cash', 'portfolio_value',
|
'period_close', 'starting_cash', 'ending_cash', 'portfolio_value',
|
||||||
'pnl', 'long_exposure', 'short_exposure', 'orders', 'transactions',
|
'pnl', 'long_exposure', 'short_exposure', 'orders', 'transactions',
|
||||||
@@ -241,11 +244,6 @@ def prepare_stats(stats, recorded_cols=list()):
|
|||||||
for column in recorded_cols:
|
for column in recorded_cols:
|
||||||
index_cols.append(column)
|
index_cols.append(column)
|
||||||
|
|
||||||
df['orders'] = df['orders'].apply(lambda orders: len(orders))
|
|
||||||
df['transactions'] = df['transactions'].apply(
|
|
||||||
lambda transactions: len(transactions)
|
|
||||||
)
|
|
||||||
|
|
||||||
if asset_cols:
|
if asset_cols:
|
||||||
columns = asset_cols
|
columns = asset_cols
|
||||||
df.set_index(index_cols, drop=True, inplace=True)
|
df.set_index(index_cols, drop=True, inplace=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user