Skip to content

Commit e8b8971

Browse files
restore csv to git from lfs
1 parent d1f38e5 commit e8b8971

17 files changed

+217
-535
lines changed

sysdata/arctic/__init__.py

Whitespace-only changes.

sysdata/arctic/futures_contracts.py

Whitespace-only changes.

sysdata/csv/__init__.py

Whitespace-only changes.

sysdata/csvdata.py renamed to sysdata/csv/csvfuturesdata.py

-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ def __init__(self, datapath=None, absolute_datapath=None):
6464
else:
6565
pyst_dir = os.path.dirname(os.path.dirname(sysdata.__file__) )
6666
resolved_datapath = os.path.join(pyst_dir,'data', 'futures','legacycsv')
67-
print ('using ' + resolved_datapath)
68-
# resolved_datapath = get_pathname_for_package(LEGACY_DATA_PATH)
6967
"""
7068
Most Data objects that read data from a specific place have a 'source' of some kind
7169
Here it's a directory

sysdata/futures/__init__.py

Whitespace-only changes.

sysdata/futures/futuresDataForSim.py

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
import pandas as pd
3+
4+
from sysdata.data import Data
5+
6+
class FuturesData(Data):
7+
"""
8+
Get futures specific data used for simulation and signal generation eg just adjusted prices and data for carry
9+
10+
Extends the Data class to add additional features for asset specific
11+
12+
Will normally be overriden by a method for a specific data source eg csv or arctic
13+
See legacy.py
14+
15+
"""
16+
17+
def __repr__(self):
18+
return "FuturesData object with %d instruments" % len(
19+
self.get_instrument_list())
20+
21+
def get_instrument_raw_carry_data(self, instrument_code):
22+
"""
23+
Returns a pd. dataframe with the 4 columns PRICE, CARRY, PRICE_CONTRACT, CARRY_CONTRACT
24+
25+
These are specifically needed for futures trading
26+
27+
For other asset classes we'd probably pop in eg equities fundamental data, FX interest rates...
28+
29+
Normally we'd inherit from this method for a specific data source
30+
31+
:param instrument_code: instrument to get carry data for
32+
:type instrument_code: str
33+
34+
:returns: pd.DataFrame
35+
36+
"""
37+
# Default method to get instrument price
38+
# Will usually be overriden when inherited with specific data source
39+
error_msg = "You have created a FuturesData() object or you probably need to replace this method to do anything useful"
40+
self.log.critical(error_msg)
41+
42+
43+
44+
45+
46+
47+
48+
if __name__ == '__main__':
49+
import doctest
50+
doctest.testmod()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import pandas as pd
2+
from sysdata.data import baseData
3+
4+
class futuresData(pd.DataFrame):
5+
"""
6+
Data frame in specific format containing per contract information
7+
"""
8+
9+
def __init__(self, data):
10+
11+
data_present = list(data.columns)
12+
data_present.sort()
13+
14+
try:
15+
assert data_present == ['OPEN', 'CLOSE', 'HIGH', 'LOW', 'SETTLE', 'VOLUME', 'OPEN_INTEREST']
16+
except AssertionError:
17+
raise Exception("futuresData has to conform to pattern")
18+
19+
super().__init__(data)
20+
21+
22+
23+
class futuresContractPriceData(baseData):
24+
"""
25+
Extends the baseData object to a data source that reads in prices for specific futures contracts
26+
27+
This would normally be extended further for information from a specific source eg quandl, mongodb
28+
"""
29+
30+
def __repr__(self):
31+
return "Individual futures prices"
32+
33+
def __getitem__(self, keyname):
34+
"""
35+
convenience method to get the price, make it look like a dict
36+
37+
:param keyname: instrument to get prices for
38+
:type keyname: str
39+
40+
:returns: pd.DataFrame
41+
"""
42+
43+
raise Exception("__getitem__ not defined for baseData class: use a class where it has been overriden")
44+
45+
46+
def keys(self):
47+
"""
48+
list of things in this data set (futures contracts, instruments...)
49+
50+
:returns: list of str
51+
52+
>>> data=Data()
53+
>>> data.keys()
54+
[]
55+
"""
56+
return []
57+

sysdata/futures/instruments.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
Read / write and represent instrument data
3+
"""
4+
5+
class futuresInstrument(object):
6+
"""
7+
Define a generic instrument
8+
"""
9+
10+
def __init__(self, instrument_code, **ignored_kwargs):
11+
"""
12+
Create a new instrument
13+
14+
:param instrument_code: The name of the contract
15+
:param rollcycle: The roll cycle
16+
:param ignored_kwargs: Stuff that might be passed by accident
17+
"""
18+
assert type(instrument_code) is str
19+
20+
self.instrument_code = instrument_code
21+
22+
def __repr__(self):
23+
return self.instrument_code
24+

0 commit comments

Comments
 (0)