Skip to content

Commit 27cbfa0

Browse files
author
todd
committed
Merge remote-tracking branch 'robcarver17/master' into missing-data
2 parents 740d984 + e6d8f16 commit 27cbfa0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1329
-881
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ Note that the large contract prices will continue to be updated (best to keep do
260260

261261
## Version 0.23.0
262262

263-
- 'get_filename_for_package' can now take absolute as well as relative paths, and can cope with separate file names
263+
- 'resolve_path_and_filename_for_package' can now take absolute as well as relative paths, and can cope with separate file names
264264
- Updated legacy .csv files
265265
- Fixed a few bugs
266266
- Can now get unexpired contracts for a given instrument using 'contractDateWithRollParameters.get_unexpired_contracts_from_now_to_contract_date()'

CONTRIBUTING.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ In general, we try and follow the original texts: [PEP 8](https://peps.python.or
5656

5757
### General
5858

59-
- Unless there is a single parameter, parameters should be explicit.
60-
- Type hints should be used, with Unions if required `from typing import Union`
61-
59+
- Unless there is a single parameter, passed parameters should be explicit.
60+
- Type hints should be used, with Unions if required `from typing import Union` and Lists / Dicts ...`from typing import List, Dict`
61+
- Verbose doc strings specifying all the parameters are no longer required (superseded by type hints)
6262

6363
### Naming conventions
6464

docs/backtesting.md

+15-15
Original file line numberDiff line numberDiff line change
@@ -1436,17 +1436,17 @@ You can also save a config object into a yaml file:
14361436
```python
14371437
from systems.provided.futures_chapter15.basesystem import futures_system
14381438
import yaml
1439-
from syscore.fileutils import get_filename_for_package
1439+
from syscore.fileutils import resolve_path_and_filename_for_package
14401440

1441-
system=futures_system()
1442-
my_config=system.config
1441+
system = futures_system()
1442+
my_config = system.config
14431443

14441444
## make some changes to my_config here
14451445

1446-
filename=get_filename_for_package("private.this_system_name.config.yaml")
1446+
filename = resolve_path_and_filename_for_package("private.this_system_name.config.yaml")
14471447

14481448
with open(filename, 'w') as outfile:
1449-
outfile.write( yaml.dump(my_config, default_flow_style=True) )
1449+
outfile.write(yaml.dump(my_config, default_flow_style=True))
14501450
```
14511451

14521452
This is useful if you've been playing with a backtest configuration, and want
@@ -3794,24 +3794,24 @@ There are a number of different ways one might want to specify path and file nam
37943794
For convenience I have written some functions that translate betweeen these different formats, and the underlying OS representation.
37953795

37963796
```python
3797-
from syscore.fileutils import get_resolved_pathname, get_filename_for_package
3797+
from syscore.fileutils import get_resolved_pathname, resolve_path_and_filename_for_package
37983798

37993799
# Resolve both filename and pathname jointly. Useful when writing the name of eg a configuration file
38003800
## Absolute format
38013801
### Windows (note use of double backslash in str) Make sure you include the initial backslash, or will be treated as relative format
3802-
get_filename_for_package("\\home\\rob\\file.csv")
3802+
resolve_path_and_filename_for_package("\\home\\rob\\file.csv")
38033803

38043804
### Unix. Make sure you include the initial forward slash,
3805-
get_filename_for_package("/home/rob/file.csv")
3805+
resolve_path_and_filename_for_package("/home/rob/file.csv")
38063806

38073807
## Relative format to find a file in the installed pysystemtrade
38083808
### Dot format. Notice there is no initial 'dot' and we don't need to include 'pysystemtrade'
3809-
get_filename_for_package("syscore.tests.pricedata.csv")
3809+
resolve_path_and_filename_for_package("syscore.tests.pricedata.csv")
38103810

38113811
# Specify the path and filename separately
3812-
get_filename_for_package("\\home\\rob","file.csv")
3813-
get_filename_for_package("/home/rob","file.csv")
3814-
get_filename_for_package("syscore.tests","pricedata.csv")
3812+
resolve_path_and_filename_for_package("\\home\\rob", "file.csv")
3813+
resolve_path_and_filename_for_package("/home/rob", "file.csv")
3814+
resolve_path_and_filename_for_package("syscore.tests", "pricedata.csv")
38153815

38163816
# Resolve just the pathname
38173817
get_resolved_pathname("/home/rob")
@@ -3821,13 +3821,13 @@ get_resolved_pathname("syscore.tests")
38213821
## DON'T USE THESE:-
38223822
### It's possible to use Unix or Windows for relative filenames, but I prefer not to, so there is a clearer disctinction between absolute and relative.
38233823
### However this works:
3824-
get_filename_for_package("syscore/tests/pricedata.csv")
3824+
resolve_path_and_filename_for_package("syscore/tests/pricedata.csv")
38253825

38263826
### Similarly, I prefer not to use dot format for absolute filenames but it will work
3827-
get_filename_for_package(".home.rob.file.csv")
3827+
resolve_path_and_filename_for_package(".home.rob.file.csv")
38283828

38293829
### Finally, You can mix and match the above formats in a single string, but it won't make the code very readable!
3830-
get_filename_for_package("\\home/rob.file.csv")
3830+
resolve_path_and_filename_for_package("\\home/rob.file.csv")
38313831

38323832
```
38333833

docs/doc_generation/list_of_futures_product_pages_generator.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from pathlib import Path
2-
from syscore.fileutils import get_filename_for_package
2+
from syscore.fileutils import resolve_path_and_filename_for_package
33
from docs.doc_generation.symbol_product_page_map import symbol_product_page_map
44

55
# GET ABSOLUTE PATH TO THE DOCS MODULE
66
file_in_module_where_md_file_is_to_be_stored = "docs.__init__.py"
7-
full_path = get_filename_for_package(
8-
pathname=file_in_module_where_md_file_is_to_be_stored
7+
full_path = resolve_path_and_filename_for_package(
8+
path_and_filename=file_in_module_where_md_file_is_to_be_stored
99
)
1010
write_path = Path(full_path).parent
1111

docs/instruments.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,11 @@ system.get_list_of_bad_markets()
311311
```
312312

313313

314+
### Automatically excluded
315+
316+
It's also possible that there are some instruments that have zero positions. The most likely explanation for this is that you have set a speed limit on trading costs, and there are no trading rules that are cheap enough to trade the given instrument. These are automatically added to the list of markets given a zero weight for optimisation.
317+
318+
314319
## Customising the list of 'all instruments' and 'excluded for optimisation'
315320

316321
If you make two calls to system *before you do anything else with a system* you can decide exactly what is, or is not, included in the instrument lists. The following calls will reproduce the default system behaviour, but you can modify them if desired. IMPORTANT: they must be called in this order if you want to change the instrument_list() call.
@@ -337,7 +342,7 @@ system.get_list_of_markets_not_trading_but_with_data(
337342
```
338343

339344

340-
# Operating in production
345+
# Operating in production environment
341346

342347
Operating in the production environment is a bit more complex, due to the interaction of configuration files, the way that constraints operate, and the possibility of pulling in additional constraints from a database.
343348

sysbrokers/IB/client/ib_price_client.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from syscore.exceptions import missingContract, missingData
1313

1414
from syscore.dateutils import (
15-
adjust_timestamp_to_include_notional_close_and_time_offset,
15+
replace_midnight_with_notional_closing_time,
1616
strip_timezone_fromdatetime,
1717
Frequency,
1818
DAILY_PRICE_FREQ,
@@ -220,15 +220,12 @@ def _ib_timestamp_to_datetime(self, timestamp_ib) -> datetime.datetime:
220220
and adjusts yyyymm to closing vector
221221
222222
:param timestamp_str: datetime.datetime
223-
:return: pd.datetime
223+
:return: datetime.datetime
224224
"""
225225

226-
local_timestamp_ib = self._adjust_ib_time_to_local(timestamp_ib)
227-
timestamp = pd.to_datetime(local_timestamp_ib)
226+
timestamp = self._adjust_ib_time_to_local(timestamp_ib)
228227

229-
adjusted_ts = adjust_timestamp_to_include_notional_close_and_time_offset(
230-
timestamp
231-
)
228+
adjusted_ts = replace_midnight_with_notional_closing_time(timestamp)
232229

233230
return adjusted_ts
234231

sysbrokers/IB/ib_Fx_prices_data.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77

88
from sysobjects.spot_fx_prices import fxPrices
99
from syslogdiag.log_to_screen import logtoscreen
10-
from syscore.fileutils import get_filename_for_package
10+
from syscore.fileutils import resolve_path_and_filename_for_package
1111
from syscore.objects import missing_instrument, missing_file
1212

13-
IB_CCY_CONFIG_FILE = get_filename_for_package("sysbrokers.IB.ib_config_spot_FX.csv")
13+
IB_CCY_CONFIG_FILE = resolve_path_and_filename_for_package(
14+
"sysbrokers.IB.ib_config_spot_FX.csv"
15+
)
1416

1517
ibFXConfig = namedtuple("ibFXConfig", ["ccy1", "ccy2", "invert"])
1618

sysbrokers/IB/ib_instruments_data.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@
88
from sysbrokers.IB.ib_connection import connectionIB
99
from sysbrokers.broker_instrument_data import brokerFuturesInstrumentData
1010

11-
from syscore.fileutils import get_filename_for_package
12-
from syscore.genutils import value_or_npnan
11+
from syscore.fileutils import resolve_path_and_filename_for_package
12+
from syscore.genutils import return_another_value_if_nan
1313
from syscore.objects import missing_instrument, missing_file
1414

1515
from sysobjects.instruments import futuresInstrument
1616

1717
from syslogdiag.log_to_screen import logtoscreen
1818

19-
IB_FUTURES_CONFIG_FILE = get_filename_for_package("sysbrokers.IB.ib_config_futures.csv")
19+
IB_FUTURES_CONFIG_FILE = resolve_path_and_filename_for_package(
20+
"sysbrokers.IB.ib_config_futures.csv"
21+
)
2022

2123

2224
class IBconfig(pd.DataFrame):
@@ -171,11 +173,11 @@ def get_instrument_object_from_config(
171173
config_row = config[config.Instrument == instrument_code]
172174
symbol = config_row.IBSymbol.values[0]
173175
exchange = config_row.IBExchange.values[0]
174-
currency = value_or_npnan(config_row.IBCurrency.values[0], NOT_REQUIRED_FOR_IB)
175-
ib_multiplier = value_or_npnan(
176+
currency = return_another_value_if_nan(config_row.IBCurrency.values[0], NOT_REQUIRED_FOR_IB)
177+
ib_multiplier = return_another_value_if_nan(
176178
config_row.IBMultiplier.values[0], NOT_REQUIRED_FOR_IB
177179
)
178-
price_magnifier = value_or_npnan(config_row.priceMagnifier.values[0], 1.0)
180+
price_magnifier = return_another_value_if_nan(config_row.priceMagnifier.values[0], 1.0)
179181
ignore_weekly = config_row.IgnoreWeekly.values[0]
180182

181183
# We use the flexibility of futuresInstrument to add additional arguments

sysbrokers/IB/ib_trading_hours.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
tradingHours,
77
listOfTradingHours,
88
)
9-
from syscore.fileutils import does_file_exist
9+
from syscore.fileutils import does_filename_exist
1010
from sysdata.config.production_config import get_production_config
1111
from sysdata.production.trading_hours import read_trading_hours
1212

@@ -17,7 +17,7 @@
1717

1818

1919
def get_saved_trading_hours():
20-
if does_file_exist(PRIVATE_CONFIG_TRADING_HOURS_FILE):
20+
if does_filename_exist(PRIVATE_CONFIG_TRADING_HOURS_FILE):
2121
return read_trading_hours(PRIVATE_CONFIG_TRADING_HOURS_FILE)
2222
else:
2323
return read_trading_hours(IB_CONFIG_TRADING_HOURS_FILE)

syscontrol/monitor.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import datetime
44
from sysdata.data_blob import dataBlob
55

6-
from syscore.fileutils import get_filename_for_package
6+
from syscore.fileutils import resolve_path_and_filename_for_package
77
from sysproduction.data.control_process import dataControlProcess
88
from sysproduction.data.control_process import diagControlProcess
9-
from syscore.dateutils import last_run_or_heartbeat_from_date_or_none
9+
from syscore.dateutils import date_as_short_pattern_or_question_if_missing
1010
from syscontrol.list_running_pids import describe_trading_server_login_data
1111

1212

@@ -83,7 +83,7 @@ def send_update_message(self, process_name, current_status, new_status):
8383
process_name,
8484
current_status,
8585
new_status,
86-
last_run_or_heartbeat_from_date_or_none(datetime.datetime.now()),
86+
date_as_short_pattern_or_question_if_missing(datetime.datetime.now()),
8787
)
8888
self.log_messages.append_msg(msg)
8989

@@ -123,7 +123,7 @@ def check_if_pid_running_and_if_not_finish(process_observatory: processMonitor):
123123

124124

125125
def generate_html(process_observatory: processMonitor):
126-
resolved_filename = get_filename_for_package(filename)
126+
resolved_filename = resolve_path_and_filename_for_package(filename)
127127
trading_server_description = describe_trading_server_login_data()
128128
dbase_description = str(process_observatory.data.mongo_db)
129129
with open(resolved_filename, "w") as file:

0 commit comments

Comments
 (0)