diff --git a/configuration/equity.cfg b/configuration/equity.cfg index ca8d821..2f3a58f 100644 --- a/configuration/equity.cfg +++ b/configuration/equity.cfg @@ -2,7 +2,7 @@ "security_type": "EQUITY", "data_directory": "./data/equity", "datafiles": [ - "202506*.mktdata.ohlcv.db", + "20250618.mktdata.ohlcv.db", ], "db_table_name": "md_1min_bars", "exchange_id": "ALPACA", @@ -19,8 +19,8 @@ "dis-equilibrium_close_trshld": 1.0, "training_minutes": 120, "funding_per_pair": 2000.0, - "fit_method_class": "pt_trading.sliding_fit.SlidingFit", - # "fit_method_class": "pt_trading.static_fit.StaticFit", + # "fit_method_class": "pt_trading.sliding_fit.SlidingFit", + "fit_method_class": "pt_trading.static_fit.StaticFit", "exclude_instruments": ["CAN"], "close_outstanding_positions": false diff --git a/configuration/equity_lg.cfg b/configuration/equity_lg.cfg new file mode 100644 index 0000000..1b3574b --- /dev/null +++ b/configuration/equity_lg.cfg @@ -0,0 +1,26 @@ +{ + "security_type": "EQUITY", + "data_directory": "./data/equity", + "datafiles": [ + "20250602.mktdata.ohlcv.db", + ], + "db_table_name": "md_1min_bars", + "exchange_id": "ALPACA", + "instrument_id_pfx": "STOCK-", + "trading_hours": { + "begin_session": "9:30:00", + "end_session": "16:00:00", + "timezone": "America/New_York" + }, + "price_column": "close", + "min_required_points": 30, + "zero_threshold": 1e-10, + "dis-equilibrium_open_trshld": 2.0, + "dis-equilibrium_close_trshld": 1.0, + "training_minutes": 120, + "funding_per_pair": 2000.0, + "fit_method_class": "pt_trading.fit_methods.StaticFit", + "exclude_instruments": ["CAN"] +} +# "fit_method_class": "pt_trading.fit_methods.SlidingFit", +# "fit_method_class": "pt_trading.fit_methods.StaticFit", diff --git a/lg_notes.md b/lg_notes.md new file mode 100644 index 0000000..fc3ddc5 --- /dev/null +++ b/lg_notes.md @@ -0,0 +1,115 @@ +07.11.2025 +pairs_trading/configuration <---- directory for config +equity_lg.cfg <-------- copy of equity.cfg +How to run a Program: TRIANGLEsquare ----> triangle EQUITY backtest +Results are in > results (timestamp table for all runs) +table "...timestamp... .pt_backtest_results.equity.db" +going to table using sqlite +> sqlite3 '/home/coder/results/20250721_175750.pt_backtest_results.equity.db' + +sqlite> .databases +main: /home/coder/results/20250717_180122.pt_backtest_results.equity.db r/w +sqlite> .tables +config outstanding_positions pt_bt_results + +sqlite> PRAGMA table_info('pt_bt_results'); +0|date|DATE|0||0 +1|pair|TEXT|0||0 +2|symbol|TEXT|0||0 +3|open_time|DATETIME|0||0 +4|open_side|TEXT|0||0 +5|open_price|REAL|0||0 +6|open_quantity|INTEGER|0||0 +7|open_disequilibrium|REAL|0||0 +8|close_time|DATETIME|0||0 +9|close_side|TEXT|0||0 +10|close_price|REAL|0||0 +11|close_quantity|INTEGER|0||0 +12|close_disequilibrium|REAL|0||0 +13|symbol_return|REAL|0||0 +14|pair_return|REAL|0||0 + +select count(*) as cnt from pt_bt_results; +8 + +select * from pt_bt_results; + +select +date, close_time, pair, symbol, symbol_return, pair_return +from pt_bt_results ; + +select date, sum(symbol_return) as daily_return +from pt_bt_results where date = '2025-06-18' group by date; + +.quit + +sqlite3 '/home/coder/results/20250717_172435.pt_backtest_results.equity.db' + +sqlite> select date, sum(symbol_return) as daily_return +from pt_bt_results group by date; + +2025-06-02|1.29845390060828 +... +2025-06-18|-43.5084977104115 <========== ????? ==========> +2025-06-20|11.8605547517183 + + +select +date, close_time, pair, symbol, symbol_return, pair_return +from pt_bt_results ; + +select date, close_time, pair, symbol, symbol_return, pair_return +from pt_bt_results where date = '2025-06-18'; + + +./scripts/load_equity_pair_intraday.sh -A NVDA -B QQQ -d 20250701 -T ./intraday_md + +to inspect exactly what sources, formats, and processing steps you can open the script with: +head -n 50 ./scripts/load_equity_pair_intraday.sh + + + +✓ Data file found: /home/coder/pairs_trading/data/crypto/20250605.mktdata.ohlcv.db + +sqlite3 '/home/coder/results/20250722_201930.pt_backtest_results.crypto.db' + +sqlite3 '/home/coder/results/xxxxxxxx_yyyyyy.pt_backtest_results.pseudo.db' + +11111111 +=== At your terminal, run these commands: +sqlite3 '/home/coder/results/20250722_201930.pt_backtest_results.crypto.db' +=== Then inside the SQLite prompt: +.mode csv +.headers on +.output results_20250722.csv +SELECT * FROM pt_bt_results; +.output stdout +.quit + +cd /home/coder/ + +# === mode csv formats output as CSV +# === headers on includes column names +# === output my_table.csv directs output to that file +# === Run your SELECT query, then revert output +# === Open my_table.csv in Excel directly + +# ======== Using scp (Secure Copy) +# === On your local machine, open a terminal and run: +scp cvtt@953f6e8df266:/home/coder/results_20250722.csv ~/Downloads/ + + +# ===== convert cvs pandas dataframe ====== --> +import pandas as pd +# Replace with the actual path to your CSV file +file_path = '/home/coder/results_20250722.csv' +# Read the CSV file into a DataFrame +df = pd.read_csv(file_path) +# Show the first few rows +print(df.head()) + + + + + + diff --git a/research/notebooks/pt_pair_backtest.ipynb b/research/notebooks/pt_pair_backtest.ipynb new file mode 100644 index 0000000..a71f245 --- /dev/null +++ b/research/notebooks/pt_pair_backtest.ipynb @@ -0,0 +1,16 @@ +{ + "cells": [], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "name": "python", + "version": "3.12.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/research/notebooks/pt_sliding.ipynb b/research/notebooks/pt_sliding.ipynb index b09bba3..714b06b 100644 --- a/research/notebooks/pt_sliding.ipynb +++ b/research/notebooks/pt_sliding.ipynb @@ -43,7 +43,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -105,7 +105,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -147,7 +147,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -227,7 +227,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -314,7 +314,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -375,7 +375,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -420,7 +420,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -512,7 +512,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ @@ -582,7 +582,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ @@ -1131,7 +1131,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -1201,7 +1201,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -1282,7 +1282,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -1298,7 +1298,7 @@ "\n", "Loading crypto configuration using HJSON...\n", "✓ Successfully loaded CRYPTO configuration\n", - " Data directory: /home/oleg/develop/pairs_trading/data/crypto\n", + " Data directory: /home/coder/pairs_trading/data/crypto\n", " Database table: md_1min_bars\n", " Exchange: BNBSPOT\n", " Training window: 120 minutes\n", @@ -1310,8 +1310,8 @@ "Data Configuration:\n", " Data File: 20250605.mktdata.ohlcv.db\n", " Security Type: CRYPTO\n", - " ✓ Data file found: /home/oleg/develop/pairs_trading/data/crypto/20250605.mktdata.ohlcv.db\n", - "Loading data from: /home/oleg/develop/pairs_trading/data/crypto/20250605.mktdata.ohlcv.db\n", + " ✓ Data file found: /home/coder/pairs_trading/data/crypto/20250605.mktdata.ohlcv.db\n", + "Loading data from: /home/coder/pairs_trading/data/crypto/20250605.mktdata.ohlcv.db\n", "Loaded 1202 rows of market data\n", "Symbols in data: ['BTC-USDT' 'ETH-USDT']\n", "Time range: 2025-06-05 10:00:00 to 2025-06-05 20:00:00\n", @@ -4828,9 +4828,9 @@ }, "text/html": [ "
\n", - "
\n", - "