quantplay 1.2.89__tar.gz → 1.2.92__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.
- {quantplay-1.2.89 → quantplay-1.2.92}/PKG-INFO +1 -1
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/broker/iifl_xts.py +1 -1
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/broker/xts.py +23 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/services/tradelens.py +120 -16
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay.egg-info/PKG-INFO +1 -1
- {quantplay-1.2.89 → quantplay-1.2.92}/setup.py +1 -1
- {quantplay-1.2.89 → quantplay-1.2.92}/README.md +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/__init__.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/backtest/__init__.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/backtest/backtest_trades.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/broker/__init__.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/broker/angelone.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/broker/broker_client.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/broker/client.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/broker/finvasia_utils/__init__.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/broker/finvasia_utils/shoonya.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/broker/generics/__init__.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/broker/generics/broker.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/broker/iifl.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/broker/kite_utils.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/broker/motilal.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/broker/shoonya.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/broker/symphony.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/broker/xts_utils/Connect.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/broker/xts_utils/Exception.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/broker/xts_utils/InteractiveSocketClient.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/broker/xts_utils/MarketDataSocketClient.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/broker/xts_utils/__init__.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/broker/zerodha.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/brokerage/__init__.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/brokerage/angelone/__init__.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/brokerage/angelone/angel_broker.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/brokerage/generics/__init__.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/brokerage/generics/broker.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/brokerage/zerodha/ZBroker.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/brokerage/zerodha/__init__.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/config/__init__.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/config/qplay_config.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/create_sample_data.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/data_modify_script.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/date_fix.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/exception/__init__.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/exception/exceptions.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/executor/__init__.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/executor/strategy_executor.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/indicators/Indicator.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/indicators/__init__.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/indicators/atr.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/model/__init__.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/model/exchange/__init__.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/model/exchange/instrument.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/model/exchange/order.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/model/exchange/tick.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/model/strategy/__init__.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/model/strategy/strategy_response.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/oms/__init__.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/order_execution/__init__.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/order_execution/execution_algorithm.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/order_execution/mean_price.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/reporting/__init__.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/reporting/strategy_report.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/reporting/visuals.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/service.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/services/__init__.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/services/market.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/strategies/__init__.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/strategies/equities/__init__.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/strategies/equities/intraday/__init__.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/strategies/equities/overnight/__init__.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/strategies/futures/__init__.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/strategies/futures/overnight/__init__.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/strategies/options/__init__.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/strategies/options/intraday/__init__.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/strategies/options/intraday/ladder.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/strategies/options/intraday/musk.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/strategies/options/intraday/short_straddle.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/strategy/__init__.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/strategy/base.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/strategy_run.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/utils/__init__.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/utils/config_util.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/utils/constant.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/utils/data_utils.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/utils/exchange.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/utils/number_utils.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/utils/pickle_utils.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/utils/selenium_utils.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay/utils/transaction_utils.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay.egg-info/SOURCES.txt +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay.egg-info/dependency_links.txt +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay.egg-info/requires.txt +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/quantplay.egg-info/top_level.txt +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/setup.cfg +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/test/__init__.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/test/broker/__init__.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/test/broker/finvasia.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/test/executor/__init__.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/test/executor/strategy_executor.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/test/strategy/__init__.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/test/strategy/base.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/test/strategy/sample_strategy.py +0 -0
- {quantplay-1.2.89 → quantplay-1.2.92}/test/test_motilal.py +0 -0
|
@@ -5,6 +5,7 @@ import pandas as pd
|
|
|
5
5
|
import numpy as np
|
|
6
6
|
import pickle
|
|
7
7
|
import codecs
|
|
8
|
+
from datetime import datetime
|
|
8
9
|
|
|
9
10
|
from quantplay.broker.generics.broker import Broker
|
|
10
11
|
from quantplay.utils.constant import Constants, timeit, OrderType
|
|
@@ -65,6 +66,7 @@ class XTS(Broker):
|
|
|
65
66
|
)
|
|
66
67
|
|
|
67
68
|
def initialize_symbol_data(self):
|
|
69
|
+
# TODO: Check for Futures
|
|
68
70
|
try:
|
|
69
71
|
self.symbol_data = PickleUtils.load_data("xts_instruments")
|
|
70
72
|
Constants.logger.info("[LOADING_INSTRUMENTS] loading data from cache")
|
|
@@ -78,8 +80,29 @@ class XTS(Broker):
|
|
|
78
80
|
for instrument in instruments:
|
|
79
81
|
exchange = instrument["exchange"]
|
|
80
82
|
tradingsymbol = instrument["tradingsymbol"]
|
|
83
|
+
# NIFTY 08JUN2023 PE 17850 <- NIFTY2360817850PE
|
|
84
|
+
# 2023-06-27 -> 08JUN2023
|
|
85
|
+
# For FUTURES : EURINR23AUGFUT -> EURINR 23AUG2023 FUT
|
|
86
|
+
|
|
87
|
+
ins_type = instrument["instrument_type"]
|
|
88
|
+
name = instrument["name"]
|
|
89
|
+
if ins_type in ["CE","PE"]:
|
|
90
|
+
expiry = datetime.strftime(datetime.strptime(str(instrument["expiry"]), "%Y-%m-%d"), "%d%b%Y").upper()
|
|
91
|
+
strike = str(instrument["strike"]).rstrip("0")
|
|
92
|
+
if strike[-1] == ".":
|
|
93
|
+
strike = strike[:-1]
|
|
94
|
+
instrument["broker_symbol"] = f"{name} {expiry} {ins_type} {strike}"
|
|
95
|
+
elif ins_type == "FUT":
|
|
96
|
+
expiry = datetime.strftime(datetime.strptime(str(instrument["expiry"]), "%Y-%m-%d"), "%d%b%Y").upper()
|
|
97
|
+
instrument["broker_symbol"] = f"{name} {expiry} FUT"
|
|
98
|
+
else:
|
|
99
|
+
instrument["broker_symbol"] = tradingsymbol
|
|
100
|
+
|
|
101
|
+
|
|
81
102
|
self.symbol_data["{}:{}".format(exchange, tradingsymbol)] = instrument
|
|
82
103
|
|
|
104
|
+
self.initialize_broker_symbol_map()
|
|
105
|
+
|
|
83
106
|
PickleUtils.save_data(self.symbol_data, "xts_instruments")
|
|
84
107
|
Constants.logger.info("[LOADING_INSTRUMENTS] loading data from server")
|
|
85
108
|
|
|
@@ -4,9 +4,12 @@ import pandas as pd
|
|
|
4
4
|
from quantplay.reporting.visuals import VisualReport
|
|
5
5
|
from quantplay.services.market import Market
|
|
6
6
|
import matplotlib.pyplot as plt
|
|
7
|
+
import inspect
|
|
8
|
+
import typing
|
|
7
9
|
|
|
8
10
|
market = Market()
|
|
9
11
|
|
|
12
|
+
|
|
10
13
|
class TradeLens:
|
|
11
14
|
|
|
12
15
|
@staticmethod
|
|
@@ -29,8 +32,10 @@ class TradeLens:
|
|
|
29
32
|
|
|
30
33
|
for j in range(0, 5):
|
|
31
34
|
temp_df.loc[:, 'balance'] = temp_df.profit.cumsum()
|
|
32
|
-
temp_df.loc[:, 'running_max_balance'] = np.maximum.accumulate(
|
|
33
|
-
|
|
35
|
+
temp_df.loc[:, 'running_max_balance'] = np.maximum.accumulate(
|
|
36
|
+
temp_df.balance)
|
|
37
|
+
temp_df.loc[:, 'drawdowns'] = temp_df.running_max_balance - \
|
|
38
|
+
temp_df.balance
|
|
34
39
|
|
|
35
40
|
max_drawdown = np.max(temp_df.drawdowns)
|
|
36
41
|
end_index = None
|
|
@@ -41,7 +46,7 @@ class TradeLens:
|
|
|
41
46
|
|
|
42
47
|
start_index = end_index
|
|
43
48
|
while temp_df.iloc[start_index - 1]['running_max_balance'] == temp_df.iloc[start_index][
|
|
44
|
-
|
|
49
|
+
'running_max_balance']:
|
|
45
50
|
start_index = start_index - 1
|
|
46
51
|
|
|
47
52
|
print("Max drawdown {} from {} till {} amount {}".format(j,
|
|
@@ -56,7 +61,8 @@ class TradeLens:
|
|
|
56
61
|
def analyse(trades, disable_metrics=[]):
|
|
57
62
|
trades.loc[:, 'date'] = pd.to_datetime(trades.date)
|
|
58
63
|
exchanges = list(trades.exchange.unique())
|
|
59
|
-
trades.loc[:, 'segment'] = np.where(
|
|
64
|
+
trades.loc[:, 'segment'] = np.where(
|
|
65
|
+
"PE" == trades.tradingsymbol.str[-2:], "PE", "CE")
|
|
60
66
|
|
|
61
67
|
trades.loc[:, 'hour'] = trades.date.dt.hour
|
|
62
68
|
trades.loc[:, "day_of_week"] = trades.date.dt.day_name()
|
|
@@ -85,18 +91,21 @@ class TradeLens:
|
|
|
85
91
|
print("Trade return by time")
|
|
86
92
|
print(trades.groupby('time').trade_return.mean())
|
|
87
93
|
|
|
88
|
-
trades.loc[:, 'trade_return'] = trades.close_price /
|
|
94
|
+
trades.loc[:, 'trade_return'] = trades.close_price / \
|
|
95
|
+
trades.entry_price - 1
|
|
89
96
|
print("Mean return of trades")
|
|
90
97
|
print(trades.trade_return.mean())
|
|
91
98
|
|
|
92
|
-
trades.loc[:, 'week_number'] = (
|
|
99
|
+
trades.loc[:, 'week_number'] = (
|
|
100
|
+
trades.order_timestamp.dt.day / 7).astype(int)
|
|
93
101
|
if "week_number" not in disable_metrics:
|
|
94
102
|
print("profit by week number")
|
|
95
103
|
print(trades.groupby('week_number').profit.mean())
|
|
96
104
|
|
|
97
105
|
@staticmethod
|
|
98
106
|
def show_report(trades):
|
|
99
|
-
trades.loc[:, 'order_timestamp'] = pd.to_datetime(
|
|
107
|
+
trades.loc[:, 'order_timestamp'] = pd.to_datetime(
|
|
108
|
+
trades.order_timestamp)
|
|
100
109
|
VisualReport.display_profit_report(trades)
|
|
101
110
|
VisualReport.display_balance_report(trades, 'tt')
|
|
102
111
|
|
|
@@ -106,7 +115,8 @@ class TradeLens:
|
|
|
106
115
|
symbols_by_security_type = {}
|
|
107
116
|
for security_type in security_types:
|
|
108
117
|
symbols_by_security_type[security_type] = list(
|
|
109
|
-
trades[trades.security_type ==
|
|
118
|
+
trades[trades.security_type ==
|
|
119
|
+
security_type].tradingsymbol.unique()
|
|
110
120
|
)
|
|
111
121
|
|
|
112
122
|
market_data = market.data(
|
|
@@ -130,7 +140,8 @@ class TradeLens:
|
|
|
130
140
|
testing = pd.concat([testing, t_df])
|
|
131
141
|
testing = testing.sort_values(["symbol", "date"])
|
|
132
142
|
testing.loc[:, 'date_only'] = pd.to_datetime(testing.date.dt.date)
|
|
133
|
-
testing.loc[:, 'pnl'] = testing.groupby(
|
|
143
|
+
testing.loc[:, 'pnl'] = testing.groupby(
|
|
144
|
+
['symbol', 'date_only']).pnl.ffill()
|
|
134
145
|
|
|
135
146
|
testing = testing.groupby('date').pnl.sum().reset_index()
|
|
136
147
|
|
|
@@ -138,8 +149,8 @@ class TradeLens:
|
|
|
138
149
|
plt.plot(testing.date, testing.pnl)
|
|
139
150
|
plt.show(block=True)
|
|
140
151
|
return {
|
|
141
|
-
"minimum_pnl"
|
|
142
|
-
"maximum_pnl"
|
|
152
|
+
"minimum_pnl": int(testing.pnl.min()),
|
|
153
|
+
"maximum_pnl": int(testing.pnl.max())
|
|
143
154
|
}
|
|
144
155
|
|
|
145
156
|
@staticmethod
|
|
@@ -163,11 +174,11 @@ class TradeLens:
|
|
|
163
174
|
trade_data = trade_data[trade_data.date < trade_data.closing_timestamp]
|
|
164
175
|
trade_data.loc[:, 'close'] = np.where(
|
|
165
176
|
((trade_data.transaction_type == "SELL") & (trade_data.close > trade_data.close_price) & (
|
|
166
|
-
|
|
177
|
+
trade_data.date >= trade_data.closing_timestamp)),
|
|
167
178
|
trade_data.close_price, trade_data.close)
|
|
168
179
|
trade_data.loc[:, 'close'] = np.where(
|
|
169
180
|
((trade_data.transaction_type == "BUY") & (trade_data.close < trade_data.close_price) & (
|
|
170
|
-
|
|
181
|
+
trade_data.date >= trade_data.closing_timestamp)),
|
|
171
182
|
trade_data.close_price, trade_data.close)
|
|
172
183
|
trade_data.loc[:, 'pnl'] = np.where(trade_data.transaction_type == "SELL",
|
|
173
184
|
trade_data.entry_price - trade_data.close,
|
|
@@ -180,10 +191,103 @@ class TradeLens:
|
|
|
180
191
|
date_only = str(check_date).split("T")[0]
|
|
181
192
|
response = TradeLens.plot_pnl(trade_data, date_only)
|
|
182
193
|
trade_analysis.append({
|
|
183
|
-
"date_only"
|
|
184
|
-
"backtesting_pnl"
|
|
185
|
-
"minimum_pnl"
|
|
194
|
+
"date_only": date_only,
|
|
195
|
+
"backtesting_pnl": trades[trades.date_only.astype(str) == date_only].profit.sum(),
|
|
196
|
+
"minimum_pnl": response["minimum_pnl"]
|
|
186
197
|
})
|
|
187
198
|
|
|
188
199
|
return pd.DataFrame(trade_analysis)
|
|
189
200
|
|
|
201
|
+
def alpha_runner(alpha: typing.Callable, day_candles: pd.DataFrame):
|
|
202
|
+
"""
|
|
203
|
+
Passes Required Parameters to the alpha function
|
|
204
|
+
"""
|
|
205
|
+
return alpha(
|
|
206
|
+
open=day_candles.open,
|
|
207
|
+
low=day_candles.low,
|
|
208
|
+
high=day_candles.high,
|
|
209
|
+
close=day_candles.close,
|
|
210
|
+
volume=day_candles.volume,
|
|
211
|
+
vwap=day_candles.vwap,
|
|
212
|
+
returns=day_candles.returns,
|
|
213
|
+
adv5=day_candles.adv5,
|
|
214
|
+
adv10=day_candles.adv10,
|
|
215
|
+
adv15=day_candles.adv15,
|
|
216
|
+
adv20=day_candles.adv20,
|
|
217
|
+
adv30=day_candles.adv30,
|
|
218
|
+
adv40=day_candles.adv40,
|
|
219
|
+
adv50=day_candles.adv50,
|
|
220
|
+
adv60=day_candles.adv60,
|
|
221
|
+
adv81=day_candles.adv81,
|
|
222
|
+
adv120=day_candles.adv120,
|
|
223
|
+
adv150=day_candles.adv150,
|
|
224
|
+
adv180=day_candles.adv180,
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
@staticmethod
|
|
229
|
+
def validate_alpha(self, day_candles, alpha, num_buckets=10):
|
|
230
|
+
"""Validate alphas by bucketing them into 10 buckets and checking the returns
|
|
231
|
+
|
|
232
|
+
Args:
|
|
233
|
+
day_candles (DataFrame): Dataframe containing day candles
|
|
234
|
+
alpha (Function): function for calculating alpha
|
|
235
|
+
num_buckets (int, optional): No of brackets required. Defaults to 10.
|
|
236
|
+
"""
|
|
237
|
+
try:
|
|
238
|
+
alpha_name = alpha.__name__
|
|
239
|
+
alpha_bucket_name = "{}_bucket".format(alpha_name)
|
|
240
|
+
|
|
241
|
+
alpha_candles = day_candles[["date"]]
|
|
242
|
+
|
|
243
|
+
alpha_candles.loc[:, alpha_name] = self.alpha_runner(alpha=alpha, day_candles=day_candles)
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
alpha_candles.loc[:, f"{alpha_name}_rank"] = alpha_candles.groupby("date")[
|
|
247
|
+
alpha_name
|
|
248
|
+
].rank(ascending=False)
|
|
249
|
+
|
|
250
|
+
alpha_candles.loc[:, "is_top500"] = np.where(
|
|
251
|
+
(alpha_candles[f"{alpha_name}_rank"] <= 500), True, False
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
alpha_candles.loc[:, "intraday_return"] = (
|
|
255
|
+
day_candles.close / day_candles.open - 1
|
|
256
|
+
)
|
|
257
|
+
alpha_candles.loc[
|
|
258
|
+
:, "next_day_intraday_return"
|
|
259
|
+
] = alpha_candles.intraday_return.shift(-1)
|
|
260
|
+
|
|
261
|
+
alpha_candles.loc[:, alpha_bucket_name] = 1 + 10 * alpha_candles.groupby(
|
|
262
|
+
["is_top500", "date"]
|
|
263
|
+
)[alpha_name].rank(method="first", pct=True)
|
|
264
|
+
|
|
265
|
+
alpha_candles.loc[:, alpha_bucket_name] = np.where(
|
|
266
|
+
alpha_candles["is_top500"] == False,
|
|
267
|
+
np.nan,
|
|
268
|
+
alpha_candles[alpha_bucket_name],
|
|
269
|
+
)
|
|
270
|
+
|
|
271
|
+
alpha_candles.loc[:, alpha_bucket_name] = (
|
|
272
|
+
alpha_candles[alpha_bucket_name]
|
|
273
|
+
.replace([np.inf, -np.inf, np.nan], 0)
|
|
274
|
+
.astype(int)
|
|
275
|
+
.replace([0], np.nan)
|
|
276
|
+
.replace([num_buckets + 1], num_buckets)
|
|
277
|
+
)
|
|
278
|
+
|
|
279
|
+
# plotting
|
|
280
|
+
t_df = (
|
|
281
|
+
alpha_candles.groupby(alpha_bucket_name)
|
|
282
|
+
.next_day_intraday_return.mean()
|
|
283
|
+
.reset_index()
|
|
284
|
+
)
|
|
285
|
+
|
|
286
|
+
plt.clf()
|
|
287
|
+
plt.title(alpha_name)
|
|
288
|
+
plt.bar(t_df[alpha_bucket_name], -1 *
|
|
289
|
+
t_df.next_day_intraday_return)
|
|
290
|
+
plt.show()
|
|
291
|
+
|
|
292
|
+
except Exception as e:
|
|
293
|
+
print(alpha, inspect.signature(alpha), e)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{quantplay-1.2.89 → quantplay-1.2.92}/quantplay/strategies/options/intraday/short_straddle.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|