-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrategy_nav.py
69 lines (55 loc) · 1.28 KB
/
strategy_nav.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# -*- coding: utf-8 -*-
# ---
# jupyter:
# jupytext:
# formats: ipynb,py:percent
# text_representation:
# extension: .py
# format_name: percent
# format_version: '1.3'
# jupytext_version: 1.6.0
# kernelspec:
# display_name: Python 3
# language: python
# name: python3
# ---
# %%
# %load_ext autoreload
# %autoreload 2
# %matplotlib inline
from pprint import pprint
from IPython.display import display
# %%
import numpy as np
import pandas as pd
import matplotlib.pylab as plt
# %%
from signal_confirmation import signal, idx_, get_df_action
# %%
def get_PnL(idx_, signal, holding_days):
df_action = get_df_action(idx_, signal, holding_days)
df = (
df_action.
assign(prc_diff = lambda x: x.prc_exit - x.p0,
PnL = lambda x: x.prc_diff.fillna(0).cumsum()).
loc[:, ['action', 'close', 'prc_diff', 'PnL']]
)
df.PnL.plot(title=f'holding days: {holding_days}', figsize=(20, 5))
plt.show()
return df
# %%
holding_days = 5
df_PnL = get_PnL(idx_, signal, holding_days)
# %%
holding_days = 10
df_PnL = get_PnL(idx_, signal, holding_days)
# %%
holding_days = 15
df_PnL = get_PnL(idx_, signal, holding_days)
# %%
holding_days = 20
df_PnL = get_PnL(idx_, signal, holding_days)
# %%
# %%
# %%
# %%