From 936963a636177418597326eb0490714c64d57ca6 Mon Sep 17 00:00:00 2001 From: Javier Chatruc <jrchatruc@gmail.com> Date: Wed, 7 Aug 2024 15:34:21 -0300 Subject: [PATCH] Mojo playground --- backtester/test/__init__.py | 2 ++ backtester/test/backtester/__init__.py | 1 + backtester/test/conftest.py | 6 ++--- main.mojo | 32 ++++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 backtester/test/__init__.py create mode 100644 backtester/test/backtester/__init__.py create mode 100644 main.mojo diff --git a/backtester/test/__init__.py b/backtester/test/__init__.py new file mode 100644 index 0000000..3b7f655 --- /dev/null +++ b/backtester/test/__init__.py @@ -0,0 +1,2 @@ +from .conftest import sample_options_datahandler, sample_stocks_datahandler, sample_stock_portfolio +from .backtester import sample_options_strategy diff --git a/backtester/test/backtester/__init__.py b/backtester/test/backtester/__init__.py new file mode 100644 index 0000000..2618189 --- /dev/null +++ b/backtester/test/backtester/__init__.py @@ -0,0 +1 @@ +from .test_backtester import sample_options_strategy, run_backtest diff --git a/backtester/test/conftest.py b/backtester/test/conftest.py index 8e7292e..39f7bc6 100644 --- a/backtester/test/conftest.py +++ b/backtester/test/conftest.py @@ -16,7 +16,7 @@ # DataHandler fixtures -@pytest.fixture(scope='module') +# @pytest.fixture(scope='module') def sample_stocks_datahandler(): data = TiingoData(SAMPLE_DATA_STOCKS) return data @@ -35,7 +35,7 @@ def constant_price_stocks(): return data -@pytest.fixture(scope='module') +# @pytest.fixture(scope='module') def sample_options_datahandler(): data = HistoricalOptionsData(SAMPLE_DATA_OPTIONS) return data @@ -56,7 +56,7 @@ def ivy_portfolio(): return [Stock('VTI', 0.2), Stock('VEU', 0.2), Stock('BND', 0.2), Stock('VNQ', 0.2), Stock('DBC', 0.2)] -@pytest.fixture(scope='module') +# @pytest.fixture(scope='module') def sample_stock_portfolio(): VOO = Stock('VOO', 0.4) TUR = Stock('TUR', 0.1) diff --git a/main.mojo b/main.mojo new file mode 100644 index 0000000..ee4d205 --- /dev/null +++ b/main.mojo @@ -0,0 +1,32 @@ +from python import Python + +fn main() raises: + Python.add_to_path("./") + var backtester = Python.import_module("backtester") + var test = Python.import_module("backtester.test") + var sample_stocks_datahandler = test.sample_stocks_datahandler() + var sample_options_datahandler = test.sample_options_datahandler() + var sample_options_strategy = test.backtester.sample_options_strategy(backtester.Direction.BUY, sample_options_datahandler.schema) + + + ## This code below crashes for me for some reason, even though it looks the same as + ## running test.backtester.run_backtest(...) + + # var allocation = Python.dict() + + # allocation["stocks"] = 0.50 + # allocation["options"] = 0.50 + # allocation["cash"] = 0 + + # var bt = backtester.Backtest(allocation, []) + # bt.stocks_data = sample_stocks_datahandler + # bt.options_strategy = sample_options_strategy + # bt.options_data = sample_options_datahandler + # bt.stocks = test.sample_stock_portfolio() + + # bt.run(rebalance_freq=1) + + test.backtester.run_backtest(sample_stocks_datahandler, + sample_options_datahandler, + sample_options_strategy, + stocks=test.sample_stock_portfolio())