progress
This commit is contained in:
parent
6cd82b3621
commit
50435f8b3b
@ -2,7 +2,7 @@
|
||||
"security_type": "EQUITY",
|
||||
"data_directory": "./data/equity",
|
||||
"datafiles": [
|
||||
"202505*.alpaca_sim_md.db",
|
||||
"202506*.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,
|
||||
# "strategy_class": "strategies.StaticFitStrategy"
|
||||
"strategy_class": "strategies.SlidingFitStrategy"
|
||||
"strategy_class": "strategies.StaticFitStrategy"
|
||||
# "strategy_class": "strategies.SlidingFitStrategy"
|
||||
"exclude_instruments": ["CAN"]
|
||||
|
||||
}
|
||||
@ -25,6 +25,7 @@ httplib2>=0.20.2
|
||||
idna>=3.3
|
||||
ifaddr>=0.1.7
|
||||
IMDbPY>=2021.4.18
|
||||
ipykernel>=6.29.5
|
||||
jeepney>=0.7.1
|
||||
jsonschema>=3.2.0
|
||||
keyring>=23.5.0
|
||||
@ -35,6 +36,7 @@ lxml>=4.8.0
|
||||
Mako>=1.1.3
|
||||
Markdown>=3.3.6
|
||||
MarkupSafe>=2.0.1
|
||||
matplotlib>=3.10.3
|
||||
more-itertools>=8.10.0
|
||||
multidict>=6.0.4
|
||||
mypy>=0.942
|
||||
@ -64,6 +66,7 @@ PyYAML>=6.0
|
||||
reportlab>=3.6.8
|
||||
requests>=2.25.1
|
||||
requests-file>=1.5.1
|
||||
seaborn>=0.13.2
|
||||
SecretStorage>=3.3.1
|
||||
setproctitle>=1.2.2
|
||||
six>=1.16.0
|
||||
|
||||
30
scripts/load_equity_1min.sh
Executable file
30
scripts/load_equity_1min.sh
Executable file
@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
usage() {
|
||||
echo "Usage: $0 [DatePattern]"
|
||||
echo "DatePattern: YYYYMM or YYYYM or YYYYMMD"
|
||||
exit 1
|
||||
}
|
||||
|
||||
DatePattern="${1}"
|
||||
if [ -z "${DatePattern}" ]; then
|
||||
usage
|
||||
fi
|
||||
FilePattern="${DatePattern}*.alpaca_sim_md.db.gz"
|
||||
|
||||
pushd ./data/equity
|
||||
Cmd="rsync -ahvv cvtt@hs01.cvtt.vpn:/works/cvtt/md_archive/equity/alpaca_md/sim/${FilePattern} ./"
|
||||
echo ${Cmd}
|
||||
eval ${Cmd}
|
||||
# -------------------------------------
|
||||
|
||||
for srcfname in $(ls *.db.gz); do
|
||||
dt="${srcfname:0:8}"
|
||||
tgtfile=${dt}.mktdata.ohlcv.db
|
||||
echo "${srcfname} -> ${tgtfile}"
|
||||
|
||||
gunzip -c $srcfname > temp.db
|
||||
rm -f ${tgtfile} && sqlite3 temp.db ".dump md_1min_bars" | sqlite3 ${tgtfile} && rm ${srcfname}
|
||||
done
|
||||
rm temp.db
|
||||
popd
|
||||
File diff suppressed because one or more lines are too long
@ -93,15 +93,30 @@ class TradingPair:
|
||||
# print(f"{self}: {self.vecm_fit_.summary()}")
|
||||
pass
|
||||
|
||||
def check_cointegration(self):
|
||||
def check_cointegration_johansen(self):
|
||||
from statsmodels.tsa.vector_ar.vecm import coint_johansen
|
||||
df = self.training_df_[self.colnames()].reset_index(drop=True)
|
||||
result = coint_johansen(df, det_order=0, k_ar_diff=1)
|
||||
# print(f"{self}: lr1={result.lr1[0]} cvt={result.cvt[0, 1]}.")
|
||||
print(f"{self}: lr1={result.lr1[0]} cvt={result.cvt[0, 1]}.")
|
||||
is_cointegrated = result.lr1[0] > result.cvt[0, 1]
|
||||
|
||||
return is_cointegrated
|
||||
|
||||
|
||||
def check_cointegration(self):
|
||||
from statsmodels.tsa.stattools import coint
|
||||
col1, col2 = self.colnames()
|
||||
series1 = self.training_df_[col1].reset_index(drop=True)
|
||||
series2 = self.training_df_[col2].reset_index(drop=True)
|
||||
|
||||
# Run Engle-Granger cointegration test
|
||||
pvalue = coint(series1, series2)[1]
|
||||
# Define cointegration if p-value < 0.05 (i.e., reject null of no cointegration)
|
||||
is_cointegrated = pvalue < 0.05
|
||||
print(f"{self}: is_cointegrated={is_cointegrated} pvalue={pvalue}")
|
||||
return is_cointegrated
|
||||
|
||||
|
||||
def train_pair(self) -> bool:
|
||||
is_cointegrated = self.check_cointegration()
|
||||
if not is_cointegrated:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user