From 04b8f2a6dcf062b0caf627c12f298b13aa886568 Mon Sep 17 00:00:00 2001 From: Enzo Busseti Date: Sat, 30 Dec 2023 03:08:09 +0400 Subject: [PATCH] Added sp500_daily strategy, cleanups --- TODOs_ROADMAP.rst | 41 +- cvxportfolio/data.py | 19 +- cvxportfolio/result.py | 2 +- cvxportfolio/simulator.py | 4 + docs/result.rst | 2 +- examples/strategies/dow30_daily.py | 1 - examples/strategies/sp500_daily.py | 94 ++++ .../sp500_daily_hyper_parameters.json | 6 + .../sp500_daily_initial_holdings.json | 508 ++++++++++++++++++ .../sp500_daily_target_weights.json | 508 ++++++++++++++++++ examples/strategies/strategy_executor.py | 21 +- strategies_runner.sh | 8 +- 12 files changed, 1184 insertions(+), 30 deletions(-) create mode 100644 examples/strategies/sp500_daily.py create mode 100644 examples/strategies/sp500_daily_hyper_parameters.json create mode 100644 examples/strategies/sp500_daily_initial_holdings.json create mode 100644 examples/strategies/sp500_daily_target_weights.json diff --git a/TODOs_ROADMAP.rst b/TODOs_ROADMAP.rst index f7fd33779..18636a88d 100644 --- a/TODOs_ROADMAP.rst +++ b/TODOs_ROADMAP.rst @@ -45,7 +45,7 @@ their planned release. -------------------------- - [ ] ``DataEstimator`` needs refactoring, too long and complex methods. Target - ``1.0.4``. + ``1.1.1``. - ``Estimator`` could define base logic for on-disk caching. By itself it wouldn't do anything, actual functionality implemented by forecasters' base class. @@ -71,10 +71,9 @@ Partially public; only ``cvx.Gamma()`` (no arguments) and ``optimize_hyperparame (simple usage) are public, all the rest is not. - [ ] Clean up interface w/ ``MarketSimulator``, right now it calls private - methods, maybe enough to make them public. Target ``1.0.4``. + methods, maybe enough to make them public. Target ``1.1.1``. - [ ] Add risk/fine default ``GammaTrade``, ``GammaRisk`` (which are - ``RangeHyperParameter``) modeled after original examples from paper. - Target ``1.1.0``. + ``RangeHyperParameter``) modeled after original examples from paper. - [ ] Add ``Constant`` internal object throughout the library, also in ``DataEstimator`` in the case of scalar; it resolves to ``current_value`` if you pass a hyper-parameter. - [ ] Distinguish integer and positive hyper-parameters (also enforced by Constant). @@ -90,14 +89,18 @@ Partially public; only ``cvx.Gamma()`` (no arguments) and ``optimize_hyperparame Optimization policies ~~~~~~~~~~~~~~~~~~~~~ -- [ ] Improve behavior for infeasibility/unboundedness/solver error. Target - ``1.1.0``. -- [ ] Improve ``__repr__`` method, now hard to read. Target ``1.0.4``. +- [ ] Improve behavior for infeasibility/unboundedness/solver error. Idea: + optimization policy gets arguments ``infeasible_fallback``, ... which are + policies (default to ``cvx.Hold``), problem is that this breaks + compatibility, it doesn't if we don't give defaults (so exceptions are raised + all the way to the caller), but then it's extra complication (more + arguments). Consider for ``2.0.0``. +- [ ] Improve ``__repr__`` method, now hard to read. Target ``1.1.1``. ``cvxportfolio.constraints`` ---------------------------- -- [ ] Add missing constraints from the paper. Target ``1.1.0``. +- [ ] Add missing constraints from the paper. - [ ] Make ``MarketNeutral`` accept arbitrary benchmark (policy object). ``cvxportfolio.result`` @@ -105,24 +108,31 @@ Optimization policies - [ ] Make ``BackTestResult`` interface methods with ``MarketSimulator`` public. -- [ ] Add a ``backruptcy`` property (boolean). Amend ``sharpe_ratio`` +- [ ] Add a ``bankruptcy`` property (boolean). Amend ``sharpe_ratio`` and other aggregate statistics (as best as possible) to return ``-np.inf`` if back-test ended in backruptcy. This is needed specifically for - hyper-parameter optimization. Target ``1.0.4``. -- [ ] Capture **logs** from the back-test; add ``logs`` property that returns - then as a string (newline separated, like a .log file). Make log level + hyper-parameter optimization. Target ``1.1.1``. +- [X] Capture **logs** from the back-test; add ``logs`` property that returns + them as a string (newline separated, like a .log file). Make log level changeable by a module constant (like ``cvxportfolio.result.LOG_LEVEL``) set to ``INFO`` by default. Then, improve logs throughout (informative, proactive on possible issues). Logs formatter should produce source module and timestamp. +Other +----- + +- [ ] Exceptions are not too good, probably ``cvxportfolio.DataError`` should + be ``ValueError``, .... Research this, one option is to simply derive from + built-ins (``class DataError(ValueError): pass``), .... No compatibility + breaks. Development & testing --------------------- - [ ] Add extra pylint checkers. - - [ ] Code complexity. Target ``1.0.4``. + - [ ] Code complexity. Target ``1.1.1``. - [ ] Consider removing downloaded data from ``test_simulator.py``, so only ``test_data.py`` requires internet. @@ -130,13 +140,12 @@ Documentation ------------- - [ ] Improve examples section, also how "Hello world" is mentioned in readme. - Target ``1.0.4``, PR #118. - [ ] Manual. - [ ] Quickstart, probably to merge into manual. Examples -------- -- [ ] Restore examples from paper. Target ``1.0.4``, PR #118. -- [ ] Expose more (all?) examples through HTML docs. Target ``1.0.4``, PR #118. +- [ ] Finish restore examples from paper. Target ``1.1.1``. +- [ ] Expose more (all?) examples through HTML docs. - [ ] Consider making examples a package that can be pip installed. diff --git a/cvxportfolio/data.py b/cvxportfolio/data.py index 2367d365d..c19e1f404 100644 --- a/cvxportfolio/data.py +++ b/cvxportfolio/data.py @@ -803,6 +803,16 @@ def partial_universe_signature(self, partial_universe): """ return None +# compiled based on Interactive Brokers benchmark rates choices +# (see https://www.ibkrguides.com/kb/article-2949.htm) +# and their FRED codes +RATES = { + 'USDOLLAR': 'DFF', # Federal funds effective rate + 'EURO': 'ECBESTRVOLWGTTRMDMNRT', # BCE short term rate + 'GBPOUND': 'IUDSOIA', # SONIA + 'JPYEN': 'IRSTCB01JPM156N', # updated monthly + } + class MarketDataInMemory(MarketData): """Market data that is stored in memory when initialized.""" @@ -919,9 +929,10 @@ def _add_cash_column(self, cash_key, grace_period): objective term. """ - if not cash_key == 'USDOLLAR': + if not cash_key in RATES: raise NotImplementedError( - 'Currently the only data pipeline built is for USDOLLAR cash') + 'Currently the only data pipelines built are for cash_key' + f' in {list(RATES)}') if self.returns.index.tz is None: raise DataError( @@ -937,7 +948,9 @@ def _add_cash_column(self, cash_key, grace_period): + " its name.") data = Fred( - 'DFF', base_location=self.base_location, grace_period=grace_period) + RATES[cash_key], base_location=self.base_location, + grace_period=grace_period) + cash_returns_per_period = resample_returns( data.data/100, periods=self.periods_per_year) diff --git a/cvxportfolio/result.py b/cvxportfolio/result.py index 18454d7d1..e64862ddb 100644 --- a/cvxportfolio/result.py +++ b/cvxportfolio/result.py @@ -233,7 +233,7 @@ def _log_final(self, t, t_next, h, extra_simulator_time): # @property - def log(self): + def logs(self): """Logs from the policy, simulator, market data server, .... :return: Logs produced during the back-test, newline separated. diff --git a/cvxportfolio/simulator.py b/cvxportfolio/simulator.py index 0b630788e..f88bb87dc 100644 --- a/cvxportfolio/simulator.py +++ b/cvxportfolio/simulator.py @@ -200,10 +200,13 @@ def simulate( # translate to weights current_portfolio_value = sum(h) + logger.info( + 'Portfolio value at time %s: %s', t, current_portfolio_value) current_weights = pd.to_numeric(h / current_portfolio_value) # evaluate the policy s = time.time() + logger.info('Evaluating the policy at time %s', t) policy_w = policy.values_in_time_recursive( t=t, current_weights=current_weights, current_portfolio_value=current_portfolio_value, @@ -482,6 +485,7 @@ def modify_orig_policy(target_policy): print('iteration', i) # print('Current optimal hyper-parameters:') # print(policy) + logger.info('Current policy: %s', policy) print('Current objective:') print(current_objective) # print() diff --git a/docs/result.rst b/docs/result.rst index 386475e66..5f3a8678e 100644 --- a/docs/result.rst +++ b/docs/result.rst @@ -88,7 +88,7 @@ Back-test result .. autoproperty:: simulator_times - .. autoproperty:: log + .. autoproperty:: logs .. automethod:: plot diff --git a/examples/strategies/dow30_daily.py b/examples/strategies/dow30_daily.py index cfaff8055..23f680847 100644 --- a/examples/strategies/dow30_daily.py +++ b/examples/strategies/dow30_daily.py @@ -100,7 +100,6 @@ def policy(gamma_risk, gamma_trade): research_sim.optimize_hyperparameters( research_policy, start_time=HYPERPAR_OPTIMIZE_START, objective='sharpe_ratio') - #objective='information_ratio') result_opt = research_sim.backtest( research_policy, start_time=HYPERPAR_OPTIMIZE_START) diff --git a/examples/strategies/sp500_daily.py b/examples/strategies/sp500_daily.py new file mode 100644 index 000000000..fede4ecf0 --- /dev/null +++ b/examples/strategies/sp500_daily.py @@ -0,0 +1,94 @@ +# Copyright 2023 Enzo Busseti +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""This is a simple example strategy which we run every day. + +It is a long-only, unit leverage, allocation on the Standard and Poor's 500 +universe. It's very similar to the two strategies ``dow30_daily`` and +``ndx100_daily``, but here we also constrain the allocation to be close +to our chosen benchmark, :class:`cvxportfolio.MarketBenchmark` (allocation +proportional to last year's total market volumes in dollars). + +This strategy also seems to have outperformed our benchmarks and an index ETF. +We will see how it performs online. + +You run it from the root of the repository in the development environment by: + +.. code:: bash + + python -m examples.strategies.sp500_daily +""" + +import cvxportfolio as cvx + +from ..universes import SP500 + +HYPERPAR_OPTIMIZE_START = '2023-01-01' + +OBJECTIVE = 'sharpe_ratio' + +def policy(gamma_risk, gamma_trade): + """Create fresh policy object, also return handles to hyper-parameters. + + :param gamma_risk: Risk aversion multiplier. + :type gamma_risk: float + :param gamma_trade: Transaction cost aversion multiplier. + :type gamma_trade: float, optional + + :return: Policy object and dictionary mapping hyper-parameter names (which + must match the arguments of this function) to their respective objects. + :rtype: tuple + """ + gamma_risk_hp = cvx.Gamma(initial_value=gamma_risk) + gamma_trade_hp = cvx.Gamma(initial_value=gamma_trade) + return cvx.SinglePeriodOptimization( + cvx.ReturnsForecast() + - gamma_risk_hp * cvx.FullCovariance() + - gamma_trade_hp * cvx.StocksTransactionCost(), + [cvx.LongOnly(), cvx.LeverageLimit(1), + cvx.MaxBenchmarkDeviation(0.05), + cvx.MinBenchmarkDeviation(-0.05)], + benchmark=cvx.MarketBenchmark(), + ignore_dpp=True, + ), {'gamma_risk': gamma_risk_hp, 'gamma_trade': gamma_trade_hp} + + +if __name__ == '__main__': + + RESEARCH = False + + if RESEARCH: + INDEX_ETF = 'SPY' + + research_sim = cvx.StockMarketSimulator(SP500) + + result_unif = research_sim.backtest( + cvx.Uniform(), start_time=HYPERPAR_OPTIMIZE_START) + print('uniform') + print(result_unif) + + result_market = research_sim.backtest( + cvx.MarketBenchmark(), start_time=HYPERPAR_OPTIMIZE_START) + print('market') + print(result_market) + + result_etf = cvx.StockMarketSimulator([INDEX_ETF]).backtest( + cvx.Uniform(), start_time=HYPERPAR_OPTIMIZE_START) + print(INDEX_ETF) + print(result_etf) + + from .strategy_executor import main + main(policy=policy, hyperparameter_opt_start=HYPERPAR_OPTIMIZE_START, + objective=OBJECTIVE, universe=SP500, initial_values={ + 'gamma_risk': 30., 'gamma_trade': 1. + }) diff --git a/examples/strategies/sp500_daily_hyper_parameters.json b/examples/strategies/sp500_daily_hyper_parameters.json new file mode 100644 index 000000000..4bc343519 --- /dev/null +++ b/examples/strategies/sp500_daily_hyper_parameters.json @@ -0,0 +1,6 @@ +{ + "2023-12-29 14:30:00+00:00": { + "gamma_risk": 58.46151300000004, + "gamma_trade": 1.9487171000000012 + } +} \ No newline at end of file diff --git a/examples/strategies/sp500_daily_initial_holdings.json b/examples/strategies/sp500_daily_initial_holdings.json new file mode 100644 index 000000000..3bd4045b2 --- /dev/null +++ b/examples/strategies/sp500_daily_initial_holdings.json @@ -0,0 +1,508 @@ +{ + "2023-12-29 14:30:00+00:00": { + "A": 0.0, + "AAL": 0.0, + "AAPL": 0.0, + "ABBV": 0.0, + "ABNB": 0.0, + "ABT": 0.0, + "ACGL": 0.0, + "ACN": 0.0, + "ADBE": 0.0, + "ADI": 0.0, + "ADM": 0.0, + "ADP": 0.0, + "ADSK": 0.0, + "AEE": 0.0, + "AEP": 0.0, + "AES": 0.0, + "AFL": 0.0, + "AIG": 0.0, + "AIZ": 0.0, + "AJG": 0.0, + "AKAM": 0.0, + "ALB": 0.0, + "ALGN": 0.0, + "ALL": 0.0, + "ALLE": 0.0, + "AMAT": 0.0, + "AMCR": 0.0, + "AMD": 0.0, + "AME": 0.0, + "AMGN": 0.0, + "AMP": 0.0, + "AMT": 0.0, + "AMZN": 0.0, + "ANET": 0.0, + "ANSS": 0.0, + "AON": 0.0, + "AOS": 0.0, + "APA": 0.0, + "APD": 0.0, + "APH": 0.0, + "APTV": 0.0, + "ARE": 0.0, + "ATO": 0.0, + "AVB": 0.0, + "AVGO": 0.0, + "AVY": 0.0, + "AWK": 0.0, + "AXON": 0.0, + "AXP": 0.0, + "AZO": 0.0, + "BA": 0.0, + "BAC": 0.0, + "BALL": 0.0, + "BAX": 0.0, + "BBWI": 0.0, + "BBY": 0.0, + "BDX": 0.0, + "BEN": 0.0, + "BF-B": 0.0, + "BG": 0.0, + "BIIB": 0.0, + "BIO": 0.0, + "BK": 0.0, + "BKNG": 0.0, + "BKR": 0.0, + "BLDR": 0.0, + "BLK": 0.0, + "BMY": 0.0, + "BR": 0.0, + "BRK-B": 0.0, + "BRO": 0.0, + "BSX": 0.0, + "BWA": 0.0, + "BX": 0.0, + "BXP": 0.0, + "C": 0.0, + "CAG": 0.0, + "CAH": 0.0, + "CARR": 0.0, + "CAT": 0.0, + "CB": 0.0, + "CBOE": 0.0, + "CBRE": 0.0, + "CCI": 0.0, + "CCL": 0.0, + "CDAY": 0.0, + "CDNS": 0.0, + "CDW": 0.0, + "CE": 0.0, + "CEG": 0.0, + "CF": 0.0, + "CFG": 0.0, + "CHD": 0.0, + "CHRW": 0.0, + "CHTR": 0.0, + "CI": 0.0, + "CINF": 0.0, + "CL": 0.0, + "CLX": 0.0, + "CMA": 0.0, + "CMCSA": 0.0, + "CME": 0.0, + "CMG": 0.0, + "CMI": 0.0, + "CMS": 0.0, + "CNC": 0.0, + "CNP": 0.0, + "COF": 0.0, + "COO": 0.0, + "COP": 0.0, + "COR": 0.0, + "COST": 0.0, + "CPB": 0.0, + "CPRT": 0.0, + "CPT": 0.0, + "CRL": 0.0, + "CRM": 0.0, + "CSCO": 0.0, + "CSGP": 0.0, + "CSX": 0.0, + "CTAS": 0.0, + "CTLT": 0.0, + "CTRA": 0.0, + "CTSH": 0.0, + "CTVA": 0.0, + "CVS": 0.0, + "CVX": 0.0, + "CZR": 0.0, + "D": 0.0, + "DAL": 0.0, + "DD": 0.0, + "DE": 0.0, + "DFS": 0.0, + "DG": 0.0, + "DGX": 0.0, + "DHI": 0.0, + "DHR": 0.0, + "DIS": 0.0, + "DLR": 0.0, + "DLTR": 0.0, + "DOV": 0.0, + "DOW": 0.0, + "DPZ": 0.0, + "DRI": 0.0, + "DTE": 0.0, + "DUK": 0.0, + "DVA": 0.0, + "DVN": 0.0, + "DXCM": 0.0, + "EA": 0.0, + "EBAY": 0.0, + "ECL": 0.0, + "ED": 0.0, + "EFX": 0.0, + "EG": 0.0, + "EIX": 0.0, + "EL": 0.0, + "ELV": 0.0, + "EMN": 0.0, + "EMR": 0.0, + "ENPH": 0.0, + "EOG": 0.0, + "EPAM": 0.0, + "EQIX": 0.0, + "EQR": 0.0, + "EQT": 0.0, + "ES": 0.0, + "ESS": 0.0, + "ETN": 0.0, + "ETR": 0.0, + "ETSY": 0.0, + "EVRG": 0.0, + "EW": 0.0, + "EXC": 0.0, + "EXPD": 0.0, + "EXPE": 0.0, + "EXR": 0.0, + "F": 0.0, + "FANG": 0.0, + "FAST": 0.0, + "FCX": 0.0, + "FDS": 0.0, + "FDX": 0.0, + "FE": 0.0, + "FFIV": 0.0, + "FI": 0.0, + "FICO": 0.0, + "FIS": 0.0, + "FITB": 0.0, + "FLT": 0.0, + "FMC": 0.0, + "FOX": 0.0, + "FOXA": 0.0, + "FRT": 0.0, + "FSLR": 0.0, + "FTNT": 0.0, + "FTV": 0.0, + "GD": 0.0, + "GE": 0.0, + "GEHC": 0.0, + "GEN": 0.0, + "GILD": 0.0, + "GIS": 0.0, + "GL": 0.0, + "GLW": 0.0, + "GM": 0.0, + "GNRC": 0.0, + "GOOG": 0.0, + "GOOGL": 0.0, + "GPC": 0.0, + "GPN": 0.0, + "GRMN": 0.0, + "GS": 0.0, + "GWW": 0.0, + "HAL": 0.0, + "HAS": 0.0, + "HBAN": 0.0, + "HCA": 0.0, + "HD": 0.0, + "HES": 0.0, + "HIG": 0.0, + "HII": 0.0, + "HLT": 0.0, + "HOLX": 0.0, + "HON": 0.0, + "HPE": 0.0, + "HPQ": 0.0, + "HRL": 0.0, + "HSIC": 0.0, + "HST": 0.0, + "HSY": 0.0, + "HUBB": 0.0, + "HUM": 0.0, + "HWM": 0.0, + "IBM": 0.0, + "ICE": 0.0, + "IDXX": 0.0, + "IEX": 0.0, + "IFF": 0.0, + "ILMN": 0.0, + "INCY": 0.0, + "INTC": 0.0, + "INTU": 0.0, + "INVH": 0.0, + "IP": 0.0, + "IPG": 0.0, + "IQV": 0.0, + "IR": 0.0, + "IRM": 0.0, + "ISRG": 0.0, + "IT": 0.0, + "ITW": 0.0, + "IVZ": 0.0, + "J": 0.0, + "JBHT": 0.0, + "JBL": 0.0, + "JCI": 0.0, + "JKHY": 0.0, + "JNJ": 0.0, + "JNPR": 0.0, + "JPM": 0.0, + "K": 0.0, + "KDP": 0.0, + "KEY": 0.0, + "KEYS": 0.0, + "KHC": 0.0, + "KIM": 0.0, + "KLAC": 0.0, + "KMB": 0.0, + "KMI": 0.0, + "KMX": 0.0, + "KO": 0.0, + "KR": 0.0, + "KVUE": 0.0, + "L": 0.0, + "LDOS": 0.0, + "LEN": 0.0, + "LH": 0.0, + "LHX": 0.0, + "LIN": 0.0, + "LKQ": 0.0, + "LLY": 0.0, + "LMT": 0.0, + "LNT": 0.0, + "LOW": 0.0, + "LRCX": 0.0, + "LULU": 0.0, + "LUV": 0.0, + "LVS": 0.0, + "LW": 0.0, + "LYB": 0.0, + "LYV": 0.0, + "MA": 0.0, + "MAA": 0.0, + "MAR": 0.0, + "MAS": 0.0, + "MCD": 0.0, + "MCHP": 0.0, + "MCK": 0.0, + "MCO": 0.0, + "MDLZ": 0.0, + "MDT": 0.0, + "MET": 0.0, + "META": 0.0, + "MGM": 0.0, + "MHK": 0.0, + "MKC": 0.0, + "MKTX": 0.0, + "MLM": 0.0, + "MMC": 0.0, + "MMM": 0.0, + "MNST": 0.0, + "MO": 0.0, + "MOH": 0.0, + "MOS": 0.0, + "MPC": 0.0, + "MPWR": 0.0, + "MRK": 0.0, + "MRNA": 0.0, + "MRO": 0.0, + "MS": 0.0, + "MSCI": 0.0, + "MSFT": 0.0, + "MSI": 0.0, + "MTB": 0.0, + "MTCH": 0.0, + "MTD": 0.0, + "MU": 0.0, + "NCLH": 0.0, + "NDAQ": 0.0, + "NDSN": 0.0, + "NEE": 0.0, + "NEM": 0.0, + "NFLX": 0.0, + "NI": 0.0, + "NKE": 0.0, + "NOC": 0.0, + "NOW": 0.0, + "NRG": 0.0, + "NSC": 0.0, + "NTAP": 0.0, + "NTRS": 0.0, + "NUE": 0.0, + "NVDA": 0.0, + "NVR": 0.0, + "NWS": 0.0, + "NWSA": 0.0, + "NXPI": 0.0, + "O": 0.0, + "ODFL": 0.0, + "OKE": 0.0, + "OMC": 0.0, + "ON": 0.0, + "ORCL": 0.0, + "ORLY": 0.0, + "OTIS": 0.0, + "OXY": 0.0, + "PANW": 0.0, + "PARA": 0.0, + "PAYC": 0.0, + "PAYX": 0.0, + "PCAR": 0.0, + "PCG": 0.0, + "PEAK": 0.0, + "PEG": 0.0, + "PEP": 0.0, + "PFE": 0.0, + "PFG": 0.0, + "PG": 0.0, + "PGR": 0.0, + "PH": 0.0, + "PHM": 0.0, + "PKG": 0.0, + "PLD": 0.0, + "PM": 0.0, + "PNC": 0.0, + "PNR": 0.0, + "PNW": 0.0, + "PODD": 0.0, + "POOL": 0.0, + "PPG": 0.0, + "PPL": 0.0, + "PRU": 0.0, + "PSA": 0.0, + "PSX": 0.0, + "PTC": 0.0, + "PWR": 0.0, + "PXD": 0.0, + "PYPL": 0.0, + "QCOM": 0.0, + "QRVO": 0.0, + "RCL": 0.0, + "REG": 0.0, + "REGN": 0.0, + "RF": 0.0, + "RHI": 0.0, + "RJF": 0.0, + "RL": 0.0, + "RMD": 0.0, + "ROK": 0.0, + "ROL": 0.0, + "ROP": 0.0, + "ROST": 0.0, + "RSG": 0.0, + "RTX": 0.0, + "RVTY": 0.0, + "SBAC": 0.0, + "SBUX": 0.0, + "SCHW": 0.0, + "SHW": 0.0, + "SJM": 0.0, + "SLB": 0.0, + "SNA": 0.0, + "SNPS": 0.0, + "SO": 0.0, + "SPG": 0.0, + "SPGI": 0.0, + "SRE": 0.0, + "STE": 0.0, + "STLD": 0.0, + "STT": 0.0, + "STX": 0.0, + "STZ": 0.0, + "SWK": 0.0, + "SWKS": 0.0, + "SYF": 0.0, + "SYK": 0.0, + "SYY": 0.0, + "T": 0.0, + "TAP": 0.0, + "TDG": 0.0, + "TDY": 0.0, + "TECH": 0.0, + "TEL": 0.0, + "TER": 0.0, + "TFC": 0.0, + "TFX": 0.0, + "TGT": 0.0, + "TJX": 0.0, + "TMO": 0.0, + "TMUS": 0.0, + "TPR": 0.0, + "TRGP": 0.0, + "TRMB": 0.0, + "TROW": 0.0, + "TRV": 0.0, + "TSCO": 0.0, + "TSLA": 0.0, + "TSN": 0.0, + "TT": 0.0, + "TTWO": 0.0, + "TXN": 0.0, + "TXT": 0.0, + "TYL": 0.0, + "UAL": 0.0, + "UBER": 0.0, + "UDR": 0.0, + "UHS": 0.0, + "ULTA": 0.0, + "UNH": 0.0, + "UNP": 0.0, + "UPS": 0.0, + "URI": 0.0, + "USB": 0.0, + "USDOLLAR": 1000000.0, + "V": 0.0, + "VFC": 0.0, + "VICI": 0.0, + "VLO": 0.0, + "VLTO": 0.0, + "VMC": 0.0, + "VRSK": 0.0, + "VRSN": 0.0, + "VRTX": 0.0, + "VTR": 0.0, + "VTRS": 0.0, + "VZ": 0.0, + "WAB": 0.0, + "WAT": 0.0, + "WBA": 0.0, + "WBD": 0.0, + "WDC": 0.0, + "WEC": 0.0, + "WELL": 0.0, + "WFC": 0.0, + "WHR": 0.0, + "WM": 0.0, + "WMB": 0.0, + "WMT": 0.0, + "WRB": 0.0, + "WRK": 0.0, + "WST": 0.0, + "WTW": 0.0, + "WY": 0.0, + "WYNN": 0.0, + "XEL": 0.0, + "XOM": 0.0, + "XRAY": 0.0, + "XYL": 0.0, + "YUM": 0.0, + "ZBH": 0.0, + "ZBRA": 0.0, + "ZION": 0.0, + "ZTS": 0.0 + } +} \ No newline at end of file diff --git a/examples/strategies/sp500_daily_target_weights.json b/examples/strategies/sp500_daily_target_weights.json new file mode 100644 index 000000000..d5770891b --- /dev/null +++ b/examples/strategies/sp500_daily_target_weights.json @@ -0,0 +1,508 @@ +{ + "2023-12-29 14:30:00+00:00": { + "A": 4.5896169775224445e-11, + "AAL": 0.0007320535024544476, + "AAPL": 0.039357991894695306, + "ABBV": 0.008332259348437097, + "ABNB": 2.1277430608952272e-11, + "ABT": 0.002769297154742328, + "ACGL": 7.873302164597076e-10, + "ACN": 0.00022480677904780354, + "ADBE": 0.0069639681865496005, + "ADI": 4.028518145929488e-09, + "ADM": 1.7987424348437608e-10, + "ADP": 1.6584950842316192e-10, + "ADSK": 5.665554034606695e-05, + "AEE": 4.9670109407096796e-11, + "AEP": 5.1780488021932486e-11, + "AES": 2.6376582601032452e-11, + "AFL": 0.002744747624776459, + "AIG": 8.17669217319592e-11, + "AIZ": 0.00027119444257472084, + "AJG": 1.875453632676647e-09, + "AKAM": 1.6318228489472585e-10, + "ALB": 6.690114073793923e-11, + "ALGN": 0.00030048687366893357, + "ALL": 9.917591012853495e-05, + "ALLE": 4.548778465855315e-11, + "AMAT": 0.0015847670095667245, + "AMCR": 8.972082579728484e-12, + "AMD": 0.019277932770561567, + "AME": 1.0801028073250194e-10, + "AMGN": 0.006817279534573171, + "AMP": 0.0025611329055142983, + "AMT": 0.0013743519231002865, + "AMZN": 0.03168780895432958, + "ANET": 0.0019257468174569815, + "ANSS": 0.0010356947960504835, + "AON": 0.00020684364769425778, + "AOS": 9.092405856789816e-11, + "APA": 5.159477483598802e-11, + "APD": 7.919135216020511e-10, + "APH": 0.0013668140262977043, + "APTV": 7.459930694018297e-05, + "ARE": 5.121692733593944e-11, + "ATO": 1.4530300873846511e-10, + "AVB": 1.0355885940681585e-10, + "AVGO": 0.019306827891652452, + "AVY": 1.4779203108303348e-10, + "AWK": 8.853841218357455e-08, + "AXON": 0.0048570160451374715, + "AXP": 8.025270595802975e-10, + "AZO": 0.0035577573584122738, + "BA": 0.0024806523817178195, + "BAC": 7.809374682920232e-11, + "BALL": 3.546299404322796e-10, + "BAX": 1.2556976957795983e-10, + "BBWI": 1.6428460721074125e-10, + "BBY": 0.0012219093655894881, + "BDX": 1.981642589877488e-10, + "BEN": 0.00022119695114626825, + "BF-B": 1.2364756263426396e-10, + "BG": 9.15508814264246e-06, + "BIIB": 0.002373399364234233, + "BIO": 3.389721362738487e-11, + "BK": 5.635847196226416e-11, + "BKNG": 0.0031551358317739964, + "BKR": 4.509679435755005e-11, + "BLDR": 0.0027960430450627806, + "BLK": 0.002545018768066151, + "BMY": 8.34217593913476e-10, + "BR": 1.0978191631584595e-09, + "BRK-B": 4.1289311954221576e-10, + "BRO": 9.904695590996628e-05, + "BSX": 1.8990348296647792e-10, + "BWA": 1.3466834751160895e-10, + "BX": 0.001462919327378423, + "BXP": 7.640259524355314e-11, + "C": 1.1120771780119117e-10, + "CAG": 3.3975913854794453e-10, + "CAH": 0.0001322933516686249, + "CARR": 0.017751601685850663, + "CAT": 6.729531251268256e-11, + "CB": 0.004042807541775711, + "CBOE": 7.283389060129085e-10, + "CBRE": 0.003400096743891501, + "CCI": 0.0012367939797176427, + "CCL": 2.9136637109215726e-11, + "CDAY": 1.8344850517723905e-11, + "CDNS": 0.0002762606384107477, + "CDW": 0.0024037631190096686, + "CE": 0.0004363009491943834, + "CEG": 0.0303593889274832, + "CF": 0.005588018860743452, + "CFG": 9.18380102758997e-11, + "CHD": 0.0027516610370276226, + "CHRW": 7.779557304507132e-10, + "CHTR": 0.002000416880689904, + "CI": 0.001302214200390483, + "CINF": 0.00012410815719660336, + "CL": 0.0011653636374935538, + "CLX": 0.0015003162272682802, + "CMA": 5.86768763014637e-11, + "CMCSA": 0.0036002874698283388, + "CME": 0.006638273282874821, + "CMG": 0.006653191385761695, + "CMI": 1.7052599181326092e-10, + "CMS": 4.368363001226449e-11, + "CNC": 0.0007512456699433272, + "CNP": 3.783993958823742e-11, + "COF": 0.0035195500180117316, + "COO": 5.46094971427133e-10, + "COP": 2.4161461846312363e-09, + "COR": 0.0027608810061879453, + "COST": 1.8886004498908137e-10, + "CPB": 2.141860482762438e-10, + "CPRT": 0.0006874459493279014, + "CPT": 6.303943916604758e-11, + "CRL": 2.5361606036819977e-11, + "CRM": 0.0070362958818289065, + "CSCO": 0.004981428558560211, + "CSGP": 0.00011818689486274179, + "CSX": 1.0941855449496207e-10, + "CTAS": 1.9289748843473356e-05, + "CTLT": 1.7672283202855597e-11, + "CTRA": 3.637975545589976e-11, + "CTSH": 0.005080820552939728, + "CTVA": 3.4894098263544066e-05, + "CVS": 1.3031570359189336e-10, + "CVX": 0.0014638606869261431, + "CZR": 0.0038062853930880152, + "D": 2.409465133894044e-10, + "DAL": 0.0015323496240228893, + "DD": 7.822284178822252e-11, + "DE": 0.0002970537071609436, + "DFS": 0.0018904991545650117, + "DG": 1.4454787310095332e-10, + "DGX": 4.178205326900982e-05, + "DHI": 0.0006802418512993587, + "DHR": 0.002296124423412891, + "DIS": 0.001664401875118612, + "DLR": 6.595367265442383e-05, + "DLTR": 0.0014805937539924111, + "DOV": 1.0150609388127274e-10, + "DOW": 1.2965708686208202e-09, + "DPZ": 0.003162782899302256, + "DRI": 0.0007798098767760445, + "DTE": 1.5835486167768075e-10, + "DUK": 5.516087523452114e-05, + "DVA": 0.0006311675025592967, + "DVN": 4.086478781275925e-11, + "DXCM": 0.0027607126927260447, + "EA": 0.0024720008869130662, + "EBAY": 3.9540382091717544e-10, + "ECL": 8.4464454257602e-11, + "ED": 3.630627754090136e-10, + "EFX": 1.5411124341811509e-10, + "EG": 0.0008468844974210023, + "EIX": 3.1461074783972523e-10, + "EL": 6.84712640951523e-11, + "ELV": 0.00011908260809805819, + "EMN": 6.993636482529749e-11, + "EMR": 4.862643480201113e-11, + "ENPH": 0.004977626123318644, + "EOG": 6.727746974283175e-10, + "EPAM": 0.0010470482036113234, + "EQIX": 0.0005430477584126638, + "EQR": 5.688779741352592e-11, + "EQT": 3.431506507880532e-11, + "ES": 4.2561038795088626e-11, + "ESS": 2.5257017463987755e-10, + "ETN": 9.937249643421228e-11, + "ETR": 1.877441739288607e-10, + "ETSY": 9.66585593999628e-11, + "EVRG": 2.8657908005399637e-11, + "EW": 5.774207601816295e-10, + "EXC": 5.867736990922414e-11, + "EXPD": 0.0006048769211934948, + "EXPE": 1.0162004420493262e-05, + "EXR": 0.00016951444143024008, + "F": 1.885681375408779e-11, + "FANG": 0.011417719995653152, + "FAST": 0.0009233350210519184, + "FCX": 7.148049204442511e-11, + "FDS": 0.0009022493160513187, + "FDX": 0.0036293052060150845, + "FE": 4.11071889106147e-11, + "FFIV": 0.0007247399878362019, + "FI": 0.0002652205756471424, + "FICO": 0.002346863793724819, + "FIS": 5.135791619074641e-11, + "FITB": 5.917708367545448e-10, + "FLT": 0.0007766180207554082, + "FMC": 1.0920498997753173e-10, + "FOX": 1.9267909723897335e-11, + "FOXA": 2.848726441686545e-11, + "FRT": 5.3246124710292155e-11, + "FSLR": 0.00025428031326456756, + "FTNT": 0.0014682676077368419, + "FTV": 2.802805209058992e-11, + "GD": 0.0006478969856864444, + "GE": 1.0948436060385978e-10, + "GEHC": 0.005918896600475227, + "GEN": 8.18705917096694e-11, + "GILD": 0.003696280129903756, + "GIS": 0.0023859785348496866, + "GL": 0.0001631954007110959, + "GLW": 3.62456975806857e-11, + "GM": 3.8021711772652105e-11, + "GNRC": 1.1241024774064396e-10, + "GOOG": 0.012101589344076758, + "GOOGL": 0.013788137385809206, + "GPC": 8.876811120386463e-06, + "GPN": 0.00019021129073635903, + "GRMN": 0.0014138445570718028, + "GS": 4.2671918852864e-10, + "GWW": 5.2411182420597205e-11, + "HAL": 3.673239618057866e-11, + "HAS": 0.00015644916273076478, + "HBAN": 1.916705087670498e-11, + "HCA": 0.003926146693515222, + "HD": 0.011144307827826274, + "HES": 4.849743113956629e-05, + "HIG": 0.0021196395800713993, + "HII": 0.0008968344688595022, + "HLT": 0.000888568526605216, + "HOLX": 0.0005860830125751008, + "HON": 6.082127984814548e-11, + "HPE": 1.8439515414503143e-11, + "HPQ": 3.238695933319882e-11, + "HRL": 2.1282201474697848e-10, + "HSIC": 1.7200047157577116e-10, + "HST": 4.616558934515204e-11, + "HSY": 0.005335473539938627, + "HUBB": 0.00020746008997536296, + "HUM": 0.0029984005964308067, + "HWM": 0.0009388524702201855, + "IBM": 6.839663996569914e-11, + "ICE": 0.0018672149565379013, + "IDXX": 0.0005355048488968979, + "IEX": 9.699276616904604e-11, + "IFF": 7.71892132103614e-11, + "ILMN": 0.0006893173630049752, + "INCY": 0.0012832822205733696, + "INTC": 1.8411250739838024e-10, + "INTU": 0.001982430889365318, + "INVH": 2.501436880758025e-11, + "IP": 5.009655495535778e-11, + "IPG": 8.89355389596129e-11, + "IQV": 5.3300347998860875e-11, + "IR": 0.00010831436432215919, + "IRM": 9.449002241847153e-11, + "ISRG": 0.004583801348269024, + "IT": 0.000798972378565637, + "ITW": 1.487100697959177e-10, + "IVZ": 2.6730096785775155e-11, + "J": 3.779918470379848e-10, + "JBHT": 1.7982145940629238e-10, + "JBL": 0.0026848799755327135, + "JCI": 1.0106874984811502e-10, + "JKHY": 0.0011117944732217154, + "JNJ": 0.013563549040017765, + "JNPR": 2.2953289938196065e-11, + "JPM": 0.006210859828565852, + "K": 0.0004156936255109539, + "KDP": 5.122545601981955e-10, + "KEY": 1.706097672826314e-11, + "KEYS": 1.88156667003074e-10, + "KHC": 1.4703828207507415e-11, + "KIM": 2.759337446666047e-11, + "KLAC": 0.0005049831258071445, + "KMB": 0.004832878054173591, + "KMI": 1.110165297466702e-11, + "KMX": 8.265436639406603e-11, + "KO": 0.00020198159664587998, + "KR": 1.4524613121067865e-10, + "KVUE": 4.397188813591665e-12, + "L": 5.1848202973263253e-05, + "LDOS": 3.818601658634624e-11, + "LEN": 9.749524825049839e-05, + "LH": 5.452035286482573e-11, + "LHX": 1.3487143107961505e-10, + "LIN": 0.002004208722811197, + "LKQ": 1.146318857076841e-09, + "LLY": 0.003190388438723937, + "LMT": 0.0069433715256824935, + "LNT": 3.498513597032753e-11, + "LOW": 0.0006099900823927303, + "LRCX": 0.0017024327497704801, + "LULU": 0.004103533551775488, + "LUV": 1.4224798335273795e-05, + "LVS": 0.0006729783048484743, + "LW": 0.0023524302475932102, + "LYB": 0.003634059755226602, + "LYV": 0.002593533113068952, + "MA": 0.022765996578040758, + "MAA": 1.0281987878989893e-10, + "MAR": 0.0011145251191896578, + "MAS": 1.0309569069626544e-10, + "MCD": 0.008943892168331108, + "MCHP": 0.0030824869607607628, + "MCK": 0.0010974634609624819, + "MCO": 4.154768047216983e-11, + "MDLZ": 4.9896016482031486e-11, + "MDT": 0.0004472121134780596, + "MET": 5.463711431083875e-05, + "META": 0.021612542356995824, + "MGM": 0.0009400202553732887, + "MHK": 3.907932583787542e-06, + "MKC": 1.0069232599931158e-10, + "MKTX": 0.0011212516935001102, + "MLM": 8.279669877283608e-11, + "MMC": 6.578348617571701e-11, + "MMM": 1.2594032930628074e-10, + "MNST": 0.0032211554759851904, + "MO": 0.0023950655217258475, + "MOH": 0.00039189353171921795, + "MOS": 2.8959465669046806e-11, + "MPC": 0.007544538751565689, + "MPWR": 0.000677878211966208, + "MRK": 0.004236786695519972, + "MRNA": 0.0056630229525521675, + "MRO": 1.3873190334132641e-11, + "MS": 0.0063030807743822415, + "MSCI": 0.0008598697128992767, + "MSFT": 0.04045493353284348, + "MSI": 2.0709120391961785e-10, + "MTB": 0.0013968731948332627, + "MTCH": 8.059971492744773e-11, + "MTD": 0.00024835374954117797, + "MU": 0.003940812812158244, + "NCLH": 4.2999928688296394e-10, + "NDAQ": 1.3509121593005604e-10, + "NDSN": 9.995429487453971e-11, + "NEE": 5.1563086829066344e-11, + "NEM": 1.1245211394674499e-10, + "NFLX": 0.01565832799156399, + "NI": 2.518292080931531e-11, + "NKE": 0.0001294824282330165, + "NOC": 0.0013684436517584825, + "NOW": 0.0036759488943481976, + "NRG": 1.1096627841566095e-10, + "NSC": 0.00013900592165322497, + "NTAP": 0.003492624602937229, + "NTRS": 1.0373868258128232e-10, + "NUE": 6.788808862630397e-09, + "NVDA": 0.07415221449576642, + "NVR": 0.0008541055302144098, + "NWS": 2.131647299944976e-11, + "NWSA": 2.1565055585321313e-11, + "NXPI": 0.005173783305215015, + "O": 2.0481463679500145e-10, + "ODFL": 0.0015598348830293883, + "OKE": 1.2185567360595626e-10, + "OMC": 1.3746252969732072e-10, + "ON": 0.0003652435492263334, + "ORCL": 0.0075721669919248755, + "ORLY": 0.003073162615017435, + "OTIS": 0.001632990471901287, + "OXY": 7.723172101227356e-11, + "PANW": 0.005563559316181395, + "PARA": 2.144175069648563e-11, + "PAYC": 2.321704690477076e-05, + "PAYX": 2.6417623596105562e-08, + "PCAR": 8.445157612545094e-10, + "PCG": 2.8346808398989674e-11, + "PEAK": 1.8471188145880687e-11, + "PEG": 3.8310970203902574e-10, + "PEP": 0.005017598154415478, + "PFE": 5.99130805510818e-11, + "PFG": 0.0001594710104755587, + "PG": 0.0005560223463603979, + "PGR": 0.004777267202073217, + "PH": 1.2246791895615732e-10, + "PHM": 0.000617729808945712, + "PKG": 0.0004269194725399392, + "PLD": 1.0710916918397771e-10, + "PM": 6.374434356429004e-10, + "PNC": 8.198118575861198e-05, + "PNR": 4.220748354703525e-11, + "PNW": 4.7558676721110105e-11, + "PODD": 0.001550445808336815, + "POOL": 0.0010575022351085016, + "PPG": 0.00027427278608806036, + "PPL": 4.757300852636295e-11, + "PRU": 0.0013338202866184487, + "PSA": 7.919369989568555e-11, + "PSX": 0.002572991544968324, + "PTC": 0.0003163181785396701, + "PWR": 0.0013376946173031276, + "PXD": 0.0008978339321650469, + "PYPL": 1.503551370730825e-11, + "QCOM": 0.005521525252171092, + "QRVO": 1.6089272464322168e-11, + "RCL": 0.001405413056156767, + "REG": 5.739482131556773e-11, + "REGN": 0.0020441879564308527, + "RF": 2.4268805454458627e-11, + "RHI": 1.593735464665051e-10, + "RJF": 5.7221450854752376e-05, + "RL": 1.9557301296567614e-10, + "RMD": 0.002654464318402595, + "ROK": 0.0005355446128761732, + "ROL": 4.77653087471279e-11, + "ROP": 0.004893968060442007, + "ROST": 0.0014945496147986902, + "RSG": 3.121794280709215e-10, + "RTX": 2.0191852864166196e-10, + "RVTY": 3.3679906530910914e-11, + "SBAC": 0.004379365446931631, + "SBUX": 0.004769618202327634, + "SCHW": 0.00020814214865337227, + "SHW": 0.0016765590856992797, + "SJM": 8.316487049834134e-05, + "SLB": 3.6424415831248575e-11, + "SNA": 3.23913272597498e-10, + "SNPS": 9.610406528755957e-11, + "SO": 0.0006969353463976477, + "SPG": 2.2680230025140598e-10, + "SPGI": 1.1952531085516852e-10, + "SRE": 9.891590788674954e-10, + "STE": 0.0003689902097183969, + "STLD": 0.000654490202210253, + "STT": 0.00034901791093276555, + "STX": 0.0007347642405119222, + "STZ": 0.0044509516566946915, + "SWK": 1.1489569824783021e-10, + "SWKS": 4.7271588181778414e-11, + "SYF": 1.0713501943714103e-10, + "SYK": 0.0024444371292689565, + "SYY": 4.0750141271437324e-10, + "T": 6.022271845220343e-11, + "TAP": 2.182520349000186e-10, + "TDG": 0.008069161957349202, + "TDY": 0.00019017471178927857, + "TECH": 1.1851133311413624e-05, + "TEL": 2.1603343122289896e-10, + "TER": 4.597490767948249e-11, + "TFC": 5.656086642637419e-11, + "TFX": 1.1474972587414534e-09, + "TGT": 2.659657040090422e-10, + "TJX": 0.00034981554736762514, + "TMO": 5.771150185490784e-05, + "TMUS": 0.0006727920924708726, + "TPR": 0.0009694134058137535, + "TRGP": 0.0011357963507529034, + "TRMB": 7.418402249703797e-11, + "TROW": 2.207040123553398e-10, + "TRV": 1.358873715276326e-09, + "TSCO": 0.002099034100710778, + "TSLA": 0.12154227734680055, + "TSN": 0.00021697923675701486, + "TT": 1.4582306072047501e-10, + "TTWO": 0.0007502250092610763, + "TXN": 7.98516985579317e-11, + "TXT": 4.953157909508736e-11, + "TYL": 9.743705453115848e-06, + "UAL": 0.0028122917097496347, + "UBER": 3.9337275992775044e-11, + "UDR": 3.043631181144681e-11, + "UHS": 9.366555958481773e-11, + "ULTA": 0.0047115061013097625, + "UNH": 0.01313071762411703, + "UNP": 2.336793138795637e-09, + "UPS": 3.029816651506405e-11, + "URI": 1.1922956986698286e-06, + "USB": 6.821899023296108e-11, + "USDOLLAR": 2.3206629284899805e-08, + "V": 0.008572640725108908, + "VFC": 2.578326233162811e-11, + "VICI": 4.090695637875089e-11, + "VLO": 7.143987377633046e-06, + "VLTO": 0.008426646338340104, + "VMC": 3.2116265682574213e-11, + "VRSK": 1.3838624559311584e-10, + "VRSN": 0.001024005033310653, + "VRTX": 0.0020134101920949673, + "VTR": 1.0993959885374805e-10, + "VTRS": 1.456799671711908e-11, + "VZ": 1.3194520738908984e-10, + "WAB": 7.861907464796682e-11, + "WAT": 0.0004101560519218868, + "WBA": 6.556225648640342e-11, + "WBD": 1.4098517219311172e-11, + "WDC": 0.00011148021512355573, + "WEC": 5.45138733943346e-10, + "WELL": 1.0221636053670769e-10, + "WFC": 7.122097596494762e-07, + "WHR": 1.7796372771386267e-10, + "WM": 0.0016388031990639158, + "WMB": 2.191381733432236e-09, + "WMT": 0.009943015847846017, + "WRB": 2.911251756527414e-10, + "WRK": 2.8461694607229982e-11, + "WST": 4.625988007937228e-11, + "WTW": 3.370958093246272e-09, + "WY": 2.966342556877593e-11, + "WYNN": 0.002487236203309626, + "XEL": 6.255063927616726e-11, + "XOM": 3.124015826664396e-10, + "XRAY": 9.557501719536823e-11, + "XYL": 2.9391968632228657e-10, + "YUM": 6.029320062160699e-05, + "ZBH": 4.200019761619658e-11, + "ZBRA": 4.9752923518011994e-11, + "ZION": 3.3175283084105715e-11, + "ZTS": 2.581309123994494e-10 + } +} \ No newline at end of file diff --git a/examples/strategies/strategy_executor.py b/examples/strategies/strategy_executor.py index 61ddd9ab1..b781a67b1 100644 --- a/examples/strategies/strategy_executor.py +++ b/examples/strategies/strategy_executor.py @@ -49,7 +49,7 @@ def main( policy, hyperparameter_opt_start, objective, universe, - cash_key='USDOLLAR'): + cash_key='USDOLLAR', initial_values=None): """Executor for each strategy's script. :param policy: Function that returns the policy object and a dictionary @@ -67,6 +67,8 @@ def main( :type universe: iterable :param cash_key: Name of cash account. :type cash_key: str + :param initial_values: Initial hyper-parameter choices. + :type initial_values: dict or None """ if len(sys.argv) < 2 or sys.argv[1] not in ['hyperparameters', 'strategy']: print('Usage (from root directory):') @@ -86,7 +88,9 @@ def main( sys.exit(0) runner = _Runner( - policy, hyperparameter_opt_start, objective, universe, cash_key) + policy=policy, hyperparameter_opt_start=hyperparameter_opt_start, + objective=objective, universe=universe, cash_key=cash_key, + initial_values=initial_values) if sys.argv[1] == 'hyperparameters': runner.run_hyperparameters() @@ -95,7 +99,8 @@ def main( def hyperparameter_optimize( - universe, policy, hyperparameter_opt_start, objective='sharpe_ratio'): + universe, policy, hyperparameter_opt_start, objective='sharpe_ratio', + initial_values=None): """Optimize hyper-parameters of a policy over back-test. :param universe: Trading universe for the policy. @@ -109,12 +114,15 @@ def hyperparameter_optimize( (must be an attribute of :class:`cvxportfolio.BacktestResult`). Default ``'sharpe_ratio'``. :type objective: str + :param initial_values: Initial hyper-parameter choices. + :type initial_values: dict or None :return: Choice of gamma risk and gamma trade. :rtype: dict """ hyper_parameter_names = inspect.getfullargspec(policy).args - initial_values = {k: 1. for k in hyper_parameter_names} + if initial_values is None: + initial_values = {k: 1. for k in hyper_parameter_names} sim = cvx.StockMarketSimulator(universe) policy, hyperpar_handles = policy(**initial_values) @@ -152,12 +160,13 @@ class _Runner: def __init__( self, policy, hyperparameter_opt_start, objective, universe, - cash_key='USDOLLAR'): + cash_key='USDOLLAR', initial_values=None): self.policy = policy self.hyperparameter_opt_start = hyperparameter_opt_start self.objective = objective self.universe = universe self.cash_key = cash_key + self.initial_values = initial_values # self.today = str(datetime.datetime.now().date()) self.stratfile = self.policy.__code__.co_filename self.all_hyper_params = self.load_json(self.file_hyper_parameters) @@ -248,7 +257,7 @@ def run_hyperparameters(self): self.all_hyper_params[self.today] = hyperparameter_optimize( universe=self.universe, policy=self.policy, hyperparameter_opt_start=self.hyperparameter_opt_start, - objective=self.objective) + objective=self.objective, initial_values=self.initial_values) print('Hyper-parameters optimized today:') print(self.all_hyper_params[self.today]) diff --git a/strategies_runner.sh b/strategies_runner.sh index f9c73b023..1d1a16303 100755 --- a/strategies_runner.sh +++ b/strategies_runner.sh @@ -10,10 +10,14 @@ env/bin/python -m examples.strategies.dow30_daily strategy &>> examples/strategies/dow30_daily.log git add examples/strategies/dow30_daily*.json -git commit -m '[auto commit] ${date +%Y-%m-%d} dow30_daily reconciliation & execution' +git commit -m '[auto commit] dow30_daily reconciliation & execution' env/bin/python -m examples.strategies.ndx100_daily strategy &>> examples/strategies/ndx100_daily.log git add examples/strategies/ndx100_daily*.json -git commit -m '[auto commit] ${date +%Y-%m-%d} ndx100_daily reconciliation & execution' +git commit -m '[auto commit] ndx100_daily reconciliation & execution' + +env/bin/python -m examples.strategies.sp500_daily strategy &>> examples/strategies/sp500_daily.log +git add examples/strategies/sp500_daily*.json +git commit -m '[auto commit] sp500_daily reconciliation & execution' git push