forked from robcarver17/pysystemtrade
-
Notifications
You must be signed in to change notification settings - Fork 0
/
basesystem.py
88 lines (67 loc) · 2.33 KB
/
basesystem.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
"""
This is a futures system
A system consists of a system, plus a config
"""
from syscore.constants import arg_not_supplied
from sysdata.sim.csv_futures_sim_data import csvFuturesSimData
from sysdata.config.configdata import Config
from systems.forecasting import Rules
from systems.basesystem import System
from systems.forecast_combine import ForecastCombine
from systems.forecast_scale_cap import ForecastScaleCap
from systems.rawdata import RawData
from systems.positionsizing import PositionSizing
from systems.portfolio import Portfolios
from systems.accounts.accounts_stage import Account
def futures_system(
data=arg_not_supplied,
config=arg_not_supplied,
trading_rules=arg_not_supplied,
):
"""
:param data: data object (defaults to reading from csv files)
:type data: sysdata.data.simData, or anything that inherits from it
:param config: Configuration object (defaults to futuresconfig.yaml in this directory)
:type config: sysdata.configdata.Config
:param trading_rules: Set of trading rules to use (defaults to set specified in config object)
:type trading_rules: list or dict of TradingRules, or something that can be parsed to that
>>> system=futures_system()
>>> system
System with stages: accounts, portfolio, positionSize, rawdata, combForecast, forecastScaleCap, rules
>>> system.rules.get_raw_forecast("EDOLLAR", "ewmac2_8").dropna().head(2)
ewmac2_8
1983-10-10 0.695929
1983-10-11 -0.604704
ewmac2_8
2015-04-21 0.172416
2015-04-22 -0.477559
>>> system.rules.get_raw_forecast("EDOLLAR", "carry").dropna().head(2)
carry
1983-10-10 0.952297
1983-10-11 0.854075
carry
2015-04-21 0.350892
2015-04-22 0.350892
"""
if data is arg_not_supplied:
data = csvFuturesSimData()
if config is arg_not_supplied:
config = Config("systems.provided.futures_chapter15.futuresconfig.yaml")
rules = Rules(trading_rules)
system = System(
[
Account(),
Portfolios(),
PositionSizing(),
RawData(),
ForecastCombine(),
ForecastScaleCap(),
rules,
],
data,
config,
)
return system
if __name__ == "__main__":
import doctest
doctest.testmod()