forked from robcarver17/pysystemtrade
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_instrument_lists.py
102 lines (82 loc) · 3.38 KB
/
check_instrument_lists.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
"""
This little utility allows you to keep up with your various sets of instruments, basically designed for those that add a
big load of instruments in one go as is my wont
"""
import pandas as pd
from syscore.interactive.progress_bar import progressBar
from sysproduction.data.prices import diagPrices
from sysproduction.data.instruments import diagInstruments
from systems.provided.rob_system.run_system import (
futures_system,
) ## replace with your own
diag_prices = diagPrices()
all_instruments_with_prices = diag_prices.get_list_of_instruments_with_contract_prices()
all_instruments_with_prices.sort()
## check for high correlations, likely to be repeats
def check_for_high_correlations():
checked = []
all_dups = []
returns = dict()
p = progressBar((len(all_instruments_with_prices) ** 2) / 2)
for instrument1 in all_instruments_with_prices:
if instrument1 not in returns.keys():
returns[instrument1] = weekly_perc_returns_last_year(instrument1)
for instrument2 in all_instruments_with_prices:
if instrument1 == instrument2:
continue
if (instrument2, instrument1) in checked:
continue
checked.append((instrument1, instrument2))
if instrument2 not in returns.keys():
returns[instrument2] = weekly_perc_returns_last_year(instrument2)
ret1 = returns[instrument1]
ret2 = returns[instrument2]
both = pd.concat([ret1, ret2], axis=1)
both.columns = ["1", "2"]
both = both.dropna()
corr = both.corr()["1"]["2"]
if corr > 0.9:
all_dups.append(
"Possible duplicates %s %s corr %.3f"
% (instrument1, instrument2, corr)
)
print(all_dups)
p.iterate()
return all_dups
def weekly_perc_returns_last_year(instrument_code):
weekly_prices = (
diag_prices.get_adjusted_prices(instrument_code).resample("1W").ffill()
)
weekly_prices_last_year = weekly_prices[-52:]
return (weekly_prices_last_year / weekly_prices_last_year.shift(1)) - 1
def check_for_zero_commission():
diag_instruments = diagInstruments()
zero_warnings = []
for instrument_code in all_instruments_with_prices:
commission = diag_instruments.get_cost_object(
instrument_code
).value_of_block_commission
if commission == 0:
zero_warnings.append(instrument_code)
return zero_warnings
def print_missing_and_no_trade_markets():
system = futures_system()
all_instruments = system.data.get_instrument_list()
duplicates = system.get_list_of_duplicate_instruments_to_remove()
ignored = system.get_list_of_ignored_instruments_to_remove()
all_instruments_without_duplicates = [
instrument_code
for instrument_code in all_instruments
if instrument_code not in duplicates and instrument_code not in ignored
]
configured_in_system = list(
system.config.instrument_weights.keys()
) ## not all will be traded
missing = [
instrument_code
for instrument_code in all_instruments_without_duplicates
if instrument_code not in configured_in_system
]
missing.sort()
print("Missing: %s" % missing)
print("No trade: %s" % system.get_list_of_markets_with_trading_restrictions())