mirror of
https://github.com/wassname/options_backtester.git
synced 2026-06-27 17:31:05 +08:00
merged_bt_example now has a more thorough explanation of the backtester
This commit is contained in:
+13618
-356
File diff suppressed because one or more lines are too long
@@ -49,14 +49,14 @@ def returns_histogram(report):
|
||||
|
||||
|
||||
def monthly_returns_heatmap(report):
|
||||
resample = report.resample('M')['capital'].last()
|
||||
resample = report.resample('M')['total capital'].last()
|
||||
monthly_returns = resample.pct_change().reset_index()
|
||||
monthly_returns['capital'].iat[0] = resample.iloc[0] / report.iloc[0]['capital'] - 1
|
||||
monthly_returns.columns = ['date', 'capital']
|
||||
monthly_returns['total capital'].iat[0] = resample.iloc[0] / report.iloc[0]['total capital'] - 1
|
||||
monthly_returns.columns = ['date', 'total capital']
|
||||
|
||||
chart = alt.Chart(monthly_returns).mark_rect().encode(
|
||||
alt.X('year(date):O', title='Year'), alt.Y('month(date):O', title='Month'),
|
||||
alt.Color('mean(capital)', title='Return', scale=alt.Scale(scheme='redyellowgreen')),
|
||||
alt.Tooltip('mean(capital)', format='.2f')).properties(title='Monthly Returns')
|
||||
alt.Color('mean(total capital)', title='Return', scale=alt.Scale(scheme='redyellowgreen')),
|
||||
alt.Tooltip('mean(total capital)', format='.2f')).properties(title='Monthly Returns')
|
||||
|
||||
return chart
|
||||
|
||||
Reference in New Issue
Block a user