├── code ├── __init__.py ├── config │ ├── __init__.py │ ├── .gitignore │ ├── test │ │ ├── .gitignore │ │ ├── param_tmp.py │ │ └── test.py │ ├── param_2day_label.py │ ├── param_2day_label_trainable105.py │ ├── param_2day_label_trainable125.py │ ├── param_2day_label_trainable45.py │ ├── param_2day_label_trainable65.py │ ├── param_2day_label_trainable85.py │ ├── param_2day_label_small.py │ ├── param_2day_label_small_trainable25.py │ ├── param_2day_label_small_trainable45.py │ ├── param_2day_label_small_trainable65.py │ ├── param_2day_label_small_trainable85.py │ ├── param_2day_label_small_trainable105.py │ ├── param_2day_label_small_trainable125.py │ └── param_positive_negative_line_label.py ├── .gitignore ├── model_paper.py └── post_my_slack.py ├── GitHub └── mplfinance │ ├── ※plot.py変更入れてる!!!.txt │ ├── tests │ ├── test_images │ │ └── placeholder.png │ ├── reference_images │ │ ├── pnf01.png │ │ ├── pnf02.png │ │ ├── pnf03.png │ │ ├── pnf04.png │ │ ├── renko01.png │ │ ├── renko02.png │ │ ├── renko03.png │ │ ├── renko04.png │ │ ├── addplot01.png │ │ ├── addplot02.png │ │ ├── addplot03.png │ │ └── addplot04.png │ ├── conftest.py │ ├── original_flavor │ │ ├── test_plot_day_summary_oclh_demo.py │ │ ├── test_date_demo2.py │ │ ├── test_date_demo1.py │ │ ├── test_finance_demo.py │ │ ├── test_longshort.py │ │ └── test_finance_work2.py │ ├── test_exceptions.py │ ├── test_pnf.py │ ├── test_renko.py │ └── test_addplot.py │ ├── examples │ ├── original_flavor │ │ ├── data │ │ ├── plot_day_summary_oclh_demo.py │ │ ├── date_demo2.py │ │ ├── finance_demo.py │ │ ├── date_demo1.py │ │ ├── longshort.py │ │ └── finance_work2.py │ ├── scratch_pad │ │ ├── data.pkl │ │ ├── rcp_to_df.py │ │ ├── rcpars.py │ │ └── tplot.py │ └── data │ │ └── SP500_NOV2019_Hist.csv │ ├── .gitignore │ ├── doc │ ├── source │ │ ├── modules.rst │ │ ├── examples.rst │ │ ├── index.rst │ │ └── mpl_finance.rst │ └── README │ ├── readme_files │ ├── readme_4_0.png │ ├── readme_4_1.png │ ├── readme_5_1.png │ ├── readme_6_0.png │ ├── readme_6_1.png │ ├── readme_7_0.png │ ├── readme_7_1.png │ ├── readme_8_1.png │ ├── readme_9_0.png │ ├── readme_9_1.png │ ├── readme_10_0.png │ ├── readme_10_1.png │ ├── readme_12_0.png │ ├── readme_12_1.png │ ├── readme_14_0.png │ ├── readme_14_1.png │ ├── readme_18_0.png │ ├── readme_18_1.png │ ├── readme_20_0.png │ ├── readme_20_1.png │ ├── readme_22_0.png │ ├── readme_22_1.png │ ├── readme_24_0.png │ ├── readme_24_1.png │ ├── readme_26_0.png │ ├── readme_26_1.png │ ├── readme_29_0.png │ └── readme_29_1.png │ ├── src │ └── mplfinance │ │ ├── _styledata │ │ ├── sas.py │ │ ├── starsandstripes.py │ │ ├── brasil.py │ │ ├── yahoo.py │ │ ├── nightclouds.py │ │ ├── blueskies.py │ │ ├── checkers.py │ │ ├── classic.py │ │ ├── default.py │ │ ├── __init__.py │ │ ├── binance.py │ │ ├── charles.py │ │ └── mike.py │ │ ├── __init__.py │ │ ├── _version.py │ │ ├── _mpf_warnings.py │ │ └── _arg_validators.py │ ├── .travis.yml │ ├── .github │ ├── ISSUE_TEMPLATE │ │ ├── feedback.md │ │ ├── ask-a-question.md │ │ ├── feature_request.md │ │ └── bug_report.md │ └── workflows │ │ └── pythonpublish.yml │ ├── tox.ini │ ├── setup.py │ └── LICENSE ├── .gitignore ├── output.lnk ├── tfgpu.yml ├── img_sample.png ├── notebook ├── tmp.png ├── .gitignore ├── png_cp.sh └── png_cp.ipynb ├── CM_without_normalize_Xception_2day_label.png ├── predict_post_slack.bat ├── jpx400_nikkei225_500_split ├── 501-561.txt ├── 1-100.txt ├── 101-200.txt ├── 201-300.txt ├── 301-400.txt └── 401-500.txt ├── nikkei1000_split ├── 901-994.txt ├── 1-100.txt ├── 101-200.txt ├── 201-300.txt ├── 301-400.txt ├── 401-500.txt ├── 501-600.txt ├── 601-700.txt ├── 701-800.txt └── 801-900.txt ├── predict.sh ├── split.sh ├── make_dataset.sh ├── make_candlestick.sh ├── README.md ├── train.sh └── jpx400_nikkei225_500.txt /code/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /code/config/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /GitHub/mplfinance/※plot.py変更入れてる!!!.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /GitHub/mplfinance/tests/test_images/placeholder.png: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /GitHub/mplfinance/examples/original_flavor/data: -------------------------------------------------------------------------------- 1 | ../data -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/.gitignore -------------------------------------------------------------------------------- /output.lnk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/output.lnk -------------------------------------------------------------------------------- /tfgpu.yml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/tfgpu.yml -------------------------------------------------------------------------------- /code/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/code/.gitignore -------------------------------------------------------------------------------- /img_sample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/img_sample.png -------------------------------------------------------------------------------- /notebook/tmp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/notebook/tmp.png -------------------------------------------------------------------------------- /notebook/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/notebook/.gitignore -------------------------------------------------------------------------------- /code/config/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/code/config/.gitignore -------------------------------------------------------------------------------- /code/config/test/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/code/config/test/.gitignore -------------------------------------------------------------------------------- /GitHub/mplfinance/.gitignore: -------------------------------------------------------------------------------- 1 | doc/build 2 | doc/examples 3 | _as_gen 4 | __pycache__ 5 | *.pyc 6 | *.egg-info 7 | .tox/ 8 | .cache/ 9 | -------------------------------------------------------------------------------- /GitHub/mplfinance/doc/source/modules.rst: -------------------------------------------------------------------------------- 1 | mpl_finance 2 | =========== 3 | 4 | .. toctree:: 5 | :maxdepth: 4 6 | 7 | mpl_finance 8 | -------------------------------------------------------------------------------- /CM_without_normalize_Xception_2day_label.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/CM_without_normalize_Xception_2day_label.png -------------------------------------------------------------------------------- /GitHub/mplfinance/readme_files/readme_4_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/readme_files/readme_4_0.png -------------------------------------------------------------------------------- /GitHub/mplfinance/readme_files/readme_4_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/readme_files/readme_4_1.png -------------------------------------------------------------------------------- /GitHub/mplfinance/readme_files/readme_5_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/readme_files/readme_5_1.png -------------------------------------------------------------------------------- /GitHub/mplfinance/readme_files/readme_6_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/readme_files/readme_6_0.png -------------------------------------------------------------------------------- /GitHub/mplfinance/readme_files/readme_6_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/readme_files/readme_6_1.png -------------------------------------------------------------------------------- /GitHub/mplfinance/readme_files/readme_7_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/readme_files/readme_7_0.png -------------------------------------------------------------------------------- /GitHub/mplfinance/readme_files/readme_7_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/readme_files/readme_7_1.png -------------------------------------------------------------------------------- /GitHub/mplfinance/readme_files/readme_8_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/readme_files/readme_8_1.png -------------------------------------------------------------------------------- /GitHub/mplfinance/readme_files/readme_9_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/readme_files/readme_9_0.png -------------------------------------------------------------------------------- /GitHub/mplfinance/readme_files/readme_9_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/readme_files/readme_9_1.png -------------------------------------------------------------------------------- /notebook/png_cp.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | PWDDIR=`pwd` 3 | 4 | DIR=D:\work\candlestick_model\output\ts_dataset_all_2day_label_binary\train\2 5 | 6 | cp ${DIR} -------------------------------------------------------------------------------- /GitHub/mplfinance/examples/scratch_pad/data.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/examples/scratch_pad/data.pkl -------------------------------------------------------------------------------- /GitHub/mplfinance/readme_files/readme_10_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/readme_files/readme_10_0.png -------------------------------------------------------------------------------- /GitHub/mplfinance/readme_files/readme_10_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/readme_files/readme_10_1.png -------------------------------------------------------------------------------- /GitHub/mplfinance/readme_files/readme_12_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/readme_files/readme_12_0.png -------------------------------------------------------------------------------- /GitHub/mplfinance/readme_files/readme_12_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/readme_files/readme_12_1.png -------------------------------------------------------------------------------- /GitHub/mplfinance/readme_files/readme_14_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/readme_files/readme_14_0.png -------------------------------------------------------------------------------- /GitHub/mplfinance/readme_files/readme_14_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/readme_files/readme_14_1.png -------------------------------------------------------------------------------- /GitHub/mplfinance/readme_files/readme_18_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/readme_files/readme_18_0.png -------------------------------------------------------------------------------- /GitHub/mplfinance/readme_files/readme_18_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/readme_files/readme_18_1.png -------------------------------------------------------------------------------- /GitHub/mplfinance/readme_files/readme_20_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/readme_files/readme_20_0.png -------------------------------------------------------------------------------- /GitHub/mplfinance/readme_files/readme_20_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/readme_files/readme_20_1.png -------------------------------------------------------------------------------- /GitHub/mplfinance/readme_files/readme_22_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/readme_files/readme_22_0.png -------------------------------------------------------------------------------- /GitHub/mplfinance/readme_files/readme_22_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/readme_files/readme_22_1.png -------------------------------------------------------------------------------- /GitHub/mplfinance/readme_files/readme_24_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/readme_files/readme_24_0.png -------------------------------------------------------------------------------- /GitHub/mplfinance/readme_files/readme_24_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/readme_files/readme_24_1.png -------------------------------------------------------------------------------- /GitHub/mplfinance/readme_files/readme_26_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/readme_files/readme_26_0.png -------------------------------------------------------------------------------- /GitHub/mplfinance/readme_files/readme_26_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/readme_files/readme_26_1.png -------------------------------------------------------------------------------- /GitHub/mplfinance/readme_files/readme_29_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/readme_files/readme_29_0.png -------------------------------------------------------------------------------- /GitHub/mplfinance/readme_files/readme_29_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/readme_files/readme_29_1.png -------------------------------------------------------------------------------- /GitHub/mplfinance/doc/README: -------------------------------------------------------------------------------- 1 | The module documentation is generated with Sphinx. 2 | 3 | Run "make html" to generate HTML. Then view build/index.html. 4 | 5 | -------------------------------------------------------------------------------- /GitHub/mplfinance/tests/reference_images/pnf01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/tests/reference_images/pnf01.png -------------------------------------------------------------------------------- /GitHub/mplfinance/tests/reference_images/pnf02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/tests/reference_images/pnf02.png -------------------------------------------------------------------------------- /GitHub/mplfinance/tests/reference_images/pnf03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/tests/reference_images/pnf03.png -------------------------------------------------------------------------------- /GitHub/mplfinance/tests/reference_images/pnf04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/tests/reference_images/pnf04.png -------------------------------------------------------------------------------- /GitHub/mplfinance/tests/reference_images/renko01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/tests/reference_images/renko01.png -------------------------------------------------------------------------------- /GitHub/mplfinance/tests/reference_images/renko02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/tests/reference_images/renko02.png -------------------------------------------------------------------------------- /GitHub/mplfinance/tests/reference_images/renko03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/tests/reference_images/renko03.png -------------------------------------------------------------------------------- /GitHub/mplfinance/tests/reference_images/renko04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/tests/reference_images/renko04.png -------------------------------------------------------------------------------- /GitHub/mplfinance/tests/reference_images/addplot01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/tests/reference_images/addplot01.png -------------------------------------------------------------------------------- /GitHub/mplfinance/tests/reference_images/addplot02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/tests/reference_images/addplot02.png -------------------------------------------------------------------------------- /GitHub/mplfinance/tests/reference_images/addplot03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/tests/reference_images/addplot03.png -------------------------------------------------------------------------------- /GitHub/mplfinance/tests/reference_images/addplot04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/riron1206/candlestick_model/HEAD/GitHub/mplfinance/tests/reference_images/addplot04.png -------------------------------------------------------------------------------- /GitHub/mplfinance/src/mplfinance/_styledata/sas.py: -------------------------------------------------------------------------------- 1 | # style sas is just an abbreviation for starsandstripes: 2 | 3 | from mplfinance._styledata import starsandstripes 4 | style = starsandstripes.style 5 | -------------------------------------------------------------------------------- /GitHub/mplfinance/.travis.yml: -------------------------------------------------------------------------------- 1 | dist: xenial 2 | sudo: false 3 | language: python 4 | matrix: 5 | include: 6 | - python: 3.6 7 | - python: 3.7 8 | - python: 3.8 9 | install: 10 | - pip install tox-travis 11 | script: tox 12 | -------------------------------------------------------------------------------- /GitHub/mplfinance/src/mplfinance/__init__.py: -------------------------------------------------------------------------------- 1 | from mplfinance.plotting import plot, make_addplot 2 | from mplfinance._styles import make_mpf_style, make_marketcolors, available_styles 3 | from mplfinance._version import __version__ 4 | import mplfinance._mpf_warnings 5 | -------------------------------------------------------------------------------- /GitHub/mplfinance/src/mplfinance/_version.py: -------------------------------------------------------------------------------- 1 | version_info = (0, 12, 3, 'alpha', 5) 2 | 3 | _specifier_ = {'alpha': 'a', 'beta': 'b', 'candidate': 'rc', 'final': ''} 4 | 5 | __version__ = '%s.%s.%s%s'%(version_info[0], version_info[1], version_info[2], 6 | '' if version_info[3]=='final' else _specifier_[version_info[3]]+str(version_info[4])) 7 | -------------------------------------------------------------------------------- /GitHub/mplfinance/.github/ISSUE_TEMPLATE/feedback.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feedback 3 | about: What do you think of mplfinance? Pros? Cons? Thoughts? 4 | title: 'Comment:' 5 | labels: 'feedback' 6 | assignees: '' 7 | 8 | --- 9 | 10 | What do you think of mplfinance? Pros? Cons? Thoughts? 11 | Thank you for taking the time to provide feedback. Much appreciated! 12 | -------------------------------------------------------------------------------- /code/config/test/param_tmp.py: -------------------------------------------------------------------------------- 1 | def get_class_fine_tuning_parameter_base() -> dict: 2 | """ 3 | Get parameter sample for class fine_tuning (like Keras) 4 | Returns: 5 | dict: parameter sample generated by trial object 6 | """ 7 | return { 8 | "output_dir": r"D:\work\candlestick_model\output\model\ts_dataset_all_2day_label", 9 | } 10 | -------------------------------------------------------------------------------- /GitHub/mplfinance/.github/ISSUE_TEMPLATE/ask-a-question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Ask a Question 3 | about: Question about usage, project priorities, or anything else related to mplfinance. 4 | title: '' 5 | labels: 'question' 6 | assignees: '' 7 | 8 | --- 9 | 10 | Ask anything you want about mplfinance usage, project philosophy and/or priorities, or anything else related to mplfinance. 11 | -------------------------------------------------------------------------------- /GitHub/mplfinance/src/mplfinance/_mpf_warnings.py: -------------------------------------------------------------------------------- 1 | import sys as __sys 2 | if not __sys.warnoptions: 3 | import os as __os 4 | import warnings as __warnings 5 | __warnings.filterwarnings("default",category=DeprecationWarning,module='mplfinance') # Change the filter in this process 6 | __os.environ["PYTHONWARNINGS"] = "default::DeprecationWarning:mplfinance" # Also affect subprocesses 7 | -------------------------------------------------------------------------------- /GitHub/mplfinance/examples/scratch_pad/rcp_to_df.py: -------------------------------------------------------------------------------- 1 | def rcParams_to_df(rcp,name=None): 2 | keys = [] 3 | vals = [] 4 | for item in rcp: 5 | keys.append(item) 6 | vals.append(rcp[item]) 7 | df = pd.DataFrame(vals,index=pd.Index(keys,name='rcParams Key')) 8 | if name is not None: 9 | df.columns = [name] 10 | else: 11 | df.columns = ['Value'] 12 | return df 13 | -------------------------------------------------------------------------------- /predict_post_slack.bat: -------------------------------------------------------------------------------- 1 | @rem 作成日2020/08/10 シグナルcsvファイルを更新して銘柄コードをSlackに送る 2 | 3 | call activate tfgpu 4 | 5 | cd code 6 | 7 | call python tf_predict_best_model.py --is_2day_label 8 | 9 | call python tf_predict_best_model.py -m D:\work\candlestick_model\output\model\ts_dataset_all_positive_negative_line_label\best_val_loss.h5 -o D:\work\candlestick_model\output\model\ts_dataset_all_positive_negative_line_label\predict --is_positive_negative_line_label 10 | 11 | call python post_my_slack.py 12 | 13 | @rem pause -------------------------------------------------------------------------------- /GitHub/mplfinance/doc/source/examples.rst: -------------------------------------------------------------------------------- 1 | Examples 2 | ======== 3 | 4 | .. plot:: ../../examples/date_demo1.py 5 | :include-source: 6 | 7 | .. plot:: ../../examples/date_demo2.py 8 | :include-source: 9 | 10 | .. plot:: ../../examples/finance_demo.py 11 | :include-source: 12 | 13 | .. plot:: ../../examples/finance_work2.py 14 | :include-source: 15 | 16 | .. plot:: ../../examples/longshort.py 17 | :include-source: 18 | 19 | .. plot:: ../../examples/plot_day_summary_oclh_demo.py 20 | :include-source: 21 | -------------------------------------------------------------------------------- /GitHub/mplfinance/tests/conftest.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | import os 3 | import pandas as pd 4 | import os.path 5 | 6 | os.environ['MPLBACKEND'] = 'agg' 7 | 8 | print('\npd.__version__ =',pd.__version__ ) # for the record 9 | 10 | infile = os.path.join('examples','data','SPY_20110701_20120630_Bollinger.csv') 11 | df = pd.read_csv(infile,index_col=0,parse_dates=True) 12 | print('df.shape=' , df.shape ) 13 | print('df.head(3)=', df.head(3)) 14 | print('df.tail(3)=', df.tail(3)) 15 | 16 | @pytest.fixture() 17 | def bolldata(): 18 | return df 19 | -------------------------------------------------------------------------------- /GitHub/mplfinance/tox.ini: -------------------------------------------------------------------------------- 1 | # Tox (http://tox.testrun.org/) is a tool for running tests 2 | # in multiple virtualenvs. This configuration file will run the 3 | # test suite on all supported python versions. To use it, "pip install tox" 4 | # and then run "tox" from this directory. 5 | 6 | [tox] 7 | envlist = py36, py37, py38 8 | 9 | [pytest] 10 | python_files = tests/* 11 | 12 | [testenv] 13 | deps = 14 | matplotlib 15 | numpy 16 | pandas 17 | pytest 18 | setenv = 19 | # don't use interactive backend for matplotlib in e2e tests 20 | MPLBACKEND = agg 21 | commands = 22 | pytest 23 | -------------------------------------------------------------------------------- /code/config/test/test.py: -------------------------------------------------------------------------------- 1 | import os, sys, argparse 2 | 3 | sys.path.append( 4 | r"C:\Users\81908\jupyter_notebook\tf_2_work\stock_work\candlestick_model\code\config" 5 | ) 6 | 7 | if __name__ == "__main__": 8 | ap = argparse.ArgumentParser() 9 | ap.add_argument("-p", "--param", type=str, default="param_2day_label.py") 10 | args = vars(ap.parse_args()) 11 | 12 | if args["param"] == "param_2day_label.py": 13 | import param_2day_label as param_py 14 | else: 15 | import param_tmp as param_py 16 | 17 | params = param_py.get_class_fine_tuning_parameter_base() 18 | print(params) 19 | -------------------------------------------------------------------------------- /jpx400_nikkei225_500_split/501-561.txt: -------------------------------------------------------------------------------- 1 | 9048 2 | 9062 3 | 9064 4 | 9065 5 | 9076 6 | 9086 7 | 9101 8 | 9104 9 | 9107 10 | 9142 11 | 9143 12 | 9201 13 | 9202 14 | 9232 15 | 9301 16 | 9303 17 | 9364 18 | 9401 19 | 9404 20 | 9412 21 | 9432 22 | 9433 23 | 9435 24 | 9437 25 | 9449 26 | 9468 27 | 9501 28 | 9502 29 | 9503 30 | 9504 31 | 9505 32 | 9506 33 | 9507 34 | 9508 35 | 9509 36 | 9513 37 | 9531 38 | 9532 39 | 9533 40 | 9602 41 | 9603 42 | 9613 43 | 9627 44 | 9678 45 | 9681 46 | 9684 47 | 9697 48 | 9706 49 | 9719 50 | 9735 51 | 9744 52 | 9766 53 | 9783 54 | 9810 55 | 9831 56 | 9843 57 | 9962 58 | 9983 59 | 9984 60 | 9987 61 | 9989 62 | -------------------------------------------------------------------------------- /GitHub/mplfinance/.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: 'Feature Request:' 5 | labels: 'enhancement' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /GitHub/mplfinance/.github/workflows/pythonpublish.yml: -------------------------------------------------------------------------------- 1 | name: Upload Python Package 2 | 3 | on: 4 | release: 5 | types: [created] 6 | 7 | jobs: 8 | deploy: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v1 12 | - name: Set up Python 13 | uses: actions/setup-python@v1 14 | with: 15 | python-version: '3.x' 16 | - name: Install dependencies 17 | run: | 18 | python -m pip install --upgrade pip 19 | pip install setuptools wheel twine 20 | - name: Build and publish 21 | env: 22 | TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} 23 | TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} 24 | run: | 25 | python setup.py sdist bdist_wheel 26 | twine upload dist/* 27 | -------------------------------------------------------------------------------- /GitHub/mplfinance/examples/scratch_pad/rcpars.py: -------------------------------------------------------------------------------- 1 | # This allows multiple outputs from a single jupyter notebook cell: 2 | import pandas as pd 3 | import mplfinance as mpf 4 | 5 | daily = pd.read_csv('../data/SP500_NOV2019_Hist.csv',index_col=0,parse_dates=True) 6 | daily.index.name = 'Date' 7 | daily.shape 8 | daily.head(2) 9 | daily.tail(2) 10 | 11 | ##mpf.plot(daily) 12 | 13 | import matplotlib as mpl 14 | import matplotlib.pyplot as plt 15 | 16 | 17 | prop_cycle = mpl.rcParams['axes.prop_cycle'] 18 | colors = [item['color'] for item in prop_cycle] 19 | 20 | #plt.rcParams['axes.facecolor'] = '#b4dced' 21 | 22 | jj = 0 23 | fig, axs = plt.subplots(2,5) 24 | for ax in axs.flat: 25 | plt.rcParams['axes.facecolor'] = colors[jj] 26 | print("plt.rcParams['axes.facecolor'] = ",plt.rcParams['axes.facecolor']) 27 | ax.plot([1,1]) 28 | ax.draw() 29 | jj+=1 30 | 31 | plt.show() 32 | -------------------------------------------------------------------------------- /nikkei1000_split/901-994.txt: -------------------------------------------------------------------------------- 1 | 2492 2 | 2702 3 | 3087 4 | 3197 5 | 3543 6 | 3563 7 | 3626 8 | 3632 9 | 3635 10 | 3659 11 | 3668 12 | 3765 13 | 3769 14 | 3774 15 | 3938 16 | 3978 17 | 4282 18 | 4307 19 | 4321 20 | 4324 21 | 4385 22 | 4544 23 | 4661 24 | 4665 25 | 4680 26 | 4681 27 | 4684 28 | 4686 29 | 4689 30 | 4704 31 | 4708 32 | 4716 33 | 4732 34 | 4733 35 | 4739 36 | 4751 37 | 4755 38 | 4768 39 | 4813 40 | 4819 41 | 4849 42 | 6028 43 | 6055 44 | 6098 45 | 6178 46 | 7412 47 | 7421 48 | 7518 49 | 7522 50 | 7550 51 | 7581 52 | 7616 53 | 7860 54 | 7974 55 | 8056 56 | 8153 57 | 8160 58 | 8179 59 | 8876 60 | 9468 61 | 9474 62 | 9601 63 | 9602 64 | 9603 65 | 9605 66 | 9616 67 | 9672 68 | 9678 69 | 9681 70 | 9682 71 | 9684 72 | 9697 73 | 9699 74 | 9715 75 | 9716 76 | 9719 77 | 9722 78 | 9728 79 | 9735 80 | 9742 81 | 9744 82 | 9746 83 | 9749 84 | 9757 85 | 9759 86 | 9766 87 | 9783 88 | 9787 89 | 9792 90 | 9793 91 | 9861 92 | 9887 93 | 9936 94 | 9945 95 | -------------------------------------------------------------------------------- /GitHub/mplfinance/doc/source/index.rst: -------------------------------------------------------------------------------- 1 | .. mpl_finance documentation master file, created by 2 | sphinx-quickstart on Sat Jan 7 14:48:13 2017. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | mpl_finance: financial helpers for matplotlib 7 | ============================================= 8 | 9 | A collection of functions for analyzing and plotting financial data 10 | in combination with matplotlib. 11 | 12 | .. toctree:: 13 | :maxdepth: 2 14 | 15 | examples 16 | modules 17 | 18 | 19 | This module has been extracted from the core Matplotlib code base 20 | unchanged. Now that this code is separate from the core it can pick 21 | up dependencies, like :mod:`pandas` or :mod:`scipy` and expose a more 22 | powerful API to the user. 23 | 24 | We are looking for a finance domain-expert to lead this effort! 25 | 26 | 27 | * :ref:`genindex` 28 | * :ref:`search` 29 | -------------------------------------------------------------------------------- /GitHub/mplfinance/doc/source/mpl_finance.rst: -------------------------------------------------------------------------------- 1 | mpl_finance module 2 | ================== 3 | 4 | .. automodule:: mpl_finance 5 | :no-members: 6 | 7 | 8 | Daily Summary 9 | ------------- 10 | 11 | .. autosummary:: 12 | :toctree: _as_gen 13 | :nosignatures: 14 | 15 | 16 | plot_day_summary_oclh 17 | plot_day_summary_ohlc 18 | plot_day_summary2_ochl 19 | plot_day_summary2_ohlc 20 | 21 | Candlesticks 22 | ------------ 23 | 24 | 25 | .. autosummary:: 26 | :toctree: _as_gen 27 | :nosignatures: 28 | 29 | candlestick_ochl 30 | candlestick_ohlc 31 | 32 | 33 | candlestick2_ochl 34 | candlestick2_ohlc 35 | 36 | Volume Overlay 37 | -------------- 38 | 39 | 40 | .. autosummary:: 41 | :toctree: _as_gen 42 | :nosignatures: 43 | 44 | volume_overlay 45 | volume_overlay2 46 | volume_overlay3 47 | 48 | Other 49 | ----- 50 | 51 | .. autosummary:: 52 | :toctree: _as_gen 53 | :nosignatures: 54 | 55 | index_bar 56 | -------------------------------------------------------------------------------- /code/model_paper.py: -------------------------------------------------------------------------------- 1 | """ 2 | 論文のcnnモデル再現 3 | https://www.arxiv-vanity.com/papers/1903.12258/ 4 | """ 5 | import tensorflow as tf 6 | import tensorflow.keras.layers as layers 7 | 8 | 9 | def create_paper_cnn(input_shape=(80, 80, 3), num_classes=3, activation="softmax"): 10 | inputs = layers.Input(input_shape) 11 | x = inputs 12 | for ch in [32, 48]: 13 | x = layers.Conv2D(ch, 3, padding="same")(x) 14 | x = layers.ReLU()(x) 15 | x = layers.MaxPool2D()(x) 16 | x = layers.Dropout(0.2)(x) 17 | for ch in [64, 96]: 18 | x = layers.Conv2D(ch, 3, padding="same")(x) 19 | x = layers.ReLU()(x) 20 | x = layers.MaxPool2D()(x) 21 | x = layers.Dropout(0.2)(x) 22 | x = layers.Flatten()(x) 23 | x = layers.Dense(256)(x) 24 | x = layers.Dropout(0.2)(x) 25 | x = layers.Dense(num_classes, activation=activation)(x) 26 | return tf.keras.models.Model(inputs, x) 27 | 28 | 29 | if __name__ == "__main__": 30 | model = create_paper_cnn() 31 | model.summary() 32 | -------------------------------------------------------------------------------- /GitHub/mplfinance/.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: 'Bug Report:' 5 | labels: 'bug' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /nikkei1000_split/1-100.txt: -------------------------------------------------------------------------------- 1 | 1332 2 | 1333 3 | 1377 4 | 1379 5 | 1515 6 | 1605 7 | 1662 8 | 1414 9 | 1417 10 | 1719 11 | 1720 12 | 1721 13 | 1766 14 | 1801 15 | 1802 16 | 1803 17 | 1808 18 | 1812 19 | 1820 20 | 1821 21 | 1824 22 | 1833 23 | 1835 24 | 1860 25 | 1861 26 | 1878 27 | 1881 28 | 1883 29 | 1885 30 | 1893 31 | 1911 32 | 1925 33 | 1928 34 | 1941 35 | 1942 36 | 1944 37 | 1946 38 | 1950 39 | 1951 40 | 1959 41 | 1961 42 | 1963 43 | 1968 44 | 1969 45 | 1979 46 | 1982 47 | 5912 48 | 6379 49 | 2001 50 | 2002 51 | 2004 52 | 2108 53 | 2109 54 | 2201 55 | 2204 56 | 2206 57 | 2212 58 | 2220 59 | 2222 60 | 2229 61 | 2264 62 | 2267 63 | 2269 64 | 2270 65 | 2281 66 | 2282 67 | 2288 68 | 2292 69 | 2296 70 | 2501 71 | 2502 72 | 2503 73 | 2531 74 | 2579 75 | 2587 76 | 2590 77 | 2593 78 | 2594 79 | 2602 80 | 2607 81 | 2613 82 | 2801 83 | 2802 84 | 2809 85 | 2810 86 | 2811 87 | 2815 88 | 2871 89 | 2875 90 | 2897 91 | 2908 92 | 2914 93 | 2931 94 | 3001 95 | 3002 96 | 3101 97 | 3103 98 | 3106 99 | 3107 100 | 3201 101 | -------------------------------------------------------------------------------- /nikkei1000_split/101-200.txt: -------------------------------------------------------------------------------- 1 | 3401 2 | 3402 3 | 3569 4 | 3591 5 | 3593 6 | 3608 7 | 3708 8 | 3861 9 | 3863 10 | 3865 11 | 3880 12 | 3941 13 | 3405 14 | 3407 15 | 4004 16 | 4005 17 | 4021 18 | 4023 19 | 4028 20 | 4041 21 | 4042 22 | 4043 23 | 4044 24 | 4045 25 | 4061 26 | 4063 27 | 4078 28 | 4088 29 | 4091 30 | 4092 31 | 4095 32 | 4109 33 | 4114 34 | 4116 35 | 4118 36 | 4182 37 | 4183 38 | 4185 39 | 4186 40 | 4188 41 | 4189 42 | 4202 43 | 4203 44 | 4204 45 | 4205 46 | 4206 47 | 4208 48 | 4212 49 | 4221 50 | 4272 51 | 4401 52 | 4403 53 | 4452 54 | 4471 55 | 4612 56 | 4613 57 | 4617 58 | 4626 59 | 4631 60 | 4634 61 | 4636 62 | 4901 63 | 4911 64 | 4912 65 | 4914 66 | 4917 67 | 4919 68 | 4921 69 | 4922 70 | 4927 71 | 4928 72 | 4958 73 | 4966 74 | 4985 75 | 4996 76 | 4997 77 | 5142 78 | 5208 79 | 6988 80 | 7958 81 | 7970 82 | 7995 83 | 4151 84 | 4502 85 | 4503 86 | 4506 87 | 4507 88 | 4516 89 | 4519 90 | 4521 91 | 4523 92 | 4527 93 | 4528 94 | 4530 95 | 4534 96 | 4536 97 | 4540 98 | 4541 99 | 4547 100 | 4548 101 | -------------------------------------------------------------------------------- /nikkei1000_split/201-300.txt: -------------------------------------------------------------------------------- 1 | 4549 2 | 4551 3 | 4552 4 | 4553 5 | 4555 6 | 4559 7 | 4563 8 | 4564 9 | 4565 10 | 4568 11 | 4569 12 | 4571 13 | 4578 14 | 4581 15 | 4587 16 | 4592 17 | 4967 18 | 4974 19 | 5017 20 | 5019 21 | 5020 22 | 5021 23 | 5101 24 | 5105 25 | 5108 26 | 5110 27 | 5122 28 | 5186 29 | 5191 30 | 5192 31 | 5195 32 | 3110 33 | 5201 34 | 5202 35 | 5214 36 | 5232 37 | 5233 38 | 5301 39 | 5302 40 | 5310 41 | 5331 42 | 5332 43 | 5333 44 | 5334 45 | 5344 46 | 5384 47 | 5393 48 | 7943 49 | 5401 50 | 5406 51 | 5410 52 | 5411 53 | 5423 54 | 5440 55 | 5444 56 | 5451 57 | 5463 58 | 5471 59 | 5480 60 | 5481 61 | 5482 62 | 5486 63 | 5541 64 | 5563 65 | 5632 66 | 3433 67 | 3436 68 | 5703 69 | 5706 70 | 5707 71 | 5711 72 | 5713 73 | 5714 74 | 5715 75 | 5726 76 | 5727 77 | 5741 78 | 5801 79 | 5802 80 | 5803 81 | 5805 82 | 5851 83 | 5852 84 | 5857 85 | 5901 86 | 5909 87 | 5929 88 | 5930 89 | 5932 90 | 5938 91 | 5943 92 | 5946 93 | 5947 94 | 5975 95 | 5976 96 | 5981 97 | 5988 98 | 5991 99 | 8155 100 | 5631 101 | -------------------------------------------------------------------------------- /nikkei1000_split/301-400.txt: -------------------------------------------------------------------------------- 1 | 6005 2 | 6013 3 | 6101 4 | 6103 5 | 6104 6 | 6113 7 | 6118 8 | 6134 9 | 6135 10 | 6136 11 | 6140 12 | 6141 13 | 6143 14 | 6151 15 | 6201 16 | 6222 17 | 6235 18 | 6247 19 | 6268 20 | 6269 21 | 6273 22 | 6278 23 | 6282 24 | 6287 25 | 6301 26 | 6302 27 | 6305 28 | 6310 29 | 6324 30 | 6326 31 | 6330 32 | 6339 33 | 6349 34 | 6361 35 | 6363 36 | 6366 37 | 6367 38 | 6368 39 | 6370 40 | 6371 41 | 6383 42 | 6395 43 | 6406 44 | 6407 45 | 6412 46 | 6413 47 | 6417 48 | 6419 49 | 6425 50 | 6432 51 | 6436 52 | 6440 53 | 6444 54 | 6454 55 | 6457 56 | 6460 57 | 6462 58 | 6463 59 | 6464 60 | 6465 61 | 6471 62 | 6472 63 | 6473 64 | 6474 65 | 6480 66 | 6481 67 | 6486 68 | 6498 69 | 7004 70 | 7011 71 | 7013 72 | 7718 73 | 3105 74 | 4062 75 | 6418 76 | 6448 77 | 6479 78 | 6501 79 | 6502 80 | 6503 81 | 6504 82 | 6506 83 | 6507 84 | 6508 85 | 6586 86 | 6588 87 | 6592 88 | 6594 89 | 6622 90 | 6632 91 | 6641 92 | 6645 93 | 6651 94 | 6652 95 | 6674 96 | 6676 97 | 6701 98 | 6702 99 | 6703 100 | 6706 101 | -------------------------------------------------------------------------------- /nikkei1000_split/401-500.txt: -------------------------------------------------------------------------------- 1 | 6707 2 | 6718 3 | 6723 4 | 6724 5 | 6727 6 | 6728 7 | 6737 8 | 6740 9 | 6741 10 | 6752 11 | 6753 12 | 6754 13 | 6755 14 | 6758 15 | 6762 16 | 6768 17 | 6770 18 | 6789 19 | 6794 20 | 6798 21 | 6804 22 | 6806 23 | 6807 24 | 6810 25 | 6841 26 | 6844 27 | 6845 28 | 6849 29 | 6856 30 | 6857 31 | 6861 32 | 6869 33 | 6875 34 | 6890 35 | 6902 36 | 6905 37 | 6908 38 | 6914 39 | 6915 40 | 6920 41 | 6923 42 | 6925 43 | 6929 44 | 6947 45 | 6951 46 | 6952 47 | 6954 48 | 6960 49 | 6961 50 | 6963 51 | 6965 52 | 6966 53 | 6967 54 | 6971 55 | 6976 56 | 6981 57 | 6986 58 | 6996 59 | 6997 60 | 6999 61 | 7280 62 | 7735 63 | 7739 64 | 7751 65 | 7752 66 | 7965 67 | 8035 68 | 7003 69 | 7012 70 | 7014 71 | 3116 72 | 5949 73 | 6995 74 | 7201 75 | 7202 76 | 7203 77 | 7205 78 | 7211 79 | 7220 80 | 7222 81 | 7230 82 | 7236 83 | 7238 84 | 7239 85 | 7240 86 | 7241 87 | 7242 88 | 7246 89 | 7251 90 | 7259 91 | 7261 92 | 7267 93 | 7269 94 | 7270 95 | 7272 96 | 7274 97 | 7276 98 | 7278 99 | 7279 100 | 7282 101 | -------------------------------------------------------------------------------- /nikkei1000_split/501-600.txt: -------------------------------------------------------------------------------- 1 | 7283 2 | 7287 3 | 7294 4 | 7296 5 | 7313 6 | 7102 7 | 7224 8 | 7226 9 | 7231 10 | 7309 11 | 4543 12 | 4902 13 | 6146 14 | 6376 15 | 7701 16 | 7716 17 | 7717 18 | 7729 19 | 7730 20 | 7731 21 | 7732 22 | 7733 23 | 7740 24 | 7741 25 | 7747 26 | 7762 27 | 7779 28 | 7780 29 | 8050 30 | 8086 31 | 7817 32 | 7832 33 | 7840 34 | 7846 35 | 7862 36 | 7864 37 | 7867 38 | 7905 39 | 7911 40 | 7912 41 | 7914 42 | 7915 43 | 7936 44 | 7947 45 | 7951 46 | 7956 47 | 7966 48 | 7976 49 | 7981 50 | 7984 51 | 7988 52 | 7994 53 | 8022 54 | 2692 55 | 2733 56 | 2768 57 | 2784 58 | 2874 59 | 3038 60 | 3076 61 | 3132 62 | 3151 63 | 3167 64 | 3360 65 | 7433 66 | 7447 67 | 7451 68 | 7458 69 | 7459 70 | 7476 71 | 7483 72 | 7575 73 | 7599 74 | 8001 75 | 8002 76 | 8011 77 | 8012 78 | 8015 79 | 8016 80 | 8020 81 | 8031 82 | 8032 83 | 8051 84 | 8053 85 | 8057 86 | 8058 87 | 8060 88 | 8066 89 | 8068 90 | 8078 91 | 8088 92 | 8098 93 | 8111 94 | 8113 95 | 8114 96 | 8129 97 | 8130 98 | 8133 99 | 8136 100 | 8140 101 | -------------------------------------------------------------------------------- /nikkei1000_split/601-700.txt: -------------------------------------------------------------------------------- 1 | 8151 2 | 8154 3 | 8283 4 | 9810 5 | 9830 6 | 9832 7 | 9869 8 | 9934 9 | 9962 10 | 9987 11 | 2651 12 | 2659 13 | 2664 14 | 2670 15 | 2678 16 | 2681 17 | 2685 18 | 2730 19 | 2782 20 | 2790 21 | 3028 22 | 3046 23 | 3048 24 | 3050 25 | 3064 26 | 3086 27 | 3088 28 | 3092 29 | 3098 30 | 3099 31 | 3141 32 | 3148 33 | 3191 34 | 3222 35 | 3349 36 | 3382 37 | 3391 38 | 3395 39 | 3549 40 | 7453 41 | 7516 42 | 7532 43 | 7545 44 | 7606 45 | 7649 46 | 8028 47 | 8168 48 | 8173 49 | 8174 50 | 8182 51 | 8184 52 | 8185 53 | 8194 54 | 8214 55 | 8217 56 | 8218 57 | 8219 58 | 8227 59 | 8233 60 | 8237 61 | 8242 62 | 8252 63 | 8267 64 | 8273 65 | 8276 66 | 8278 67 | 8279 68 | 8281 69 | 8282 70 | 9627 71 | 9831 72 | 9843 73 | 9946 74 | 9948 75 | 9956 76 | 9983 77 | 9989 78 | 9997 79 | 7167 80 | 7173 81 | 7180 82 | 7182 83 | 7186 84 | 7189 85 | 7321 86 | 7322 87 | 7327 88 | 8303 89 | 8304 90 | 8306 91 | 8308 92 | 8309 93 | 8316 94 | 8331 95 | 8334 96 | 8336 97 | 8337 98 | 8338 99 | 8341 100 | 8342 101 | -------------------------------------------------------------------------------- /nikkei1000_split/701-800.txt: -------------------------------------------------------------------------------- 1 | 8343 2 | 8344 3 | 8345 4 | 8346 5 | 8350 6 | 8354 7 | 8355 8 | 8356 9 | 8358 10 | 8359 11 | 8360 12 | 8361 13 | 8362 14 | 8363 15 | 8364 16 | 8366 17 | 8367 18 | 8368 19 | 8369 20 | 8370 21 | 8377 22 | 8379 23 | 8381 24 | 8382 25 | 8385 26 | 8386 27 | 8387 28 | 8388 29 | 8392 30 | 8393 31 | 8395 32 | 8397 33 | 8399 34 | 8410 35 | 8411 36 | 8418 37 | 8522 38 | 8524 39 | 8527 40 | 8530 41 | 8541 42 | 8544 43 | 8550 44 | 8551 45 | 8558 46 | 8600 47 | 8713 48 | 8714 49 | 7148 50 | 7164 51 | 8253 52 | 8424 53 | 8425 54 | 8439 55 | 8473 56 | 8508 57 | 8511 58 | 8515 59 | 8566 60 | 8570 61 | 8572 62 | 8584 63 | 8585 64 | 8586 65 | 8591 66 | 8593 67 | 8595 68 | 8697 69 | 8739 70 | 8601 71 | 8604 72 | 8609 73 | 8613 74 | 8616 75 | 8624 76 | 8628 77 | 8698 78 | 8699 79 | 7181 80 | 8630 81 | 8725 82 | 8729 83 | 8750 84 | 8766 85 | 8795 86 | 2337 87 | 3003 88 | 3231 89 | 3288 90 | 3289 91 | 3291 92 | 4666 93 | 8801 94 | 8802 95 | 8803 96 | 8804 97 | 8806 98 | 8830 99 | 8841 100 | 8848 101 | -------------------------------------------------------------------------------- /nikkei1000_split/801-900.txt: -------------------------------------------------------------------------------- 1 | 8850 2 | 8871 3 | 8905 4 | 8919 5 | 9706 6 | 9001 7 | 9003 8 | 9005 9 | 9006 10 | 9007 11 | 9008 12 | 9009 13 | 9010 14 | 9020 15 | 9021 16 | 9022 17 | 9024 18 | 9031 19 | 9041 20 | 9042 21 | 9044 22 | 9045 23 | 9048 24 | 9052 25 | 9081 26 | 9142 27 | 9062 28 | 9064 29 | 9065 30 | 9069 31 | 9072 32 | 9075 33 | 9076 34 | 9086 35 | 9143 36 | 9101 37 | 9104 38 | 9107 39 | 9110 40 | 9119 41 | 9201 42 | 9202 43 | 3738 44 | 4676 45 | 9401 46 | 9404 47 | 9409 48 | 9412 49 | 9424 50 | 9432 51 | 9433 52 | 9434 53 | 9435 54 | 9437 55 | 9449 56 | 9613 57 | 9984 58 | 9301 59 | 9302 60 | 9303 61 | 9364 62 | 9375 63 | 9501 64 | 9502 65 | 9503 66 | 9504 67 | 9505 68 | 9506 69 | 9507 70 | 9508 71 | 9509 72 | 9511 73 | 9513 74 | 9531 75 | 9532 76 | 9533 77 | 9536 78 | 9543 79 | 1973 80 | 2121 81 | 2127 82 | 2146 83 | 2168 84 | 2174 85 | 2175 86 | 2181 87 | 2193 88 | 2317 89 | 2326 90 | 2327 91 | 2331 92 | 2371 93 | 2379 94 | 2412 95 | 2413 96 | 2427 97 | 2432 98 | 2433 99 | 2440 100 | 2461 101 | -------------------------------------------------------------------------------- /jpx400_nikkei225_500_split/1-100.txt: -------------------------------------------------------------------------------- 1 | 1332 2 | 1333 3 | 1379 4 | 1518 5 | 1605 6 | 1662 7 | 1719 8 | 1720 9 | 1721 10 | 1801 11 | 1802 12 | 1803 13 | 1808 14 | 1812 15 | 1820 16 | 1821 17 | 1824 18 | 1860 19 | 1861 20 | 1878 21 | 1881 22 | 1893 23 | 1911 24 | 1925 25 | 1928 26 | 1942 27 | 1944 28 | 1951 29 | 1959 30 | 1963 31 | 2002 32 | 2121 33 | 2124 34 | 2127 35 | 2146 36 | 2175 37 | 2181 38 | 2201 39 | 2206 40 | 2212 41 | 2229 42 | 2264 43 | 2267 44 | 2269 45 | 2270 46 | 2282 47 | 2296 48 | 2327 49 | 2331 50 | 2337 51 | 2371 52 | 2379 53 | 2412 54 | 2413 55 | 2427 56 | 2432 57 | 2433 58 | 2501 59 | 2502 60 | 2503 61 | 2531 62 | 2579 63 | 2587 64 | 2593 65 | 2607 66 | 2651 67 | 2670 68 | 2702 69 | 2730 70 | 2768 71 | 2782 72 | 2784 73 | 2801 74 | 2802 75 | 2809 76 | 2810 77 | 2811 78 | 2815 79 | 2871 80 | 2875 81 | 2897 82 | 2914 83 | 3003 84 | 3038 85 | 3048 86 | 3064 87 | 3086 88 | 3088 89 | 3092 90 | 3099 91 | 3101 92 | 3103 93 | 3105 94 | 3107 95 | 3116 96 | 3141 97 | 3148 98 | 3167 99 | 3197 100 | 3231 101 | -------------------------------------------------------------------------------- /jpx400_nikkei225_500_split/101-200.txt: -------------------------------------------------------------------------------- 1 | 3254 2 | 3288 3 | 3289 4 | 3291 5 | 3349 6 | 3360 7 | 3382 8 | 3391 9 | 3401 10 | 3402 11 | 3405 12 | 3407 13 | 3436 14 | 3543 15 | 3549 16 | 3626 17 | 3632 18 | 3656 19 | 3659 20 | 3668 21 | 3738 22 | 3765 23 | 3769 24 | 3861 25 | 3863 26 | 3865 27 | 3932 28 | 3938 29 | 3941 30 | 4004 31 | 4005 32 | 4021 33 | 4041 34 | 4042 35 | 4043 36 | 4061 37 | 4062 38 | 4063 39 | 4088 40 | 4091 41 | 4114 42 | 4118 43 | 4151 44 | 4182 45 | 4183 46 | 4185 47 | 4188 48 | 4202 49 | 4203 50 | 4204 51 | 4205 52 | 4206 53 | 4208 54 | 4246 55 | 4272 56 | 4307 57 | 4321 58 | 4324 59 | 4403 60 | 4452 61 | 4502 62 | 4503 63 | 4506 64 | 4507 65 | 4516 66 | 4519 67 | 4521 68 | 4523 69 | 4527 70 | 4528 71 | 4530 72 | 4536 73 | 4540 74 | 4543 75 | 4544 76 | 4555 77 | 4568 78 | 4578 79 | 4581 80 | 4587 81 | 4612 82 | 4613 83 | 4631 84 | 4661 85 | 4666 86 | 4676 87 | 4680 88 | 4681 89 | 4684 90 | 4689 91 | 4704 92 | 4716 93 | 4732 94 | 4739 95 | 4751 96 | 4755 97 | 4768 98 | 4819 99 | 4849 100 | 4901 101 | -------------------------------------------------------------------------------- /jpx400_nikkei225_500_split/201-300.txt: -------------------------------------------------------------------------------- 1 | 4902 2 | 4911 3 | 4912 4 | 4921 5 | 4922 6 | 4927 7 | 4967 8 | 4974 9 | 5019 10 | 5020 11 | 5021 12 | 5101 13 | 5105 14 | 5108 15 | 5110 16 | 5201 17 | 5202 18 | 5214 19 | 5232 20 | 5233 21 | 5301 22 | 5332 23 | 5333 24 | 5334 25 | 5393 26 | 5401 27 | 5406 28 | 5411 29 | 5423 30 | 5444 31 | 5463 32 | 5471 33 | 5486 34 | 5541 35 | 5631 36 | 5703 37 | 5706 38 | 5707 39 | 5711 40 | 5713 41 | 5714 42 | 5741 43 | 5801 44 | 5802 45 | 5803 46 | 5901 47 | 5929 48 | 5938 49 | 5947 50 | 5975 51 | 5991 52 | 6028 53 | 6098 54 | 6103 55 | 6113 56 | 6135 57 | 6136 58 | 6141 59 | 6146 60 | 6178 61 | 6201 62 | 6268 63 | 6269 64 | 6273 65 | 6301 66 | 6302 67 | 6305 68 | 6324 69 | 6326 70 | 6361 71 | 6367 72 | 6370 73 | 6383 74 | 6395 75 | 6412 76 | 6417 77 | 6432 78 | 6448 79 | 6460 80 | 6463 81 | 6465 82 | 6471 83 | 6472 84 | 6473 85 | 6479 86 | 6481 87 | 6501 88 | 6503 89 | 6504 90 | 6506 91 | 6586 92 | 6588 93 | 6592 94 | 6594 95 | 6632 96 | 6641 97 | 6645 98 | 6674 99 | 6701 100 | 6702 101 | -------------------------------------------------------------------------------- /jpx400_nikkei225_500_split/301-400.txt: -------------------------------------------------------------------------------- 1 | 6703 2 | 6723 3 | 6724 4 | 6727 5 | 6728 6 | 6740 7 | 6750 8 | 6752 9 | 6753 10 | 6754 11 | 6755 12 | 6758 13 | 6762 14 | 6770 15 | 6806 16 | 6807 17 | 6841 18 | 6845 19 | 6849 20 | 6856 21 | 6857 22 | 6861 23 | 6869 24 | 6877 25 | 6902 26 | 6920 27 | 6923 28 | 6925 29 | 6952 30 | 6954 31 | 6963 32 | 6965 33 | 6967 34 | 6971 35 | 6976 36 | 6981 37 | 6988 38 | 6995 39 | 7003 40 | 7004 41 | 7011 42 | 7012 43 | 7013 44 | 7014 45 | 7148 46 | 7164 47 | 7167 48 | 7180 49 | 7181 50 | 7182 51 | 7186 52 | 7189 53 | 7201 54 | 7202 55 | 7203 56 | 7205 57 | 7211 58 | 7224 59 | 7231 60 | 7240 61 | 7251 62 | 7259 63 | 7261 64 | 7267 65 | 7269 66 | 7270 67 | 7272 68 | 7276 69 | 7282 70 | 7309 71 | 7313 72 | 7419 73 | 7453 74 | 7458 75 | 7459 76 | 7518 77 | 7532 78 | 7550 79 | 7564 80 | 7575 81 | 7606 82 | 7649 83 | 7701 84 | 7717 85 | 7729 86 | 7731 87 | 7732 88 | 7733 89 | 7735 90 | 7741 91 | 7747 92 | 7751 93 | 7752 94 | 7762 95 | 7832 96 | 7846 97 | 7867 98 | 7911 99 | 7912 100 | 7915 101 | -------------------------------------------------------------------------------- /jpx400_nikkei225_500_split/401-500.txt: -------------------------------------------------------------------------------- 1 | 7936 2 | 7951 3 | 7956 4 | 7974 5 | 7988 6 | 8001 7 | 8002 8 | 8015 9 | 8016 10 | 8020 11 | 8028 12 | 8031 13 | 8035 14 | 8053 15 | 8056 16 | 8058 17 | 8060 18 | 8086 19 | 8088 20 | 8111 21 | 8113 22 | 8136 23 | 8227 24 | 8233 25 | 8242 26 | 8252 27 | 8253 28 | 8267 29 | 8273 30 | 8279 31 | 8282 32 | 8283 33 | 8303 34 | 8304 35 | 8306 36 | 8308 37 | 8309 38 | 8316 39 | 8331 40 | 8334 41 | 8354 42 | 8355 43 | 8358 44 | 8359 45 | 8369 46 | 8377 47 | 8379 48 | 8382 49 | 8385 50 | 8410 51 | 8411 52 | 8418 53 | 8424 54 | 8439 55 | 8473 56 | 8515 57 | 8524 58 | 8570 59 | 8572 60 | 8585 61 | 8586 62 | 8591 63 | 8593 64 | 8595 65 | 8601 66 | 8604 67 | 8609 68 | 8616 69 | 8628 70 | 8630 71 | 8697 72 | 8698 73 | 8725 74 | 8729 75 | 8750 76 | 8766 77 | 8795 78 | 8801 79 | 8802 80 | 8804 81 | 8830 82 | 8848 83 | 8850 84 | 8876 85 | 8905 86 | 9001 87 | 9003 88 | 9005 89 | 9006 90 | 9007 91 | 9008 92 | 9009 93 | 9020 94 | 9021 95 | 9022 96 | 9024 97 | 9041 98 | 9042 99 | 9044 100 | 9045 101 | -------------------------------------------------------------------------------- /GitHub/mplfinance/src/mplfinance/_styledata/starsandstripes.py: -------------------------------------------------------------------------------- 1 | style = {'base_mpl_style': 'fast', 2 | 'marketcolors': {'candle': {'up': '#082865', 'down': '#ae0019'}, 3 | 'edge' : {'up': '#082865', 'down': '#ae0019'}, 4 | 'wick' : {'up': '#082865', 'down': '#ae0019'}, 5 | 'ohlc' : {'up': '#082865', 'down': '#ae0019'}, 6 | 'volume': {'up': '#082865', 'down': '#ae0019'}, 7 | 'vcedge': {'up': '#1f77b4', 'down': '#1f77b4'}, 8 | 'vcdopcod': False, 9 | 'alpha': 0.9}, 10 | 'mavcolors': None, 11 | 'facecolor': None, 12 | 'gridcolor': None, 13 | 'gridstyle': None, 14 | 'y_on_right': True, 15 | 'rc': {'axes.edgecolor': '#082865', 16 | 'axes.grid' : True, 17 | 'axes.grid.axis': 'y', 18 | 'grid.color' : '#082865', 19 | 'grid.linestyle': '--' 20 | }, 21 | 'base_mpf_style': 'starsandstripes' 22 | } 23 | -------------------------------------------------------------------------------- /GitHub/mplfinance/examples/scratch_pad/tplot.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | daily = pd.read_csv('../data/SP500_NOV2019_Hist.csv',index_col=0,parse_dates=True) 3 | daily.head(3) 4 | 5 | # idf = pd.read_csv('data/SP500_NOV2019_IDay.csv',index_col=0,parse_dates=True) 6 | # idf = idf.drop('Volume',axis=1) # Volume is zero anyway for this intraday data set 7 | # idf.index.name = 'Date' 8 | # daily = pd.read_csv('data/SP600_NOV2019_Hist.csv',index_col=0,parse_dates=True) 9 | # daily = pd.read_csv('data/SP500_NOV2019_Hist.csv',index_col=0,parse_dates=True) 10 | # daily = pd.read_csv('data/SP500_NOV2019_Hist.csv',index_col=0,parse_dates=True) 11 | 12 | import mplfinance as mpf 13 | mpf.__file__ 14 | mpf.plot(daily,mav=7,block=False) 15 | mpf.plot(daily,volume=True,block=False) 16 | 17 | df = pd.read_csv('../data/yahoofinance-SPY-20080101-20180101.csv',index_col=0,parse_dates=True) 18 | mpf.plot(df[700:850],type='bars',volume=True,mav=(20,40),figscale=0.7,block=False) 19 | 20 | mpf.plot(df[700:850],type='bars',no_xgaps=True,mav=(20,40),figscale=0.7,block=False) 21 | mpf.plot(df[700:850],type='candle',volume=True,mav=(20,40),figscale=0.7,style='charles') 22 | -------------------------------------------------------------------------------- /GitHub/mplfinance/src/mplfinance/_styledata/brasil.py: -------------------------------------------------------------------------------- 1 | style = {'base_mpl_style': 'fast', 2 | 'marketcolors': {'candle': {'up': '#fedf00', 'down': '#002776'}, 3 | 'edge' : {'up': '#fedf00', 'down': '#002776'}, 4 | 'wick' : {'up': '#fedf00', 'down': '#002776'}, 5 | 'ohlc' : {'up': '#fedf00', 'down': '#002776'}, 6 | 'volume': {'up': '#fedf00', 'down': '#002776'}, 7 | 'vcedge': {'up': '#1f77b4', 'down': '#1f77b4'}, 8 | 'vcdopcod': False, 9 | 'alpha': 0.9}, 10 | 'mavcolors' : None, 11 | 'facecolor' : None, 12 | 'gridcolor' : None, 13 | 'gridstyle' : None, 14 | 'y_on_right': True, 15 | 'rc': {'axes.grid' : True, 16 | 'axes.grid.axis': 'y', 17 | 'grid.color' : '#fedf00', 18 | 'grid.linestyle': '--', 19 | 'axes.facecolor': '#009b3a', 20 | 'axes.edgecolor': '#002776' 21 | }, 22 | 'base_mpf_style': 'brasil' 23 | } 24 | -------------------------------------------------------------------------------- /predict.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | PWDDIR=`pwd` 3 | 4 | PY_DIR=code 5 | 6 | conda activate tfgpu 7 | 8 | tf_base_class_all_data_positive_negative_line_label() { 9 | # 翌日が陽線、陰線か + 移動平均線つきについてモデル作成 10 | 11 | # スズキ 12 | #python ${PY_DIR}/tf_predict_best_model.py \ 13 | # -c 7269 \ 14 | # -d 2020-08-10 \ 15 | # -t_d 10 \ 16 | # -m /d/work/candlestick_model/output/model/ts_dataset_all_positive_negative_line_label/best_val_loss.h5 \ 17 | # -o /d/work/candlestick_model/output/model/ts_dataset_all_positive_negative_line_label/predict \ 18 | # --is_positive_negative_line_label 19 | 20 | # 日経225とか 21 | python ${PY_DIR}/tf_predict_best_model.py \ 22 | -t_d 40 \ 23 | -m /d/work/candlestick_model/output/model/ts_dataset_all_positive_negative_line_label/best_val_loss.h5 \ 24 | -o /d/work/candlestick_model/output/model/ts_dataset_all_positive_negative_line_label/predict \ 25 | --is_positive_negative_line_label 26 | } 27 | 28 | tf_base_class_all_data_positive_negative_line_label; -------------------------------------------------------------------------------- /GitHub/mplfinance/src/mplfinance/_styledata/yahoo.py: -------------------------------------------------------------------------------- 1 | style = {'base_mpl_style': 'fast', 2 | 'marketcolors' : {'candle': {'up': '#00b060', 'down': '#fe3032'}, 3 | 'edge' : {'up': '#00b060', 'down': '#fe3032'}, 4 | 'wick' : {'up': '#606060', 'down': '#606060'}, 5 | 'ohlc' : {'up': '#00b060', 'down': '#fe3032'}, 6 | 'volume': {'up': '#4dc790', 'down': '#fd6b6c'}, 7 | 'vcedge': {'up': '#1f77b4', 'down': '#1f77b4'}, 8 | 'vcdopcod' : True, 9 | 'alpha' : 0.9}, 10 | 'mavcolors' : None, 11 | 'facecolor' : '#fafafa', 12 | 'gridcolor' : '#d0d0d0', 13 | 'gridstyle' : '-', 14 | 'y_on_right' : True, 15 | 'rc' : {'axes.labelcolor': '#101010', 16 | 'axes.edgecolor' : 'f0f0f0', 17 | 'axes.grid.axis' : 'y', 18 | 'ytick.color' : '#101010', 19 | 'xtick.color' : '#101010'}, 20 | 'base_mpf_style': 'yahoo'} 21 | -------------------------------------------------------------------------------- /GitHub/mplfinance/src/mplfinance/_styledata/nightclouds.py: -------------------------------------------------------------------------------- 1 | style = dict(style_name = 'nightclouds', 2 | base_mpl_style='dark_background', 3 | marketcolors = {'candle' : {'up':'w', 'down':'#0095ff'}, 4 | 'edge' : {'up':'w', 'down':'#0095ff'}, 5 | 'wick' : {'up':'w', 'down':'w'}, 6 | 'ohlc' : {'up':'w', 'down':'w'}, 7 | 'volume' : {'up':'w', 'down':'#0095ff'}, 8 | 'vcdopcod': False, 9 | 'alpha' : 1.0, 10 | }, 11 | mavcolors = ['#40e0d0','#ff00ff','#ffd700','#1f77b4', 12 | '#ff7f0e','#2ca02c','#e377c2'], 13 | y_on_right = False, 14 | facecolor = '#0b0b0b', 15 | gridcolor = '#999999', 16 | gridstyle = '--', 17 | rc = [('patch.linewidth' , 1.0 ), 18 | ('lines.linewidth' , 1.0 ) 19 | ], 20 | base_mpf_style='nightclouds', 21 | ) 22 | -------------------------------------------------------------------------------- /GitHub/mplfinance/examples/data/SP500_NOV2019_Hist.csv: -------------------------------------------------------------------------------- 1 | Date,Open,High,Low,Close,Volume 2 | 11/1/2019,3050.72,3066.95,3050.72,3066.91,510301237 3 | 11/4/2019,3078.96,3085.2,3074.87,3078.27,524848878 4 | 11/5/2019,3080.8,3083.95,3072.15,3074.62,585634570 5 | 11/6/2019,3075.1,3078.34,3065.89,3076.78,544288522 6 | 11/7/2019,3087.02,3097.77,3080.23,3085.18,566117910 7 | 11/8/2019,3081.25,3093.09,3073.58,3093.08,460757054 8 | 11/11/2019,3080.33,3088.33,3075.82,3087.01,366044400 9 | 11/12/2019,3089.28,3102.61,3084.73,3091.84,434953689 10 | 11/13/2019,3084.18,3098.06,3078.8,3094.04,454607412 11 | 11/14/2019,3090.75,3098.2,3083.26,3096.63,408390424 12 | 11/15/2019,3107.92,3120.46,3104.6,3120.46,579104868 13 | 11/18/2019,3117.91,3124.17,3112.06,3122.03,521730492 14 | 11/19/2019,3127.45,3127.64,3113.47,3120.18,513153035 15 | 11/20/2019,3114.66,3118.97,3091.41,3108.46,756408988 16 | 11/21/2019,3108.49,3110.11,3094.55,3103.54,476836171 17 | 11/22/2019,3111.41,3112.87,3099.26,3110.29,418027927 18 | 11/25/2019,3117.44,3133.83,3117.44,3133.64,513728761 19 | 11/26/2019,3134.85,3142.69,3131,3140.52,986041660 20 | 11/27/2019,3145.49,3154.26,3143.41,3153.63,421853938 21 | 11/29/2019,3147.18,3150.3,3139.34,3140.98,286602291 22 | -------------------------------------------------------------------------------- /GitHub/mplfinance/src/mplfinance/_styledata/blueskies.py: -------------------------------------------------------------------------------- 1 | style = dict(style_name = 'blueskies', 2 | base_mpl_style='fast', 3 | marketcolors = {'candle' : {'up':'w', 'down':'#0095ff'}, 4 | 'edge' : {'up':'k', 'down':'#0095ff'}, 5 | 'wick' : {'up':'k', 'down':'#0095ff'}, 6 | 'ohlc' : {'up':'w', 'down':'w'}, 7 | 'volume' : {'up':'w', 'down':'#0095ff'}, 8 | 'vcdopcod': False, 9 | 'alpha' : 1.0, 10 | }, 11 | mavcolors = None, 12 | y_on_right = False, 13 | facecolor = '#dbf1ff', 14 | gridcolor = None, 15 | gridstyle = None, 16 | rc = [('patch.linewidth' , 1.0 ), 17 | ('patch.force_edgecolor', True ), 18 | ('lines.linewidth' , 1.0 ), 19 | #('axes.facecolor' , 'w' ), 20 | #('figure.facecolor' , 'w' ) 21 | ], 22 | base_mpf_style='blueskies', 23 | ) 24 | -------------------------------------------------------------------------------- /GitHub/mplfinance/src/mplfinance/_styledata/checkers.py: -------------------------------------------------------------------------------- 1 | style = {'base_mpl_style': 'ggplot', 2 | 'marketcolors' : {'candle': {'up': '#000000', 'down': '#ff0000'}, 3 | 'edge' : {'up': '#000000', 'down': '#ff0000'}, 4 | 'wick' : {'up': '#606060', 'down': '#606060'}, 5 | 'ohlc' : {'up': '#000000', 'down': '#ff0000'}, 6 | 'volume': {'up': '#6f6f6f', 'down': '#ff4040'}, 7 | 'vcedge': {'up': '#1f77b4', 'down': '#1f77b4'}, 8 | 'vcdopcod' : False, 9 | 'alpha' : 0.9}, 10 | 'mavcolors' : None, 11 | 'facecolor' : 'w', 12 | 'gridcolor' : '#c0c0c0', 13 | 'gridstyle' : '-', 14 | 'y_on_right' : True, 15 | 'rc' : {'axes.grid.axis': 'both', 16 | 'axes.grid' : True, 17 | 'axes.edgecolor': '#c0c0c0', 18 | 'axes.labelcolor': 'k', 19 | 'ytick.color' : 'k', 20 | 'xtick.color' : 'k', 21 | 'lines.markeredgecolor': 'k', 22 | 'patch.force_edgecolor': True}, 23 | 'base_mpf_style': 'checkers'} 24 | -------------------------------------------------------------------------------- /split.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | PWDDIR=`pwd` 3 | 4 | 5 | jpx400_nikkei225_500_split() { 6 | # jpx400_nikkei225_500.txt分割する 7 | TXT=jpx400_nikkei225_500.txt 8 | 9 | OUT_DIR=jpx400_nikkei225_500_split 10 | mkdir -p ${OUT_DIR} 11 | 12 | sed -n 1,100p ${TXT} > ${OUT_DIR}/1-100.txt 13 | sed -n 101,200p ${TXT} > ${OUT_DIR}/101-200.txt 14 | sed -n 201,300p ${TXT} > ${OUT_DIR}/201-300.txt 15 | sed -n 301,400p ${TXT} > ${OUT_DIR}/301-400.txt 16 | sed -n 401,500p ${TXT} > ${OUT_DIR}/401-500.txt 17 | sed -n 501,561p ${TXT} > ${OUT_DIR}/501-561.txt 18 | } 19 | 20 | nikkei1000_split() { 21 | # nikkei1000.txt分割する 22 | TXT=nikkei1000.txt 23 | 24 | OUT_DIR=nikkei1000_split 25 | mkdir -p ${OUT_DIR} 26 | 27 | sed -n 1,100p ${TXT} > ${OUT_DIR}/1-100.txt 28 | sed -n 101,200p ${TXT} > ${OUT_DIR}/101-200.txt 29 | sed -n 201,300p ${TXT} > ${OUT_DIR}/201-300.txt 30 | sed -n 301,400p ${TXT} > ${OUT_DIR}/301-400.txt 31 | sed -n 401,500p ${TXT} > ${OUT_DIR}/401-500.txt 32 | sed -n 501,600p ${TXT} > ${OUT_DIR}/501-600.txt 33 | sed -n 601,700p ${TXT} > ${OUT_DIR}/601-700.txt 34 | sed -n 701,800p ${TXT} > ${OUT_DIR}/701-800.txt 35 | sed -n 801,900p ${TXT} > ${OUT_DIR}/801-900.txt 36 | sed -n 901,994p ${TXT} > ${OUT_DIR}/901-994.txt 37 | } 38 | 39 | #jpx400_nikkei225_500_split; 40 | nikkei1000_split; -------------------------------------------------------------------------------- /make_dataset.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | PWDDIR=`pwd` 3 | 4 | conda activate tfgpu 5 | 6 | PY_DIR=code 7 | 8 | positive_negative_line() { 9 | # 翌日が陽線、陰線か + 移動平均線つきの画像をtrain/testに分ける 10 | IN_DIR=/d/work/candlestick_model/output/orig_image_all_positive_negative_line 11 | 12 | OUT_DIR=/d/work/candlestick_model/output/ts_dataset_all_positive_negative_line_label 13 | mkdir -p ${OUT_DIR} 14 | 15 | # 全データで不均衡補正あり 16 | python ${PY_DIR}/make_dataset.py -i ${IN_DIR} -o ${OUT_DIR} -ls 0 1 2 3 --is_test_only 17 | } 18 | 19 | positive_negative_line_all() { 20 | # 不均衡補正なし 21 | # 翌日が陽線、陰線か + 移動平均線つきの画像をtrain/testに分ける 22 | IN_DIR=/d/work/candlestick_model/output/orig_image_all_positive_negative_line 23 | OUT_DIR=/d/work/candlestick_model/output/ts_dataset_all_positive_negative_line_label_all 24 | mkdir -p ${OUT_DIR} 25 | python ${PY_DIR}/make_dataset.py -i ${IN_DIR} -o ${OUT_DIR} -ls 0 1 2 3 --is_test_only --is_not_equalize 26 | } 27 | 28 | positive_negative_line_small() { 29 | # 画像枚数減らす 30 | # 翌日が陽線、陰線か + 移動平均線つきの画像をtrain/testに分ける 31 | IN_DIR=/d/work/candlestick_model/output/orig_image_all_positive_negative_line 32 | OUT_DIR=/d/work/candlestick_model/output/ts_dataset_all_positive_negative_line_label_small 33 | mkdir -p ${OUT_DIR} 34 | python ${PY_DIR}/make_dataset.py -i ${IN_DIR} -o ${OUT_DIR} -ls 0 1 2 3 --is_test_only -l_s 5000 35 | } 36 | 37 | #positive_negative_line; 38 | positive_negative_line_all; 39 | #positive_negative_line_small; -------------------------------------------------------------------------------- /GitHub/mplfinance/examples/original_flavor/plot_day_summary_oclh_demo.py: -------------------------------------------------------------------------------- 1 | """ 2 | Show how to use plot_day_summary_oclh function 3 | """ 4 | import matplotlib.pyplot as plt 5 | import pandas as pd 6 | from pandas.plotting import register_matplotlib_converters 7 | register_matplotlib_converters() 8 | from matplotlib.dates import (MONDAY, DateFormatter, MonthLocator, 9 | WeekdayLocator, date2num) 10 | import os.path 11 | 12 | from mplfinance.original_flavor import plot_day_summary_oclh 13 | 14 | date1 = "2003-11-1" 15 | date2 = "2003-12-1" 16 | 17 | # every monday 18 | mondays = WeekdayLocator(MONDAY) 19 | daysFmt = DateFormatter("%d %b %y") 20 | 21 | 22 | infile = os.path.join('data','yahoofinance-INTC-19950101-20040412.csv') 23 | quotes = pd.read_csv(infile, 24 | index_col=0, 25 | parse_dates=True, 26 | infer_datetime_format=True) 27 | 28 | # select desired range of dates 29 | quotes = quotes[(quotes.index >= date1) & (quotes.index <= date2)] 30 | 31 | 32 | fig, ax = plt.subplots() 33 | plot_day_summary_oclh(ax, zip(date2num(quotes.index.to_pydatetime()), 34 | quotes['Open'], quotes['Close'], 35 | quotes['Low'], quotes['High']), 36 | ticksize=3) 37 | ax.xaxis.set_major_locator(mondays) 38 | ax.xaxis.set_major_formatter(daysFmt) 39 | ax.autoscale_view() 40 | ax.xaxis.grid(True, 'major') 41 | ax.grid(True) 42 | 43 | fig.autofmt_xdate() 44 | 45 | plt.show() 46 | -------------------------------------------------------------------------------- /GitHub/mplfinance/examples/original_flavor/date_demo2.py: -------------------------------------------------------------------------------- 1 | """ 2 | Show how to make date plots in matplotlib using date tick locators and 3 | formatters. See major_minor_demo1.py for more information on 4 | controlling major and minor ticks 5 | """ 6 | 7 | import matplotlib.pyplot as plt 8 | import pandas as pd 9 | from pandas.plotting import register_matplotlib_converters 10 | register_matplotlib_converters() 11 | from matplotlib.dates import (MONDAY, DateFormatter, MonthLocator, 12 | WeekdayLocator) 13 | import os.path 14 | 15 | date1 = "2002-1-5" 16 | date2 = "2003-12-1" 17 | 18 | # every monday 19 | mondays = WeekdayLocator(MONDAY) 20 | 21 | # every 3rd month 22 | months = MonthLocator(range(1, 13), bymonthday=1, interval=3) 23 | monthsFmt = DateFormatter("%b '%y") 24 | 25 | 26 | infile = os.path.join('data','yahoofinance-INTC-19950101-20040412.csv') 27 | quotes = pd.read_csv(infile, 28 | index_col=0, 29 | parse_dates=True, 30 | infer_datetime_format=True) 31 | 32 | # select desired range of dates 33 | quotes = quotes[(quotes.index >= date1) & (quotes.index <= date2)] 34 | 35 | dates = quotes.index 36 | opens = quotes['Open'] 37 | 38 | 39 | fig, ax = plt.subplots() 40 | ax.plot_date(dates, opens, '-') 41 | ax.xaxis.set_major_locator(months) 42 | ax.xaxis.set_major_formatter(monthsFmt) 43 | ax.xaxis.set_minor_locator(mondays) 44 | ax.autoscale_view() 45 | # ax.xaxis.grid(False, 'major') 46 | # ax.xaxis.grid(True, 'minor') 47 | ax.grid(True) 48 | 49 | fig.autofmt_xdate() 50 | 51 | plt.show() 52 | -------------------------------------------------------------------------------- /GitHub/mplfinance/src/mplfinance/_styledata/classic.py: -------------------------------------------------------------------------------- 1 | style = dict(style_name = 'classic', 2 | base_mpl_style= 'fast', 3 | marketcolors = {'candle' : {'up':'w', 'down':'k'}, 4 | 'edge' : {'up':'k', 'down':'k'}, 5 | 'wick' : {'up':'k', 'down':'k'}, 6 | 'ohlc' : {'up':'k', 'down':'k'}, 7 | 'volume' : {'up':'#181818', 'down':'#181818'}, 8 | 'vcedge' : {'up':'#181818', 'down':'#181818'}, 9 | 'vcdopcod': False, # Volume Color is Per Price Change On Day 10 | 'alpha' : 0.9, 11 | }, 12 | mavcolors = ['#1a1a1a','#262626','#333333','#404040'], 13 | y_on_right = True, 14 | gridcolor = '#cccccc', 15 | gridstyle = '--', 16 | facecolor = 'w', 17 | rc = [ ('axes.edgecolor' , 'black' ), 18 | ('axes.linewidth' , 1.5 ), 19 | ('axes.labelsize' , 'large' ), 20 | ('axes.labelweight', 'semibold'), 21 | ('lines.linewidth' , 2.0 ), 22 | #('patch.force_edgecolor', True ), 23 | ('font.weight' , 'medium' ), 24 | ('font.size' , 12.0 ), 25 | ], 26 | base_mpf_style= 'classic' 27 | ) 28 | -------------------------------------------------------------------------------- /GitHub/mplfinance/src/mplfinance/_styledata/default.py: -------------------------------------------------------------------------------- 1 | style = dict(style_name = 'default', 2 | base_mpl_style= 'seaborn-darkgrid', 3 | marketcolors = {'candle' : {'up':'w', 'down':'k'}, 4 | 'edge' : {'up':'k', 'down':'k'}, 5 | 'wick' : {'up':'k', 'down':'k'}, 6 | 'ohlc' : {'up':'k', 'down':'k'}, 7 | 'volume' : {'up':'#1f77b4', 'down':'#1f77b4'}, 8 | 'vcedge' : {'up':'#1f77b4', 'down':'#1f77b4'}, 9 | 'vcdopcod': False, # Volume Color is Per Price Change On Day 10 | 'alpha' : 0.9, 11 | }, 12 | mavcolors = ['#40e0d0','#ff00ff','#ffd700','#1f77b4', 13 | '#ff7f0e','#2ca02c','#e377c2'], 14 | y_on_right = False, 15 | gridcolor = None, 16 | gridstyle = None, 17 | facecolor = '#DCE3EF', 18 | rc = [ ('axes.edgecolor' , 'black' ), 19 | ('axes.linewidth' , 1.5 ), 20 | ('axes.labelsize' , 'large' ), 21 | ('axes.labelweight', 'semibold'), 22 | ('lines.linewidth' , 2.0 ), 23 | ('font.weight' , 'medium' ), 24 | ('font.size' , 12.0 ), 25 | ], 26 | base_mpf_style= 'default' 27 | ) 28 | -------------------------------------------------------------------------------- /GitHub/mplfinance/src/mplfinance/_styledata/__init__.py: -------------------------------------------------------------------------------- 1 | ''' 2 | __init__ for mplfinance._styledata module 3 | ''' 4 | 5 | from mplfinance._styledata import default 6 | from mplfinance._styledata import nightclouds 7 | from mplfinance._styledata import classic 8 | from mplfinance._styledata import mike 9 | from mplfinance._styledata import charles 10 | from mplfinance._styledata import blueskies 11 | from mplfinance._styledata import starsandstripes 12 | from mplfinance._styledata import sas 13 | from mplfinance._styledata import brasil 14 | from mplfinance._styledata import yahoo 15 | from mplfinance._styledata import checkers 16 | from mplfinance._styledata import binance 17 | 18 | _style_names = [n for n in dir() if not n.startswith('_')] 19 | 20 | _styles = {} 21 | for name in _style_names: 22 | cmd = f'_styles.update({name} = {name}.style)' 23 | eval(cmd) 24 | 25 | def _validate_style(style): 26 | keys = ['base_mpl_style','marketcolors','mavcolors','y_on_right', 27 | 'gridcolor','gridstyle','facecolor','rc' ] 28 | for key in keys: 29 | if key not in style.keys(): 30 | err = f'Key "{key}" not found in style:\n\n {style}' 31 | raise ValueError(err) 32 | 33 | mktckeys = ['candle','edge','wick','ohlc','volume','alpha'] 34 | for key in mktckeys: 35 | if key not in style['marketcolors'].keys(): 36 | err = f'Key "{key}" not found in marketcolors for style:\n\n {style}' 37 | raise ValueError(err) 38 | 39 | #print('type(_styles)=',type(_styles)) 40 | #print('_styles=',_styles) 41 | for s in _styles.keys(): 42 | _validate_style(_styles[s]) 43 | 44 | -------------------------------------------------------------------------------- /GitHub/mplfinance/src/mplfinance/_styledata/binance.py: -------------------------------------------------------------------------------- 1 | style = dict(style_name = 'binance', 2 | base_mpl_style= 'seaborn-darkgrid', 3 | marketcolors = {'candle' : {'up':'#70a800', 'down':'#ea0070'}, 4 | 'edge' : {'up':'#70a800', 'down':'#ea0070'}, 5 | 'wick' : {'up':'#70a800', 'down':'#ea0070'}, 6 | 'ohlc' : {'up':'#70a800', 'down':'#ea0070'}, 7 | 'volume' : {'up':'#70a800', 'down':'#ea0070'}, 8 | 'vcedge' : {'up':'#70a800', 'down':'#ea0070'}, 9 | 'vcdopcod': False, 10 | 'alpha' : 0.9, 11 | }, 12 | mavcolors = ['#ffc201','#ff10ff','#cd0468','#1f77b4', 13 | '#ff7f0e','#2ca02c','#40e0d0'], 14 | y_on_right = False, 15 | gridcolor = '#d0d0d0', 16 | gridstyle = '--', 17 | facecolor = '#ffffff', 18 | rc = [ ('axes.edgecolor' , '#e6e6e6' ), 19 | ('axes.linewidth' , 1.5 ), 20 | ('axes.labelsize' , 'medium' ), 21 | ('axes.labelweight', 'semibold'), 22 | ('lines.linewidth' , 2.0 ), 23 | ('font.weight' , 'medium' ), 24 | ('font.size' , 12.0 ), 25 | ], 26 | base_mpf_style= 'binance' 27 | ) 28 | -------------------------------------------------------------------------------- /make_candlestick.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | PWDDIR=`pwd` 3 | 4 | PY_DIR=code 5 | 6 | conda activate tfgpu 7 | 8 | positive_negative_line_label() { 9 | IN_DIR=nikkei1000_split 10 | 11 | OUT_DIR=/d/work/candlestick_model/output/orig_image_all_positive_negative_line 12 | mkdir -p $OUT_DIR 13 | 14 | # 並列実行するためバックグラウンドプロセスで実行 15 | # 翌日が陽線、陰線か + 移動平均線つき 16 | python ${PY_DIR}/make_candlestick.py -o $OUT_DIR -i $IN_DIR/1-100.txt --is_mav_png --is_positive_negative_line_label & 17 | python ${PY_DIR}/make_candlestick.py -o $OUT_DIR -i $IN_DIR/101-200.txt --is_mav_png --is_positive_negative_line_label & 18 | python ${PY_DIR}/make_candlestick.py -o $OUT_DIR -i $IN_DIR/201-300.txt --is_mav_png --is_positive_negative_line_label & 19 | python ${PY_DIR}/make_candlestick.py -o $OUT_DIR -i $IN_DIR/301-400.txt --is_mav_png --is_positive_negative_line_label & 20 | python ${PY_DIR}/make_candlestick.py -o $OUT_DIR -i $IN_DIR/401-500.txt --is_mav_png --is_positive_negative_line_label & 21 | python ${PY_DIR}/make_candlestick.py -o $OUT_DIR -i $IN_DIR/501-600.txt --is_mav_png --is_positive_negative_line_label & 22 | python ${PY_DIR}/make_candlestick.py -o $OUT_DIR -i $IN_DIR/601-700.txt --is_mav_png --is_positive_negative_line_label & 23 | python ${PY_DIR}/make_candlestick.py -o $OUT_DIR -i $IN_DIR/701-800.txt --is_mav_png --is_positive_negative_line_label & 24 | python ${PY_DIR}/make_candlestick.py -o $OUT_DIR -i $IN_DIR/801-900.txt --is_mav_png --is_positive_negative_line_label & 25 | python ${PY_DIR}/make_candlestick.py -o $OUT_DIR -i $IN_DIR/901-994.txt --is_mav_png --is_positive_negative_line_label & 26 | } 27 | 28 | positive_negative_line_label; -------------------------------------------------------------------------------- /GitHub/mplfinance/src/mplfinance/_styledata/charles.py: -------------------------------------------------------------------------------- 1 | style = dict(style_name = 'charles', 2 | base_mpl_style= 'fast', 3 | marketcolors = {'candle' : {'up':'#006340', 'down':'#a02128'}, 4 | 'edge' : {'up':'#006340', 'down':'#a02128'}, 5 | 'wick' : {'up':'#006340', 'down':'#a02128'}, 6 | 'ohlc' : {'up':'#006340', 'down':'#a02128'}, 7 | 'volume' : {'up':'#007a00', 'down':'#d50d18'}, 8 | 'vcdopcod': True, # Volume Color Depends On Price Change On Day 9 | 'alpha' : 1.0, 10 | }, 11 | mavcolors = ['#ef5714','#ef5714','#9f4878','#9f4878'], 12 | y_on_right = True, 13 | gridcolor = '#a0a0a0', 14 | gridstyle = '--', 15 | facecolor = 'w', 16 | rc = [ ('axes.edgecolor' , 'white' ), 17 | ('axes.linewidth' , 1.5 ), 18 | ('axes.labelsize' , 'large' ), 19 | ('axes.labelweight', 'semibold'), 20 | ('axes.grid' , True ), 21 | ('axes.grid.axis' , 'y' ), 22 | ('grid.linewidth' , 0.4 ), 23 | ('lines.linewidth' , 2.0 ), 24 | ('font.weight' , 'medium' ), 25 | ('font.size' , 10.0 ), 26 | ], 27 | base_mpf_style= 'charles' 28 | ) 29 | -------------------------------------------------------------------------------- /notebook/png_cp.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "!pwd\n", 10 | "import sys\n", 11 | "%reload_ext autoreload\n", 12 | "%autoreload 2\n", 13 | "%matplotlib inline\n", 14 | "sys.executable" 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": 2, 20 | "metadata": { 21 | "ExecuteTime": { 22 | "end_time": "2020-08-04T12:50:14.985377Z", 23 | "start_time": "2020-08-04T12:49:40.632317Z" 24 | } 25 | }, 26 | "outputs": [], 27 | "source": [ 28 | "import glob, shutil\n", 29 | "\n", 30 | "before_dir = r\"D:\\work\\candlestick_model\\output\\ts_dataset_all_2day_label_binary\\train\\2\"\n", 31 | "after_dir = r\"D:\\work\\candlestick_model\\output\\ts_dataset_all_2day_label_binary\\train\\1\"\n", 32 | "\n", 33 | "# 指定ディレクトリの下位ファイルを全件移動\n", 34 | "after_paths = [shutil.move(p, after_dir) for p in glob.glob(before_dir+'/*')]" 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": null, 40 | "metadata": {}, 41 | "outputs": [], 42 | "source": [] 43 | } 44 | ], 45 | "metadata": { 46 | "kernelspec": { 47 | "display_name": "Python 3", 48 | "language": "python", 49 | "name": "python3" 50 | }, 51 | "language_info": { 52 | "codemirror_mode": { 53 | "name": "ipython", 54 | "version": 3 55 | }, 56 | "file_extension": ".py", 57 | "mimetype": "text/x-python", 58 | "name": "python", 59 | "nbconvert_exporter": "python", 60 | "pygments_lexer": "ipython3", 61 | "version": "3.7.5" 62 | } 63 | }, 64 | "nbformat": 4, 65 | "nbformat_minor": 2 66 | } 67 | -------------------------------------------------------------------------------- /GitHub/mplfinance/tests/original_flavor/test_plot_day_summary_oclh_demo.py: -------------------------------------------------------------------------------- 1 | """ 2 | Show how to use plot_day_summary_oclh function 3 | """ 4 | import matplotlib.pyplot as plt 5 | import pandas as pd 6 | from pandas.plotting import register_matplotlib_converters 7 | register_matplotlib_converters() 8 | from matplotlib.dates import (MONDAY, DateFormatter, MonthLocator, 9 | WeekdayLocator, date2num) 10 | import os.path 11 | import io 12 | 13 | from mplfinance.original_flavor import plot_day_summary_oclh 14 | 15 | def test_plot_day_summary_oclh_demo(): 16 | 17 | date1 = "2003-11-1" 18 | date2 = "2003-12-1" 19 | 20 | # every monday 21 | mondays = WeekdayLocator(MONDAY) 22 | daysFmt = DateFormatter("%d %b %y") 23 | 24 | 25 | infile = os.path.join('examples','data','yahoofinance-INTC-19950101-20040412.csv') 26 | quotes = pd.read_csv(infile, 27 | index_col=0, 28 | parse_dates=True, 29 | infer_datetime_format=True) 30 | 31 | # select desired range of dates 32 | quotes = quotes[(quotes.index >= date1) & (quotes.index <= date2)] 33 | 34 | 35 | fig, ax = plt.subplots() 36 | plot_day_summary_oclh(ax, zip(date2num(quotes.index.to_pydatetime()), 37 | quotes['Open'], quotes['Close'], 38 | quotes['Low'], quotes['High']), 39 | ticksize=3) 40 | ax.xaxis.set_major_locator(mondays) 41 | ax.xaxis.set_major_formatter(daysFmt) 42 | ax.autoscale_view() 43 | ax.xaxis.grid(True, 'major') 44 | ax.grid(True) 45 | 46 | fig.autofmt_xdate() 47 | 48 | buf = io.BytesIO() 49 | plt.savefig(buf) 50 | -------------------------------------------------------------------------------- /GitHub/mplfinance/examples/original_flavor/finance_demo.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | 3 | import matplotlib.dates as mdates 4 | import matplotlib.pyplot as plt 5 | import pandas as pd 6 | from pandas.plotting import register_matplotlib_converters 7 | register_matplotlib_converters() 8 | from matplotlib.dates import MONDAY, DateFormatter, DayLocator, WeekdayLocator 9 | import os.path 10 | 11 | from mplfinance.original_flavor import candlestick_ohlc 12 | 13 | date1 = "2004-2-1" 14 | date2 = "2004-4-12" 15 | 16 | 17 | mondays = WeekdayLocator(MONDAY) # major ticks on the mondays 18 | alldays = DayLocator() # minor ticks on the days 19 | weekFormatter = DateFormatter('%b %d') # e.g., Jan 12 20 | dayFormatter = DateFormatter('%d') # e.g., 12 21 | 22 | infile = os.path.join('data','yahoofinance-INTC-19950101-20040412.csv') 23 | quotes = pd.read_csv(infile, 24 | index_col=0, 25 | parse_dates=True, 26 | infer_datetime_format=True) 27 | 28 | # select desired range of dates 29 | quotes = quotes[(quotes.index >= date1) & (quotes.index <= date2)] 30 | 31 | fig, ax = plt.subplots() 32 | fig.subplots_adjust(bottom=0.2) 33 | ax.xaxis.set_major_locator(mondays) 34 | ax.xaxis.set_minor_locator(alldays) 35 | ax.xaxis.set_major_formatter(weekFormatter) 36 | # ax.xaxis.set_minor_formatter(dayFormatter) 37 | 38 | # plot_day_summary(ax, quotes, ticksize=3) 39 | candlestick_ohlc(ax, zip(mdates.date2num(quotes.index.to_pydatetime()), 40 | quotes['Open'], quotes['High'], 41 | quotes['Low'], quotes['Close']), 42 | width=0.6) 43 | 44 | ax.xaxis_date() 45 | ax.autoscale_view() 46 | plt.setp(plt.gca().get_xticklabels(), rotation=45, horizontalalignment='right') 47 | 48 | plt.show() 49 | -------------------------------------------------------------------------------- /GitHub/mplfinance/examples/original_flavor/date_demo1.py: -------------------------------------------------------------------------------- 1 | """ 2 | Show how to make date plots in matplotlib using date tick locators and 3 | formatters. See major_minor_demo1.py for more information on 4 | controlling major and minor ticks 5 | 6 | All matplotlib date plotting is done by converting date instances into 7 | days since the 0001-01-01 UTC. The conversion, tick locating and 8 | formatting is done behind the scenes so this is most transparent to 9 | you. The dates module provides several converter functions date2num 10 | and num2date 11 | 12 | This example requires an active internet connection since it uses 13 | yahoo finance to get the data for plotting 14 | """ 15 | 16 | import matplotlib.pyplot as plt 17 | import pandas as pd 18 | from pandas.plotting import register_matplotlib_converters 19 | register_matplotlib_converters() 20 | from matplotlib.dates import DateFormatter, MonthLocator, YearLocator 21 | import os.path 22 | 23 | years = YearLocator() # every year 24 | months = MonthLocator() # every month 25 | yearsFmt = DateFormatter('%Y') 26 | 27 | # make file paths OS independent 28 | infile = os.path.join('data','yahoofinance-INTC-19950101-20040412.csv') 29 | quotes = pd.read_csv(infile,index_col=0,parse_dates=True,infer_datetime_format=True) 30 | 31 | dates = quotes.index 32 | opens = quotes['Open'] 33 | 34 | fig, ax = plt.subplots() 35 | ax.plot_date(dates, opens, '-') 36 | 37 | # format the ticks 38 | ax.xaxis.set_major_locator(years) 39 | ax.xaxis.set_major_formatter(yearsFmt) 40 | ax.xaxis.set_minor_locator(months) 41 | ax.autoscale_view() 42 | 43 | 44 | # format the coords message box 45 | def price(x): 46 | return '$%1.2f' % x 47 | 48 | 49 | ax.fmt_xdata = DateFormatter('%Y-%m-%d') 50 | ax.fmt_ydata = price 51 | ax.grid(True) 52 | 53 | fig.autofmt_xdate() 54 | plt.show() 55 | -------------------------------------------------------------------------------- /GitHub/mplfinance/tests/original_flavor/test_date_demo2.py: -------------------------------------------------------------------------------- 1 | """ 2 | Show how to make date plots in matplotlib using date tick locators and 3 | formatters. See major_minor_demo1.py for more information on 4 | controlling major and minor ticks 5 | """ 6 | 7 | import matplotlib.pyplot as plt 8 | import pandas as pd 9 | from pandas.plotting import register_matplotlib_converters 10 | register_matplotlib_converters() 11 | from matplotlib.dates import (MONDAY, DateFormatter, MonthLocator, 12 | WeekdayLocator) 13 | import os.path 14 | import io 15 | 16 | def test_date_demo2(): 17 | 18 | date1 = "2002-1-5" 19 | date2 = "2003-12-1" 20 | 21 | # every monday 22 | mondays = WeekdayLocator(MONDAY) 23 | 24 | # every 3rd month 25 | months = MonthLocator(range(1, 13), bymonthday=1, interval=3) 26 | monthsFmt = DateFormatter("%b '%y") 27 | 28 | 29 | infile = os.path.join('examples','data','yahoofinance-INTC-19950101-20040412.csv') 30 | quotes = pd.read_csv(infile, 31 | index_col=0, 32 | parse_dates=True, 33 | infer_datetime_format=True) 34 | 35 | # select desired range of dates 36 | quotes = quotes[(quotes.index >= date1) & (quotes.index <= date2)] 37 | 38 | dates = quotes.index.values 39 | opens = quotes['Open'] 40 | 41 | 42 | fig, ax = plt.subplots() 43 | ax.plot_date(dates, opens, '-') 44 | ax.xaxis.set_major_locator(months) 45 | ax.xaxis.set_major_formatter(monthsFmt) 46 | ax.xaxis.set_minor_locator(mondays) 47 | ax.autoscale_view() 48 | # ax.xaxis.grid(False, 'major') 49 | # ax.xaxis.grid(True, 'minor') 50 | ax.grid(True) 51 | 52 | fig.autofmt_xdate() 53 | 54 | buf = io.BytesIO() 55 | plt.savefig(buf) 56 | -------------------------------------------------------------------------------- /GitHub/mplfinance/examples/original_flavor/longshort.py: -------------------------------------------------------------------------------- 1 | """ 2 | Illustrate the rec array utility funcitons by loading prices from a 3 | csv file, computing the daily returns, appending the results to the 4 | record arrays, joining on date 5 | """ 6 | import matplotlib.mlab as mlab 7 | import matplotlib.pyplot as plt 8 | import numpy as np 9 | import pandas as pd 10 | from pandas.plotting import register_matplotlib_converters 11 | register_matplotlib_converters() 12 | 13 | import os.path 14 | from six.moves import urllib 15 | 16 | start_date = "2004-8-19" 17 | end_date = '2018-1-20' 18 | 19 | # grab the price data off yahoo csv quotes 20 | 21 | infile1 = os.path.join('data','yahoofinance-AAPL-20040819-20180120.csv') 22 | r1 = pd.read_csv(infile1, 23 | index_col=0, 24 | parse_dates=True, 25 | infer_datetime_format=True) 26 | 27 | infile2 = os.path.join('data','yahoofinance-GOOG-20040819-20180120.csv') 28 | r2 = pd.read_csv(infile2, 29 | index_col=0, 30 | parse_dates=True, 31 | infer_datetime_format=True) 32 | 33 | 34 | # compute the daily returns and add these columns to the arrays 35 | gains1 = np.zeros_like(r1["Adj Close"]) 36 | gains2 = np.zeros_like(r2["Adj Close"]) 37 | gains1[1:] = np.diff(r1["Adj Close"]) / r1["Adj Close"][:-1] 38 | gains2[1:] = np.diff(r2["Adj Close"]) / r2["Adj Close"][:-1] 39 | r1['gains'] = gains1 40 | r2['gains'] = gains2 41 | 42 | 43 | # now join them by date 44 | r = pd.merge(r1, r2, left_index=True, right_index=True, 45 | suffixes=(['1', '2']), sort=True) 46 | 47 | 48 | # long appl, short goog 49 | g = r.gains1 - r.gains2 50 | tr = (1 + g).cumprod() # the total return 51 | 52 | # plot the return 53 | fig, ax = plt.subplots() 54 | ax.plot(r.index, tr) 55 | ax.set_title('total return: long APPL, short GOOG') 56 | ax.grid() 57 | fig.autofmt_xdate() 58 | plt.show() 59 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 20日間のローソク足画像からCNNで株価の上下を予想するモデル 2 | 3 | ![img_sample.png](https://github.com/riron1206/candlestick_model/blob/master/img_sample.png) 4 | 5 | - 参考論文: https://arxiv.org/pdf/1903.12258.pdf 6 | - 論文では上がり下がりを予測するバイナリラベルでvalidationの正解率>0.9 7 | - VGG16より小さいモデルで結果出してた(学習率などのハイパラは書いてない不親切な論文だった。validationとtestを同じデータでやってるし) 8 | - 株価データベースと株価csvが必要 9 | - https://github.com/riron1206/03.stock_repo/tree/master/sqlite_analysis 10 | - 02_keras_pyライブラリも必要 11 | - https://github.com/riron1206/02_keras_py 12 | 13 | ## ラベルの分け方かえていくつかモデル作ったが、以下のラベルを採用した 14 | - 予測実行日の1日後の始値 > 2日後の始値なら「0」 15 | - 予測実行日の1日後の始値 < 2日後の始値なら「1」 16 | - 予測実行日の1日後の始値 * 1.05 < 2日後の始値なら「2」 17 | - ※上がり下がりを予測するバイナリラベルだとvalidationの正解率>0.9になるが、最近のデータで試すとあまり当たらない感じだったのでこうした(validation setの切り方が悪いためtest setの分布と合ってないのか?) 18 | - 予測実行日の終値 < 1日後の始値 and 予測ラベル=1or2 and 確信度>0.8 のデータは良さそう 19 | 20 | ![CM_without_normalize_optuna_best_trial_accuracy.png](https://github.com/riron1206/candlestick_model/blob/master/CM_without_normalize_Xception_2day_label.png) 21 | 22 | ## 行った手順 23 | #### 1. notebook/*.ipynb でデータ作成、モデル作成試す 24 | #### 2. 時系列の分け方でデータセット作成 25 | - train setは2000-2017年まで、test setは2018-2020年までのデータを使う 26 | ```bash 27 | # 画像作成 28 | $ python make_candlestick.py --is_mav_png --is_2day_label -o D:\work\candlestick_model\output\orig_image_all_2day_label 29 | ※画像200万枚ぐらいつくるため48時間近くかかる 30 | 31 | # train/test setに分割 32 | $ python make_dataset.py -i D:\work\candlestick_model\output\orig_image_all_2day_label -o D:\work\candlestick_model\output\ts_dataset_all_2day_label --is_test_only --is_not_equalize 33 | ``` 34 | #### 3. code/tf_base_class*.py でモデル作成(パラメータチューニングも可能。少量データ版では試した) 35 | ```bash 36 | $ python tf_base_class_all_data_2day_label.py -m train 37 | ``` 38 | #### 4. bestモデルで予測 39 | ```bash 40 | # JPX日経インデックス400 + 日経225 + 日経500種について 41 | $ python tf_predict_best_model.py --is_2day_label 42 | 43 | # 7269:スズキについて数日さかのぼって実行。下記は10日さかのぼる(2020/07/31からさかのぼって10日間毎日予測) 44 | $ python tf_predict_best_model.py -c 7269 -d 2020-07-31 -t_d 10 --is_2day_label 45 | ``` 46 | -------------------------------------------------------------------------------- /GitHub/mplfinance/tests/original_flavor/test_date_demo1.py: -------------------------------------------------------------------------------- 1 | """ 2 | Show how to make date plots in matplotlib using date tick locators and 3 | formatters. See major_minor_demo1.py for more information on 4 | controlling major and minor ticks 5 | 6 | All matplotlib date plotting is done by converting date instances into 7 | days since the 0001-01-01 UTC. The conversion, tick locating and 8 | formatting is done behind the scenes so this is most transparent to 9 | you. The dates module provides several converter functions date2num 10 | and num2date 11 | 12 | This example requires an active internet connection since it uses 13 | yahoo finance to get the data for plotting 14 | """ 15 | 16 | import matplotlib.pyplot as plt 17 | import pandas as pd 18 | from pandas.plotting import register_matplotlib_converters 19 | register_matplotlib_converters() 20 | from matplotlib.dates import DateFormatter, MonthLocator, YearLocator 21 | import os.path 22 | import io 23 | 24 | def test_date_demo1(): 25 | 26 | years = YearLocator() # every year 27 | months = MonthLocator() # every month 28 | yearsFmt = DateFormatter('%Y') 29 | 30 | # make file paths OS independent 31 | infile = os.path.join('examples','data','yahoofinance-INTC-19950101-20040412.csv') 32 | quotes = pd.read_csv(infile,index_col=0,parse_dates=True,infer_datetime_format=True) 33 | 34 | dates = quotes.index.values 35 | opens = quotes['Open'] 36 | 37 | fig, ax = plt.subplots() 38 | ax.plot_date(dates, opens, '-') 39 | 40 | # format the ticks 41 | ax.xaxis.set_major_locator(years) 42 | ax.xaxis.set_major_formatter(yearsFmt) 43 | ax.xaxis.set_minor_locator(months) 44 | ax.autoscale_view() 45 | 46 | 47 | # format the coords message box 48 | def price(x): 49 | return '$%1.2f' % x 50 | 51 | 52 | ax.fmt_xdata = DateFormatter('%Y-%m-%d') 53 | ax.fmt_ydata = price 54 | ax.grid(True) 55 | 56 | fig.autofmt_xdate() 57 | buf = io.BytesIO() 58 | plt.savefig(buf) 59 | -------------------------------------------------------------------------------- /GitHub/mplfinance/tests/original_flavor/test_finance_demo.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | 3 | import matplotlib.dates as mdates 4 | import matplotlib.pyplot as plt 5 | import pandas as pd 6 | from pandas.plotting import register_matplotlib_converters 7 | register_matplotlib_converters() 8 | from matplotlib.dates import MONDAY, DateFormatter, DayLocator, WeekdayLocator 9 | import os.path 10 | import io 11 | 12 | from mplfinance.original_flavor import candlestick_ohlc 13 | 14 | def test_finance_demo(): 15 | 16 | date1 = "2004-2-1" 17 | date2 = "2004-4-12" 18 | 19 | 20 | mondays = WeekdayLocator(MONDAY) # major ticks on the mondays 21 | alldays = DayLocator() # minor ticks on the days 22 | weekFormatter = DateFormatter('%b %d') # e.g., Jan 12 23 | dayFormatter = DateFormatter('%d') # e.g., 12 24 | 25 | infile = os.path.join('examples','data','yahoofinance-INTC-19950101-20040412.csv') 26 | quotes = pd.read_csv(infile, 27 | index_col=0, 28 | parse_dates=True, 29 | infer_datetime_format=True) 30 | 31 | # select desired range of dates 32 | quotes = quotes[(quotes.index >= date1) & (quotes.index <= date2)] 33 | 34 | fig, ax = plt.subplots() 35 | fig.subplots_adjust(bottom=0.2) 36 | ax.xaxis.set_major_locator(mondays) 37 | ax.xaxis.set_minor_locator(alldays) 38 | ax.xaxis.set_major_formatter(weekFormatter) 39 | # ax.xaxis.set_minor_formatter(dayFormatter) 40 | 41 | # plot_day_summary(ax, quotes, ticksize=3) 42 | candlestick_ohlc(ax, zip(mdates.date2num(quotes.index.to_pydatetime()), 43 | quotes['Open'], quotes['High'], 44 | quotes['Low'], quotes['Close']), 45 | width=0.6) 46 | 47 | ax.xaxis_date() 48 | ax.autoscale_view() 49 | plt.setp(plt.gca().get_xticklabels(), rotation=45, horizontalalignment='right') 50 | 51 | buf = io.BytesIO() 52 | plt.savefig(buf) 53 | -------------------------------------------------------------------------------- /GitHub/mplfinance/src/mplfinance/_styledata/mike.py: -------------------------------------------------------------------------------- 1 | style = dict(style_name = 'mike', 2 | base_mpl_style= 'dark_background', 3 | marketcolors = {'candle' : {'up':'#000000', 'down':'#0080ff'}, 4 | 'edge' : {'up':'#ffffff', 'down':'#0080ff'}, 5 | 'wick' : {'up':'#ffffff', 'down':'#ffffff'}, 6 | 'ohlc' : {'up':'#ffffff', 'down':'#ffffff'}, 7 | 'volume' : {'up':'#7189aa', 'down':'#7189aa'}, 8 | 'vcdopcod': False, # Volume Color Depends On Price Change On Day 9 | 'alpha' : 1.0, 10 | }, 11 | mavcolors = ['#ec009c','#78ff8f','#fcf120'], 12 | y_on_right = True, 13 | gridcolor = None, 14 | gridstyle = None, 15 | facecolor = None, 16 | rc = [ ('axes.edgecolor' , 'white' ), 17 | ('axes.linewidth' , 1.5 ), 18 | ('axes.labelsize' , 'large' ), 19 | ('axes.labelweight', 'semibold'), 20 | ('axes.grid' , True ), 21 | ('axes.grid.axis' , 'both' ), 22 | ('axes.grid.which' , 'major' ), 23 | ('grid.alpha' , 0.9 ), 24 | ('grid.color' , '#b0b0b0' ), 25 | ('grid.linestyle' , '--' ), 26 | ('grid.linewidth' , 0.8 ), 27 | ('figure.facecolor', '#0a0a0a' ), 28 | ('patch.linewidth' , 1.0 ), 29 | ('lines.linewidth' , 1.0 ), 30 | ('font.weight' , 'medium' ), 31 | ('font.size' , 10.0 ), 32 | ], 33 | base_mpf_style= 'mike' 34 | ) 35 | -------------------------------------------------------------------------------- /GitHub/mplfinance/tests/original_flavor/test_longshort.py: -------------------------------------------------------------------------------- 1 | """ 2 | Illustrate the rec array utility funcitons by loading prices from a 3 | csv file, computing the daily returns, appending the results to the 4 | record arrays, joining on date 5 | """ 6 | import matplotlib.mlab as mlab 7 | import matplotlib.pyplot as plt 8 | import numpy as np 9 | import pandas as pd 10 | from pandas.plotting import register_matplotlib_converters 11 | register_matplotlib_converters() 12 | 13 | import os.path 14 | import io 15 | from six.moves import urllib 16 | 17 | def test_longshort(): 18 | 19 | start_date = "2004-8-19" 20 | end_date = '2018-1-20' 21 | 22 | # grab the price data off yahoo csv quotes 23 | 24 | infile1 = os.path.join('examples','data','yahoofinance-AAPL-20040819-20180120.csv') 25 | r1 = pd.read_csv(infile1, 26 | index_col=0, 27 | parse_dates=True, 28 | infer_datetime_format=True) 29 | 30 | infile2 = os.path.join('examples','data','yahoofinance-GOOG-20040819-20180120.csv') 31 | r2 = pd.read_csv(infile2, 32 | index_col=0, 33 | parse_dates=True, 34 | infer_datetime_format=True) 35 | 36 | 37 | # compute the daily returns and add these columns to the arrays 38 | gains1 = np.zeros_like(r1["Adj Close"]) 39 | gains2 = np.zeros_like(r2["Adj Close"]) 40 | gains1[1:] = np.diff(r1["Adj Close"]) / r1["Adj Close"][:-1] 41 | gains2[1:] = np.diff(r2["Adj Close"]) / r2["Adj Close"][:-1] 42 | r1['gains'] = gains1 43 | r2['gains'] = gains2 44 | 45 | 46 | # now join them by date 47 | r = pd.merge(r1, r2, left_index=True, right_index=True, 48 | suffixes=(['1', '2']), sort=True) 49 | 50 | 51 | # long appl, short goog 52 | g = r.gains1 - r.gains2 53 | tr = (1 + g).cumprod() # the total return 54 | 55 | # plot the return 56 | fig, ax = plt.subplots() 57 | ax.plot(r.index.values, tr) 58 | ax.set_title('total return: long APPL, short GOOG') 59 | ax.grid() 60 | fig.autofmt_xdate() 61 | buf = io.BytesIO() 62 | plt.savefig(buf) 63 | -------------------------------------------------------------------------------- /GitHub/mplfinance/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | from setuptools import find_packages 3 | 4 | pkg_location = 'src' 5 | pkg_name = 'mplfinance' 6 | 7 | vfile = './'+pkg_location+'/'+pkg_name+'/_version.py' 8 | vers = {} 9 | with open(vfile) as f: 10 | exec(f.read(), {}, vers) 11 | 12 | with open('README.md') as f: 13 | long_description = f.read() 14 | 15 | setup(name=pkg_name, 16 | version=vers['__version__'], 17 | author='MPL Developers', 18 | author_email='matplotlib-users@python.org', 19 | maintainer_email='dgoldfarb.github@gmail.com', 20 | py_modules=[pkg_name], 21 | description='Utilities for the visualization, and visual analysis, of financial data', 22 | long_description=long_description, 23 | long_description_content_type='text/markdown; charset=UTF-8', 24 | url='http://github.com/matplotlib/mplfinance', 25 | platforms='Cross platform (Linux, Mac OSX, Windows)', 26 | install_requires=['matplotlib','pandas'], 27 | license="BSD-style", 28 | package_dir={'': pkg_location}, 29 | packages=find_packages(where=pkg_location), 30 | classifiers=['Development Status :: 3 - Alpha', 31 | 'Programming Language :: Python :: 3', 32 | 'Programming Language :: Python :: 3.6', 33 | 'Programming Language :: Python :: 3.7', 34 | 'Programming Language :: Python :: 3.8', 35 | 'Framework :: Matplotlib', 36 | 'Intended Audience :: Developers', 37 | 'Intended Audience :: Education', 38 | 'Intended Audience :: Financial and Insurance Industry', 39 | 'Intended Audience :: Science/Research', 40 | 'License :: OSI Approved :: BSD License', 41 | 'Topic :: Office/Business :: Financial', 42 | 'Topic :: Office/Business :: Financial :: Investment', 43 | 'Topic :: Scientific/Engineering :: Visualization', 44 | 'Topic :: Scientific/Engineering :: Information Analysis', 45 | ], 46 | keywords=['finance','candlestick','ohlc','market','investing','technical analysis'], 47 | ) 48 | -------------------------------------------------------------------------------- /train.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | PWDDIR=`pwd` 3 | 4 | PY_DIR=code 5 | 6 | conda activate tfgpu 7 | 8 | tf_base_class_all_data_2day_label() { 9 | # どこまでfreexeしたXceptionが一番loss下がるか調査 10 | python ${PY_DIR}/tf_base_class_all_data_2day_label.py -p "param_2day_label_trainable45.py" -m train 11 | python ${PY_DIR}/tf_base_class_all_data_2day_label.py -p "param_2day_label_trainable65.py" -m train 12 | python ${PY_DIR}/tf_base_class_all_data_2day_label.py -p "param_2day_label_trainable85.py" -m train 13 | python ${PY_DIR}/tf_base_class_all_data_2day_label.py -p "param_2day_label_trainable105.py" -m train 14 | python ${PY_DIR}/tf_base_class_all_data_2day_label.py -p "param_2day_label_trainable125.py" -m train 15 | } 16 | 17 | tf_base_class_all_data_2day_label_small() { 18 | # どこまでfreexeしたXceptionが一番loss下がるか調査 19 | python ${PY_DIR}/tf_base_class_all_data_2day_label_small.py -p "param_2day_label_small.py" -m train 20 | python ${PY_DIR}/tf_base_class_all_data_2day_label_small.py -p "param_2day_label_small_trainable25.py" -m train 21 | python ${PY_DIR}/tf_base_class_all_data_2day_label_small.py -p "param_2day_label_small_trainable45.py" -m train 22 | python ${PY_DIR}/tf_base_class_all_data_2day_label_small.py -p "param_2day_label_small_trainable65.py" -m train 23 | python ${PY_DIR}/tf_base_class_all_data_2day_label_small.py -p "param_2day_label_small_trainable85.py" -m train 24 | python ${PY_DIR}/tf_base_class_all_data_2day_label_small.py -p "param_2day_label_small_trainable105.py" -m train 25 | python ${PY_DIR}/tf_base_class_all_data_2day_label_small.py -p "param_2day_label_small_trainable125.py" -m train 26 | } 27 | 28 | tf_base_class_all_data_positive_negative_line_label() { 29 | # 翌日が陽線、陰線か + 移動平均線つきについてモデル作成 30 | #python ${PY_DIR}/tf_base_class_all_data_positive_negative_line_label.py -p "param_positive_negative_line_label.py" -m train 31 | # predict 32 | python ${PY_DIR}/tf_base_class_all_data_positive_negative_line_label.py -p "param_positive_negative_line_label.py" -m predict 33 | } 34 | 35 | tf_base_class_all_data_positive_negative_line_label_small() { 36 | # 翌日が陽線、陰線か + 移動平均線つきについて、データ数減らしてパラメータチューニング 37 | python ${PY_DIR}/tf_base_class_all_data_positive_negative_line_label.py -m tuning -n_t 80 38 | } 39 | 40 | #tf_base_class_all_data_2day_label; 41 | #tf_base_class_all_data_2day_label_small; 42 | 43 | tf_base_class_all_data_positive_negative_line_label; 44 | #tf_base_class_all_data_positive_negative_line_label_small; -------------------------------------------------------------------------------- /GitHub/mplfinance/LICENSE: -------------------------------------------------------------------------------- 1 | License agreement for mplfinance 2 | ================================= 3 | 4 | 1. This LICENSE AGREEMENT is between the Matplotlib Development Team 5 | ("MDT"), and the Individual or Organization ("Licensee") accessing and 6 | otherwise using matplotlib software in source or binary form and its 7 | associated documentation. 8 | 9 | 2. Subject to the terms and conditions of this License Agreement, MDT 10 | hereby grants Licensee a nonexclusive, royalty-free, world-wide license 11 | to reproduce, analyze, test, perform and/or display publicly, prepare 12 | derivative works, distribute, and otherwise use matplotlib 13 | alone or in any derivative version, provided, however, that MDT's 14 | License Agreement and MDT's notice of copyright, i.e., "Copyright (c) 15 | 2012- Matplotlib Development Team; All Rights Reserved" are retained in 16 | matplotlib alone or in any derivative version prepared by 17 | Licensee. 18 | 19 | 3. In the event Licensee prepares a derivative work that is based on or 20 | incorporates matplotlib or any part thereof, and wants to 21 | make the derivative work available to others as provided herein, then 22 | Licensee hereby agrees to include in any such work a brief summary of 23 | the changes made to matplotlib . 24 | 25 | 4. MDT is making matplotlib available to Licensee on an "AS 26 | IS" basis. MDT MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR 27 | IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, MDT MAKES NO AND 28 | DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS 29 | FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF MATPLOTLIB 30 | WILL NOT INFRINGE ANY THIRD PARTY RIGHTS. 31 | 32 | 5. MDT SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF MATPLOTLIB 33 | FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR 34 | LOSS AS A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING 35 | MATPLOTLIB , OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF 36 | THE POSSIBILITY THEREOF. 37 | 38 | 6. This License Agreement will automatically terminate upon a material 39 | breach of its terms and conditions. 40 | 41 | 7. Nothing in this License Agreement shall be deemed to create any 42 | relationship of agency, partnership, or joint venture between MDT and 43 | Licensee. This License Agreement does not grant permission to use MDT 44 | trademarks or trade name in a trademark sense to endorse or promote 45 | products or services of Licensee, or any third party. 46 | 47 | 8. By copying, installing or otherwise using matplotlib , 48 | Licensee agrees to be bound by the terms and conditions of this License 49 | Agreement. 50 | -------------------------------------------------------------------------------- /GitHub/mplfinance/tests/test_exceptions.py: -------------------------------------------------------------------------------- 1 | import os as os 2 | import io as io 3 | import pandas as pd 4 | import mplfinance as mpf 5 | import matplotlib.pyplot as plt 6 | from matplotlib.testing.compare import compare_images 7 | 8 | print('pd.__version__ =',pd.__version__ ) # for the record 9 | print('mpf.__version__ =',mpf.__version__) # for the record 10 | print("plt.rcParams['backend'] =",plt.rcParams['backend']) # for the record 11 | 12 | import pytest 13 | 14 | def test_dataframe_typeErr(): 15 | s = pd.Series([0,1,2]) 16 | with pytest.raises(TypeError) as ex: 17 | mpf.plot(s) 18 | assert 'Expect data as DataFrame' in str(ex.value) 19 | 20 | df = pd.DataFrame() 21 | with pytest.raises(TypeError) as ex: 22 | mpf.plot(df) 23 | assert 'Expect data.index as DatetimeIndex' in str(ex.value) 24 | 25 | def test_kwarg_not_implemented(bolldata): 26 | df = bolldata 27 | with pytest.raises(NotImplementedError) as ex: 28 | mpf.plot(df,volume=True,study='Bollinger') 29 | assert 'kwarg NOT implemented' in str(ex.value) 30 | 31 | def test_unrecognized_kwarg(bolldata): 32 | df = bolldata 33 | with pytest.raises(KeyError) as ex: 34 | mpf.plot(df,volume=True,foo='bar') 35 | assert 'Unrecognized kwarg' in str(ex.value) 36 | 37 | def test_kwarg_validation_error(bolldata): 38 | ''' 39 | We *could* very exhaustively test all kwargs, but that 40 | would be hundreds of lines of code, etc. So just going 41 | to more-or-less randomly spot check just a few. 42 | ''' 43 | df = bolldata 44 | 45 | apdict = mpf.make_addplot(df['LowerB']) 46 | with pytest.raises(TypeError) as ex: 47 | mpf.plot(df,volume='True',addplot=apdict) 48 | assert 'validator returned False for value' in str(ex.value) 49 | 50 | apdict = {'data':df['LowerB']} 51 | with pytest.raises(KeyError) as ex: 52 | mpf.plot(df,volume=True,addplot=apdict) 53 | 54 | with pytest.raises(TypeError) as ex: 55 | mpf.plot(df,volume=True,style='some random style name') 56 | assert 'validator returned False for value' in str(ex.value) 57 | 58 | with pytest.raises(ValueError) as ex: 59 | mpf.make_marketcolors(base_mpf_style='classic',ohlc='chartreussse') 60 | assert 'NOT is_color_like' in str(ex.value) 61 | 62 | def test_pmove_addplot(bolldata): 63 | df = bolldata 64 | apdict = mpf.make_addplot(df['LowerB']) 65 | with pytest.raises(ValueError) as ex: 66 | mpf.plot(df,type='renko',volume=True,addplot=apdict) 67 | assert '`addplot` is not supported for `type=\'renko\'`' in str(ex.value) 68 | 69 | with pytest.raises(ValueError) as ex: 70 | mpf.plot(df,type='pointnfigure',volume=True,addplot=apdict) 71 | assert '`addplot` is not supported for `type=\'pointnfigure\'`' in str(ex.value) 72 | #mpf.plot(df,type='renko',volume=True) 73 | 74 | def test_figratio_bounds(bolldata): 75 | df = bolldata 76 | buf = io.BytesIO() 77 | mpf.plot(df,volume=True,figratio=(10,5),savefig=buf) 78 | with pytest.raises(ValueError) as ex: 79 | mpf.plot(df,volume=True,figratio=(11,2),savefig=buf) 80 | assert '"figratio" (aspect ratio) must be between' in str(ex.value) 81 | with pytest.raises(ValueError) as ex: 82 | mpf.plot(df,volume=True,figratio=(10,41),savefig=buf) 83 | assert '"figratio" (aspect ratio) must be between' in str(ex.value) 84 | -------------------------------------------------------------------------------- /GitHub/mplfinance/tests/test_pnf.py: -------------------------------------------------------------------------------- 1 | import os 2 | import os.path 3 | import glob 4 | import mplfinance as mpf 5 | import matplotlib.pyplot as plt 6 | from matplotlib.testing.compare import compare_images 7 | 8 | print('mpf.__version__ =',mpf.__version__) # for the record 9 | print("plt.rcParams['backend'] =",plt.rcParams['backend']) # for the record 10 | 11 | base='pnf' 12 | tdir = os.path.join('tests','test_images') 13 | refd = os.path.join('tests','reference_images') 14 | 15 | globpattern = os.path.join(tdir,base+'*.png') 16 | oldtestfiles = glob.glob(globpattern) 17 | 18 | for fn in oldtestfiles: 19 | try: 20 | os.remove(fn) 21 | except: 22 | print('Error removing file "'+fn+'"') 23 | 24 | # IMGCOMP_TOLERANCE = 7.0 # this works fine for linux 25 | IMGCOMP_TOLERANCE = 11.0 # required for a windows pass. (really 10.25 may do it). 26 | 27 | def test_pnf01(bolldata): 28 | 29 | df = bolldata 30 | 31 | fname = base+'01.png' 32 | tname = os.path.join(tdir,fname) 33 | rname = os.path.join(refd,fname) 34 | 35 | fig_axis = mpf.plot(df,type='pnf',volume=True,savefig=tname,returnfig=True) 36 | plt.close(fig_axis[0]) 37 | 38 | tsize = os.path.getsize(tname) 39 | print(glob.glob(tname),'[',tsize,'bytes',']') 40 | 41 | rsize = os.path.getsize(rname) 42 | print(glob.glob(rname),'[',rsize,'bytes',']') 43 | 44 | result = compare_images(rname,tname,tol=IMGCOMP_TOLERANCE) 45 | if result is not None: 46 | print('result=',result) 47 | assert result is None 48 | 49 | 50 | def test_pnf02(bolldata): 51 | 52 | df = bolldata 53 | 54 | fname = base+'02.png' 55 | tname = os.path.join(tdir,fname) 56 | rname = os.path.join(refd,fname) 57 | 58 | fig_axis = mpf.plot(df,type='pnf',pointnfig_params=dict(box_size=4),volume=True,savefig=tname,returnfig=True) 59 | plt.close(fig_axis[0]) 60 | 61 | tsize = os.path.getsize(tname) 62 | print(glob.glob(tname),'[',tsize,'bytes',']') 63 | 64 | rsize = os.path.getsize(rname) 65 | print(glob.glob(rname),'[',rsize,'bytes',']') 66 | 67 | result = compare_images(rname,tname,tol=IMGCOMP_TOLERANCE) 68 | if result is not None: 69 | print('result=',result) 70 | assert result is None 71 | 72 | 73 | def test_pnf03(bolldata): 74 | 75 | df = bolldata 76 | 77 | fname = base+'03.png' 78 | tname = os.path.join(tdir,fname) 79 | rname = os.path.join(refd,fname) 80 | 81 | fig_axis = mpf.plot(df,type='pnf',pointnfig_params=dict(box_size='atr',atr_length=2),volume=True,savefig=tname,returnfig=True) 82 | plt.close(fig_axis[0]) 83 | 84 | tsize = os.path.getsize(tname) 85 | print(glob.glob(tname),'[',tsize,'bytes',']') 86 | 87 | rsize = os.path.getsize(rname) 88 | print(glob.glob(rname),'[',rsize,'bytes',']') 89 | 90 | result = compare_images(rname,tname,tol=IMGCOMP_TOLERANCE) 91 | if result is not None: 92 | print('result=',result) 93 | assert result is None 94 | 95 | def test_pnf04(bolldata): 96 | 97 | df = bolldata 98 | 99 | fname = base+'04.png' 100 | tname = os.path.join(tdir,fname) 101 | rname = os.path.join(refd,fname) 102 | 103 | fig_axis = mpf.plot(df,type='pnf',pointnfig_params=dict(box_size='atr',atr_length='total'),mav=(4,6,8),volume=True,savefig=tname,returnfig=True) 104 | plt.close(fig_axis[0]) 105 | 106 | tsize = os.path.getsize(tname) 107 | print(glob.glob(tname),'[',tsize,'bytes',']') 108 | 109 | rsize = os.path.getsize(rname) 110 | print(glob.glob(rname),'[',rsize,'bytes',']') 111 | 112 | result = compare_images(rname,tname,tol=IMGCOMP_TOLERANCE) 113 | if result is not None: 114 | print('result=',result) 115 | assert result is None -------------------------------------------------------------------------------- /GitHub/mplfinance/tests/test_renko.py: -------------------------------------------------------------------------------- 1 | import os 2 | import os.path 3 | import glob 4 | import mplfinance as mpf 5 | import matplotlib.pyplot as plt 6 | from matplotlib.testing.compare import compare_images 7 | 8 | print('mpf.__version__ =',mpf.__version__) # for the record 9 | print("plt.rcParams['backend'] =",plt.rcParams['backend']) # for the record 10 | 11 | base='renko' 12 | tdir = os.path.join('tests','test_images') 13 | refd = os.path.join('tests','reference_images') 14 | 15 | globpattern = os.path.join(tdir,base+'*.png') 16 | oldtestfiles = glob.glob(globpattern) 17 | 18 | for fn in oldtestfiles: 19 | try: 20 | os.remove(fn) 21 | except: 22 | print('Error removing file "'+fn+'"') 23 | 24 | # IMGCOMP_TOLERANCE = 7.0 # this works fine for linux 25 | IMGCOMP_TOLERANCE = 11.0 # required for a windows pass. (really 10.25 may do it). 26 | 27 | def test_renko01(bolldata): 28 | 29 | df = bolldata 30 | 31 | fname = base+'01.png' 32 | tname = os.path.join(tdir,fname) 33 | rname = os.path.join(refd,fname) 34 | 35 | fig_axis = mpf.plot(df,type='renko',volume=True,savefig=tname,returnfig=True) 36 | plt.close(fig_axis[0]) 37 | 38 | tsize = os.path.getsize(tname) 39 | print(glob.glob(tname),'[',tsize,'bytes',']') 40 | 41 | rsize = os.path.getsize(rname) 42 | print(glob.glob(rname),'[',rsize,'bytes',']') 43 | 44 | result = compare_images(rname,tname,tol=IMGCOMP_TOLERANCE) 45 | if result is not None: 46 | print('result=',result) 47 | assert result is None 48 | 49 | 50 | def test_renko02(bolldata): 51 | 52 | df = bolldata 53 | 54 | fname = base+'02.png' 55 | tname = os.path.join(tdir,fname) 56 | rname = os.path.join(refd,fname) 57 | 58 | fig_axis = mpf.plot(df,type='renko',renko_params=dict(brick_size=4),volume=True,savefig=tname,returnfig=True) 59 | plt.close(fig_axis[0]) 60 | 61 | tsize = os.path.getsize(tname) 62 | print(glob.glob(tname),'[',tsize,'bytes',']') 63 | 64 | rsize = os.path.getsize(rname) 65 | print(glob.glob(rname),'[',rsize,'bytes',']') 66 | 67 | result = compare_images(rname,tname,tol=IMGCOMP_TOLERANCE) 68 | if result is not None: 69 | print('result=',result) 70 | assert result is None 71 | 72 | 73 | def test_renko03(bolldata): 74 | 75 | df = bolldata 76 | 77 | fname = base+'03.png' 78 | tname = os.path.join(tdir,fname) 79 | rname = os.path.join(refd,fname) 80 | 81 | fig_axis = mpf.plot(df,type='renko',renko_params=dict(brick_size='atr',atr_length=2),volume=True,savefig=tname,returnfig=True) 82 | plt.close(fig_axis[0]) 83 | 84 | tsize = os.path.getsize(tname) 85 | print(glob.glob(tname),'[',tsize,'bytes',']') 86 | 87 | rsize = os.path.getsize(rname) 88 | print(glob.glob(rname),'[',rsize,'bytes',']') 89 | 90 | result = compare_images(rname,tname,tol=IMGCOMP_TOLERANCE) 91 | if result is not None: 92 | print('result=',result) 93 | assert result is None 94 | 95 | def test_renko04(bolldata): 96 | 97 | df = bolldata 98 | 99 | fname = base+'04.png' 100 | tname = os.path.join(tdir,fname) 101 | rname = os.path.join(refd,fname) 102 | 103 | fig_axis = mpf.plot(df,type='renko',renko_params=dict(brick_size='atr',atr_length='total'),mav=(8,20,30),volume=True,savefig=tname,returnfig=True) 104 | plt.close(fig_axis[0]) 105 | 106 | tsize = os.path.getsize(tname) 107 | print(glob.glob(tname),'[',tsize,'bytes',']') 108 | 109 | rsize = os.path.getsize(rname) 110 | print(glob.glob(rname),'[',rsize,'bytes',']') 111 | 112 | result = compare_images(rname,tname,tol=IMGCOMP_TOLERANCE) 113 | if result is not None: 114 | print('result=',result) 115 | assert result is None 116 | 117 | def test_renkovalues(bolldata): 118 | 119 | df = bolldata 120 | 121 | rcv = {} 122 | fig_axis = mpf.plot(df,type='renko',return_calculated_values=rcv,returnfig=True) 123 | plt.close(fig_axis[0]) 124 | 125 | assert rcv['renko_bricks'][-1] == 133.919998 -------------------------------------------------------------------------------- /code/post_my_slack.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | """ 4 | 自分のSlackに結果メッセージを飛ばす 5 | 参考: 6 | https://vaaaaaanquish.hatenablog.com/entry/2017/09/27/154210 7 | https://qiita.com/ik-fib/items/b4a502d173a22b3947a0 8 | 9 | Usage: 10 | $ python post_my_slack.py 11 | """ 12 | import os 13 | import requests 14 | import json 15 | import pandas as pd 16 | import yaml 17 | import warnings 18 | 19 | warnings.filterwarnings("ignore") 20 | 21 | 22 | def post_slack(name, text): 23 | """slackに情報投げる""" 24 | # webhookのエンドポイントのurl 25 | with open( 26 | os.path.join( 27 | r"C:\Users\81908\jupyter_notebook\tf_2_work\stock_work\candlestick_model\code\password", 28 | "slack.yml", 29 | ) 30 | ) as f: 31 | config = yaml.load(f) 32 | post_url = config["post_url"] 33 | requests.post( 34 | post_url, 35 | data=json.dumps({"text": text, "username": name, "icon_emoji": ":python:"}), 36 | ) 37 | 38 | 39 | def post_filter_df_2day_label( 40 | csv=r"D:\work\candlestick_model\output\model\ts_dataset_all_2day_label\Xception\predict\pred.csv", 41 | th_price=5000, 42 | th_pb=0.8, 43 | ): 44 | """2営業日後に上がりそうな株情報絞ってslackに投げる""" 45 | df = pd.read_csv(csv, parse_dates=["date_exe"]) 46 | 47 | # 最新日だけ 48 | df = df[df["date_exe"] == df["date_exe"].max()] 49 | 50 | # 条件に合う行だけにする 51 | df_result = None 52 | for i, df_g in df.groupby(["date_exe"]): 53 | if df_g.shape[0] > 0: 54 | df_g = df_g[ 55 | (df_g["pred_pb"] > th_pb) # スコア高いのだけに 56 | & (df_g["2day_pred_y"] > 0) # ラベル1,2だけに 57 | & (df_g["date_exe_price"] < th_price) # 価格が高すぎるのは除く 58 | ] 59 | df_g = df_g.sort_values(by="pred_pb", ascending=False) # スコアの降順にする 60 | df_g = df_g.head(10) if df_g.shape[0] > 10 else df_g # 10件に絞る 61 | df_result = df_g 62 | # print(df_result) 63 | 64 | # 株コードslackに投げる 65 | date = df_result.iloc[0]["date_exe"].date() 66 | # print(date) 67 | codes = df_result["code"].to_list() 68 | # str_codes = map(str, codes) # 格納される数値を文字列にする 69 | # str_codes = ", ".join(str_codes) # リストを文字列にする 70 | text = f"{str(date)} にシグナル出た銘柄上位 {len(codes)} 件" # {str_codes}" 71 | for code in codes: 72 | text = ( 73 | text 74 | + "\n" 75 | + f"https://stocks.finance.yahoo.co.jp/stocks/chart/?code={str(code)}.T" 76 | ) 77 | print(text) 78 | post_slack("2営業日後に上がりそうな株情報", text) 79 | 80 | 81 | def post_filter_df_positive_negative_line_label( 82 | csv=r"D:\work\candlestick_model\output\model\ts_dataset_all_positive_negative_line_label\predict\pred.csv", 83 | th_price=5000, 84 | th_pb=0.45, 85 | ): 86 | """翌日が陽線になりそうな株情報絞ってslackに投げる""" 87 | df = pd.read_csv(csv, parse_dates=["date_exe"]) 88 | 89 | # 最新日だけ 90 | df = df[df["date_exe"] == df["date_exe"].max()] 91 | 92 | # 条件に合う行だけにする 93 | df_result = None 94 | for i, df_g in df.groupby(["date_exe"]): 95 | if df_g.shape[0] > 0: 96 | df_g = df_g[ 97 | (df_g["pred_pb"] > th_pb) # スコア高いのだけに 98 | & (df_g["next_day_pred_y"] > 1) # ラベル2,3だけに 99 | & (df_g["date_exe_price"] < th_price) # 価格が高すぎるのは除く 100 | ] 101 | df_g = df_g.sort_values(by="pred_pb", ascending=False) # スコアの降順にする 102 | df_g = df_g.head(10) if df_g.shape[0] > 10 else df_g # 10件に絞る 103 | df_result = df_g 104 | # print(df_result) 105 | 106 | # 株コードslackに投げる 107 | date = df_result.iloc[0]["date_exe"].date() 108 | # print(date) 109 | codes = df_result["code"].to_list() 110 | # str_codes = map(str, codes) # 格納される数値を文字列にする 111 | # str_codes = ", ".join(str_codes) # リストを文字列にする 112 | text = f"{str(date)} にシグナル出た銘柄上位 {len(codes)} 件" # {str_codes}" 113 | for code in codes: 114 | text = ( 115 | text 116 | + "\n" 117 | + f"https://stocks.finance.yahoo.co.jp/stocks/chart/?code={str(code)}.T" 118 | ) 119 | print(text) 120 | post_slack("翌日が陽線になりそうな株情報", text) 121 | 122 | 123 | if __name__ == "__main__": 124 | 125 | # ###################### 翌日が陽線か ###################### 126 | post_filter_df_positive_negative_line_label() 127 | ############################################################ 128 | 129 | # ################### 2営業日後に上がりそうか ############## 130 | post_filter_df_2day_label() 131 | ############################################################ 132 | -------------------------------------------------------------------------------- /code/config/param_2day_label.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | # tensorflowのINFOレベルのログを出さないようにする 4 | os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2" 5 | import tensorflow as tf 6 | from tensorflow import keras 7 | 8 | 9 | def get_class_fine_tuning_parameter_base() -> dict: 10 | """ 11 | Get parameter sample for class fine_tuning (like Keras) 12 | Returns: 13 | dict: parameter sample generated by trial object 14 | """ 15 | my_IDG_options = { 16 | "rescale": 1.0 / 255.0, 17 | #'width_shift_range': 0.2, 18 | #'height_shift_range': 0.2, 19 | #'horizontal_flip': True, 20 | #'vertical_flip': True, 21 | #'shear_range': 20, 22 | #'zoom_range': 0.2, 23 | #'rotation_range': 20, 24 | #'channel_shift_range': 50, 25 | #'brightness_range': [0.3, 1.0], 26 | # "random_erasing_prob": 0.5, 27 | # "random_erasing_maxpixel": 255, 28 | #'mix_up_alpha': 0.2, 29 | #'random_crop': [224,224], 30 | #'ricap_beta': 0.3, 31 | #'ricap_use_same_random_value_on_batch': True, 32 | "randaugment_N": 3, 33 | "randaugment_M": 4, 34 | #'is_kuzushiji_gen': True, 35 | "cutmix_alpha": 1.0, 36 | } 37 | 38 | ## Augmentor使う場合のoption 39 | # train_augmentor_options = { 40 | # 'input_width': 80, 41 | # 'input_height': 80, 42 | # 'random_dist_prob': 0.3, 43 | # 'zoom_prob': 0.3, 44 | # 'zoom_min': 0.5 45 | # , 'zoom_max': 1.9 46 | # , 'flip_left_right': 0.3 47 | # , 'flip_top_bottom': 0.3 48 | # , 'random_erasing_prob': 0.3 49 | # , 'random_erasing_area': 0.3 50 | # } 51 | 52 | return { 53 | "output_dir": r"D:\work\candlestick_model\output\model\ts_dataset_all_2day_label", 54 | # "output_dir": r"D:\work\candlestick_model\output\model\ts_dataset_all_2day_label\model_paper", 55 | "gpu_count": 1, 56 | "img_rows": 80, 57 | "img_cols": 80, 58 | "channels": 3, 59 | "batch_size": 256, 60 | "classes": ["0", "1", "2"], 61 | "num_classes": 3, 62 | # "classes": ["0", "1"], 63 | # "num_classes": 2, 64 | "train_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label\train", 65 | "validation_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label\test", 66 | "test_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label\test", 67 | "color_mode": "rgb", 68 | "class_mode": "categorical", # generatorのラベルをone-hotベクトルに変換する場合。generatorのラベルを0か1のどちらかに変えるだけなら'binary' 69 | "activation": "softmax", 70 | # "loss": "categorical_crossentropy", 71 | "loss": keras.losses.CategoricalCrossentropy(label_smoothing=0.1), 72 | "metrics": [ 73 | "accuracy", 74 | keras.metrics.Precision(name="precision"), 75 | keras.metrics.Recall(name="recall"), 76 | keras.metrics.AUC(name="auc"), 77 | ], 78 | "model_path": None, 79 | # 初期モデル指定する!!! 80 | # "model_path": r"D:\work\candlestick_model\output\model\ts_dataset_all_2day_label\best_val_loss_20200727.h5", 81 | "num_epoch": 200, 82 | "n_multitask": 1, # マルチタスクのタスク数 83 | "multitask_pred_n_node": 1, # マルチタスクの各クラス数 84 | # model param 85 | "weights": "imagenet", 86 | "choice_model": "Xception", 87 | # "choice_model": "model_paper", 88 | "fcpool": "GlobalAveragePooling2D", 89 | "is_skip_bn": False, 90 | "trainable": "all", # 249, 91 | # "trainable": 25, 92 | # "trainable": 45, 93 | # "trainable": 65, 94 | # "trainable": 85, 95 | # "trainable": 105, 96 | # "trainable": 125, 97 | "efficientnet_num": 3, 98 | # full layer param 99 | # "fcs": [], 100 | "fcs": [100], 101 | "drop": 0.3, 102 | "is_add_batchnorm": False, # True, 103 | "l2_rate": 1e-4, 104 | # optimizer param 105 | "choice_optim": "sgd", 106 | "lr": 1e-1, 107 | "decay": 1e-5, 108 | "my_IDG_options": my_IDG_options, 109 | #'train_augmentor_options': train_augmentor_options, 110 | "TTA": "", # 'flip', 111 | "TTA_rotate_deg": 0, 112 | "TTA_crop_num": 0, 113 | "TTA_crop_size": [224, 224], 114 | "preprocess": 1.0, 115 | "resize_size": [100, 100], 116 | "is_flow": False, 117 | "is_flow_from_directory": True, 118 | "is_flow_from_dataframe": False, 119 | # "is_lr_finder": False, 120 | "is_lr_finder": True, 121 | "is_class_weight": True, 122 | } 123 | -------------------------------------------------------------------------------- /code/config/param_2day_label_trainable105.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | # tensorflowのINFOレベルのログを出さないようにする 4 | os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2" 5 | import tensorflow as tf 6 | from tensorflow import keras 7 | 8 | 9 | def get_class_fine_tuning_parameter_base() -> dict: 10 | """ 11 | Get parameter sample for class fine_tuning (like Keras) 12 | Returns: 13 | dict: parameter sample generated by trial object 14 | """ 15 | my_IDG_options = { 16 | "rescale": 1.0 / 255.0, 17 | #'width_shift_range': 0.2, 18 | #'height_shift_range': 0.2, 19 | #'horizontal_flip': True, 20 | #'vertical_flip': True, 21 | #'shear_range': 20, 22 | #'zoom_range': 0.2, 23 | #'rotation_range': 20, 24 | #'channel_shift_range': 50, 25 | #'brightness_range': [0.3, 1.0], 26 | # "random_erasing_prob": 0.5, 27 | # "random_erasing_maxpixel": 255, 28 | #'mix_up_alpha': 0.2, 29 | #'random_crop': [224,224], 30 | #'ricap_beta': 0.3, 31 | #'ricap_use_same_random_value_on_batch': True, 32 | "randaugment_N": 3, 33 | "randaugment_M": 4, 34 | #'is_kuzushiji_gen': True, 35 | "cutmix_alpha": 1.0, 36 | } 37 | 38 | ## Augmentor使う場合のoption 39 | # train_augmentor_options = { 40 | # 'input_width': 80, 41 | # 'input_height': 80, 42 | # 'random_dist_prob': 0.3, 43 | # 'zoom_prob': 0.3, 44 | # 'zoom_min': 0.5 45 | # , 'zoom_max': 1.9 46 | # , 'flip_left_right': 0.3 47 | # , 'flip_top_bottom': 0.3 48 | # , 'random_erasing_prob': 0.3 49 | # , 'random_erasing_area': 0.3 50 | # } 51 | 52 | return { 53 | "output_dir": r"D:\work\candlestick_model\output\model\ts_dataset_all_2day_label\Xception\trainable\_105", 54 | # "output_dir": r"D:\work\candlestick_model\output\model\ts_dataset_all_2day_label\model_paper", 55 | "gpu_count": 1, 56 | "img_rows": 80, 57 | "img_cols": 80, 58 | "channels": 3, 59 | "batch_size": 256, 60 | "classes": ["0", "1", "2"], 61 | "num_classes": 3, 62 | # "classes": ["0", "1"], 63 | # "num_classes": 2, 64 | "train_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label\train", 65 | "validation_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label\test", 66 | "test_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label\test", 67 | "color_mode": "rgb", 68 | "class_mode": "categorical", # generatorのラベルをone-hotベクトルに変換する場合。generatorのラベルを0か1のどちらかに変えるだけなら'binary' 69 | "activation": "softmax", 70 | # "loss": "categorical_crossentropy", 71 | "loss": keras.losses.CategoricalCrossentropy(label_smoothing=0.1), 72 | "metrics": [ 73 | "accuracy", 74 | keras.metrics.Precision(name="precision"), 75 | keras.metrics.Recall(name="recall"), 76 | keras.metrics.AUC(name="auc"), 77 | ], 78 | "model_path": None, 79 | # 初期モデル指定する!!! 80 | # "model_path": r"D:\work\candlestick_model\output\model\ts_dataset_all_2day_label\best_val_loss_20200727.h5", 81 | "num_epoch": 200, 82 | "n_multitask": 1, # マルチタスクのタスク数 83 | "multitask_pred_n_node": 1, # マルチタスクの各クラス数 84 | # model param 85 | "weights": "imagenet", 86 | "choice_model": "Xception", 87 | # "choice_model": "model_paper", 88 | "fcpool": "GlobalAveragePooling2D", 89 | "is_skip_bn": False, 90 | # "trainable": "all", # 249, 91 | # "trainable": 25, 92 | # "trainable": 45, 93 | # "trainable": 65, 94 | # "trainable": 85, 95 | "trainable": 105, 96 | # "trainable": 125, 97 | "efficientnet_num": 3, 98 | # full layer param 99 | # "fcs": [], 100 | "fcs": [100], 101 | "drop": 0.3, 102 | "is_add_batchnorm": False, # True, 103 | "l2_rate": 1e-4, 104 | # optimizer param 105 | "choice_optim": "sgd", 106 | "lr": 1e-1, 107 | "decay": 1e-5, 108 | "my_IDG_options": my_IDG_options, 109 | #'train_augmentor_options': train_augmentor_options, 110 | "TTA": "", # 'flip', 111 | "TTA_rotate_deg": 0, 112 | "TTA_crop_num": 0, 113 | "TTA_crop_size": [224, 224], 114 | "preprocess": 1.0, 115 | "resize_size": [100, 100], 116 | "is_flow": False, 117 | "is_flow_from_directory": True, 118 | "is_flow_from_dataframe": False, 119 | # "is_lr_finder": False, 120 | "is_lr_finder": True, 121 | "is_class_weight": True, 122 | } 123 | -------------------------------------------------------------------------------- /code/config/param_2day_label_trainable125.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | # tensorflowのINFOレベルのログを出さないようにする 4 | os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2" 5 | import tensorflow as tf 6 | from tensorflow import keras 7 | 8 | 9 | def get_class_fine_tuning_parameter_base() -> dict: 10 | """ 11 | Get parameter sample for class fine_tuning (like Keras) 12 | Returns: 13 | dict: parameter sample generated by trial object 14 | """ 15 | my_IDG_options = { 16 | "rescale": 1.0 / 255.0, 17 | #'width_shift_range': 0.2, 18 | #'height_shift_range': 0.2, 19 | #'horizontal_flip': True, 20 | #'vertical_flip': True, 21 | #'shear_range': 20, 22 | #'zoom_range': 0.2, 23 | #'rotation_range': 20, 24 | #'channel_shift_range': 50, 25 | #'brightness_range': [0.3, 1.0], 26 | # "random_erasing_prob": 0.5, 27 | # "random_erasing_maxpixel": 255, 28 | #'mix_up_alpha': 0.2, 29 | #'random_crop': [224,224], 30 | #'ricap_beta': 0.3, 31 | #'ricap_use_same_random_value_on_batch': True, 32 | "randaugment_N": 3, 33 | "randaugment_M": 4, 34 | #'is_kuzushiji_gen': True, 35 | "cutmix_alpha": 1.0, 36 | } 37 | 38 | ## Augmentor使う場合のoption 39 | # train_augmentor_options = { 40 | # 'input_width': 80, 41 | # 'input_height': 80, 42 | # 'random_dist_prob': 0.3, 43 | # 'zoom_prob': 0.3, 44 | # 'zoom_min': 0.5 45 | # , 'zoom_max': 1.9 46 | # , 'flip_left_right': 0.3 47 | # , 'flip_top_bottom': 0.3 48 | # , 'random_erasing_prob': 0.3 49 | # , 'random_erasing_area': 0.3 50 | # } 51 | 52 | return { 53 | "output_dir": r"D:\work\candlestick_model\output\model\ts_dataset_all_2day_label\Xception\trainable\_125", 54 | # "output_dir": r"D:\work\candlestick_model\output\model\ts_dataset_all_2day_label\model_paper", 55 | "gpu_count": 1, 56 | "img_rows": 80, 57 | "img_cols": 80, 58 | "channels": 3, 59 | "batch_size": 256, 60 | "classes": ["0", "1", "2"], 61 | "num_classes": 3, 62 | # "classes": ["0", "1"], 63 | # "num_classes": 2, 64 | "train_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label\train", 65 | "validation_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label\test", 66 | "test_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label\test", 67 | "color_mode": "rgb", 68 | "class_mode": "categorical", # generatorのラベルをone-hotベクトルに変換する場合。generatorのラベルを0か1のどちらかに変えるだけなら'binary' 69 | "activation": "softmax", 70 | # "loss": "categorical_crossentropy", 71 | "loss": keras.losses.CategoricalCrossentropy(label_smoothing=0.1), 72 | "metrics": [ 73 | "accuracy", 74 | keras.metrics.Precision(name="precision"), 75 | keras.metrics.Recall(name="recall"), 76 | keras.metrics.AUC(name="auc"), 77 | ], 78 | "model_path": None, 79 | # 初期モデル指定する!!! 80 | # "model_path": r"D:\work\candlestick_model\output\model\ts_dataset_all_2day_label\best_val_loss_20200727.h5", 81 | "num_epoch": 200, 82 | "n_multitask": 1, # マルチタスクのタスク数 83 | "multitask_pred_n_node": 1, # マルチタスクの各クラス数 84 | # model param 85 | "weights": "imagenet", 86 | "choice_model": "Xception", 87 | # "choice_model": "model_paper", 88 | "fcpool": "GlobalAveragePooling2D", 89 | "is_skip_bn": False, 90 | # "trainable": "all", # 249, 91 | # "trainable": 25, 92 | # "trainable": 45, 93 | # "trainable": 65, 94 | # "trainable": 85, 95 | # "trainable": 105, 96 | "trainable": 125, 97 | "efficientnet_num": 3, 98 | # full layer param 99 | # "fcs": [], 100 | "fcs": [100], 101 | "drop": 0.3, 102 | "is_add_batchnorm": False, # True, 103 | "l2_rate": 1e-4, 104 | # optimizer param 105 | "choice_optim": "sgd", 106 | "lr": 1e-1, 107 | "decay": 1e-5, 108 | "my_IDG_options": my_IDG_options, 109 | #'train_augmentor_options': train_augmentor_options, 110 | "TTA": "", # 'flip', 111 | "TTA_rotate_deg": 0, 112 | "TTA_crop_num": 0, 113 | "TTA_crop_size": [224, 224], 114 | "preprocess": 1.0, 115 | "resize_size": [100, 100], 116 | "is_flow": False, 117 | "is_flow_from_directory": True, 118 | "is_flow_from_dataframe": False, 119 | # "is_lr_finder": False, 120 | "is_lr_finder": True, 121 | "is_class_weight": True, 122 | } 123 | -------------------------------------------------------------------------------- /code/config/param_2day_label_trainable45.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | # tensorflowのINFOレベルのログを出さないようにする 4 | os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2" 5 | import tensorflow as tf 6 | from tensorflow import keras 7 | 8 | 9 | def get_class_fine_tuning_parameter_base() -> dict: 10 | """ 11 | Get parameter sample for class fine_tuning (like Keras) 12 | Returns: 13 | dict: parameter sample generated by trial object 14 | """ 15 | my_IDG_options = { 16 | "rescale": 1.0 / 255.0, 17 | #'width_shift_range': 0.2, 18 | #'height_shift_range': 0.2, 19 | #'horizontal_flip': True, 20 | #'vertical_flip': True, 21 | #'shear_range': 20, 22 | #'zoom_range': 0.2, 23 | #'rotation_range': 20, 24 | #'channel_shift_range': 50, 25 | #'brightness_range': [0.3, 1.0], 26 | # "random_erasing_prob": 0.5, 27 | # "random_erasing_maxpixel": 255, 28 | #'mix_up_alpha': 0.2, 29 | #'random_crop': [224,224], 30 | #'ricap_beta': 0.3, 31 | #'ricap_use_same_random_value_on_batch': True, 32 | "randaugment_N": 3, 33 | "randaugment_M": 4, 34 | #'is_kuzushiji_gen': True, 35 | "cutmix_alpha": 1.0, 36 | } 37 | 38 | ## Augmentor使う場合のoption 39 | # train_augmentor_options = { 40 | # 'input_width': 80, 41 | # 'input_height': 80, 42 | # 'random_dist_prob': 0.3, 43 | # 'zoom_prob': 0.3, 44 | # 'zoom_min': 0.5 45 | # , 'zoom_max': 1.9 46 | # , 'flip_left_right': 0.3 47 | # , 'flip_top_bottom': 0.3 48 | # , 'random_erasing_prob': 0.3 49 | # , 'random_erasing_area': 0.3 50 | # } 51 | 52 | return { 53 | "output_dir": r"D:\work\candlestick_model\output\model\ts_dataset_all_2day_label\Xception\trainable\_45", 54 | # "output_dir": r"D:\work\candlestick_model\output\model\ts_dataset_all_2day_label\model_paper", 55 | "gpu_count": 1, 56 | "img_rows": 80, 57 | "img_cols": 80, 58 | "channels": 3, 59 | "batch_size": 256, 60 | "classes": ["0", "1", "2"], 61 | "num_classes": 3, 62 | # "classes": ["0", "1"], 63 | # "num_classes": 2, 64 | "train_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label\train", 65 | "validation_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label\test", 66 | "test_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label\test", 67 | "color_mode": "rgb", 68 | "class_mode": "categorical", # generatorのラベルをone-hotベクトルに変換する場合。generatorのラベルを0か1のどちらかに変えるだけなら'binary' 69 | "activation": "softmax", 70 | # "loss": "categorical_crossentropy", 71 | "loss": keras.losses.CategoricalCrossentropy(label_smoothing=0.1), 72 | "metrics": [ 73 | "accuracy", 74 | keras.metrics.Precision(name="precision"), 75 | keras.metrics.Recall(name="recall"), 76 | keras.metrics.AUC(name="auc"), 77 | ], 78 | "model_path": None, 79 | # 初期モデル指定する!!! 80 | # "model_path": r"D:\work\candlestick_model\output\model\ts_dataset_all_2day_label\best_val_loss_20200727.h5", 81 | "num_epoch": 200, 82 | "n_multitask": 1, # マルチタスクのタスク数 83 | "multitask_pred_n_node": 1, # マルチタスクの各クラス数 84 | # model param 85 | "weights": "imagenet", 86 | "choice_model": "Xception", 87 | # "choice_model": "model_paper", 88 | "fcpool": "GlobalAveragePooling2D", 89 | "is_skip_bn": False, 90 | # "trainable": "all", # 249, 91 | # "trainable": 25, 92 | "trainable": 45, 93 | # "trainable": 65, 94 | # "trainable": 85, 95 | # "trainable": 105, 96 | # "trainable": 125, 97 | "efficientnet_num": 3, 98 | # full layer param 99 | # "fcs": [], 100 | "fcs": [100], 101 | "drop": 0.3, 102 | "is_add_batchnorm": False, # True, 103 | "l2_rate": 1e-4, 104 | # optimizer param 105 | "choice_optim": "sgd", 106 | "lr": 1e-1, 107 | "decay": 1e-5, 108 | "my_IDG_options": my_IDG_options, 109 | #'train_augmentor_options': train_augmentor_options, 110 | "TTA": "", # 'flip', 111 | "TTA_rotate_deg": 0, 112 | "TTA_crop_num": 0, 113 | "TTA_crop_size": [224, 224], 114 | "preprocess": 1.0, 115 | "resize_size": [100, 100], 116 | "is_flow": False, 117 | "is_flow_from_directory": True, 118 | "is_flow_from_dataframe": False, 119 | # "is_lr_finder": False, 120 | "is_lr_finder": True, 121 | "is_class_weight": True, 122 | } 123 | -------------------------------------------------------------------------------- /code/config/param_2day_label_trainable65.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | # tensorflowのINFOレベルのログを出さないようにする 4 | os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2" 5 | import tensorflow as tf 6 | from tensorflow import keras 7 | 8 | 9 | def get_class_fine_tuning_parameter_base() -> dict: 10 | """ 11 | Get parameter sample for class fine_tuning (like Keras) 12 | Returns: 13 | dict: parameter sample generated by trial object 14 | """ 15 | my_IDG_options = { 16 | "rescale": 1.0 / 255.0, 17 | #'width_shift_range': 0.2, 18 | #'height_shift_range': 0.2, 19 | #'horizontal_flip': True, 20 | #'vertical_flip': True, 21 | #'shear_range': 20, 22 | #'zoom_range': 0.2, 23 | #'rotation_range': 20, 24 | #'channel_shift_range': 50, 25 | #'brightness_range': [0.3, 1.0], 26 | # "random_erasing_prob": 0.5, 27 | # "random_erasing_maxpixel": 255, 28 | #'mix_up_alpha': 0.2, 29 | #'random_crop': [224,224], 30 | #'ricap_beta': 0.3, 31 | #'ricap_use_same_random_value_on_batch': True, 32 | "randaugment_N": 3, 33 | "randaugment_M": 4, 34 | #'is_kuzushiji_gen': True, 35 | "cutmix_alpha": 1.0, 36 | } 37 | 38 | ## Augmentor使う場合のoption 39 | # train_augmentor_options = { 40 | # 'input_width': 80, 41 | # 'input_height': 80, 42 | # 'random_dist_prob': 0.3, 43 | # 'zoom_prob': 0.3, 44 | # 'zoom_min': 0.5 45 | # , 'zoom_max': 1.9 46 | # , 'flip_left_right': 0.3 47 | # , 'flip_top_bottom': 0.3 48 | # , 'random_erasing_prob': 0.3 49 | # , 'random_erasing_area': 0.3 50 | # } 51 | 52 | return { 53 | "output_dir": r"D:\work\candlestick_model\output\model\ts_dataset_all_2day_label\Xception\trainable\_65", 54 | # "output_dir": r"D:\work\candlestick_model\output\model\ts_dataset_all_2day_label\model_paper", 55 | "gpu_count": 1, 56 | "img_rows": 80, 57 | "img_cols": 80, 58 | "channels": 3, 59 | "batch_size": 256, 60 | "classes": ["0", "1", "2"], 61 | "num_classes": 3, 62 | # "classes": ["0", "1"], 63 | # "num_classes": 2, 64 | "train_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label\train", 65 | "validation_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label\test", 66 | "test_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label\test", 67 | "color_mode": "rgb", 68 | "class_mode": "categorical", # generatorのラベルをone-hotベクトルに変換する場合。generatorのラベルを0か1のどちらかに変えるだけなら'binary' 69 | "activation": "softmax", 70 | # "loss": "categorical_crossentropy", 71 | "loss": keras.losses.CategoricalCrossentropy(label_smoothing=0.1), 72 | "metrics": [ 73 | "accuracy", 74 | keras.metrics.Precision(name="precision"), 75 | keras.metrics.Recall(name="recall"), 76 | keras.metrics.AUC(name="auc"), 77 | ], 78 | "model_path": None, 79 | # 初期モデル指定する!!! 80 | # "model_path": r"D:\work\candlestick_model\output\model\ts_dataset_all_2day_label\best_val_loss_20200727.h5", 81 | "num_epoch": 200, 82 | "n_multitask": 1, # マルチタスクのタスク数 83 | "multitask_pred_n_node": 1, # マルチタスクの各クラス数 84 | # model param 85 | "weights": "imagenet", 86 | "choice_model": "Xception", 87 | # "choice_model": "model_paper", 88 | "fcpool": "GlobalAveragePooling2D", 89 | "is_skip_bn": False, 90 | # "trainable": "all", # 249, 91 | # "trainable": 25, 92 | # "trainable": 45, 93 | "trainable": 65, 94 | # "trainable": 85, 95 | # "trainable": 105, 96 | # "trainable": 125, 97 | "efficientnet_num": 3, 98 | # full layer param 99 | # "fcs": [], 100 | "fcs": [100], 101 | "drop": 0.3, 102 | "is_add_batchnorm": False, # True, 103 | "l2_rate": 1e-4, 104 | # optimizer param 105 | "choice_optim": "sgd", 106 | "lr": 1e-1, 107 | "decay": 1e-5, 108 | "my_IDG_options": my_IDG_options, 109 | #'train_augmentor_options': train_augmentor_options, 110 | "TTA": "", # 'flip', 111 | "TTA_rotate_deg": 0, 112 | "TTA_crop_num": 0, 113 | "TTA_crop_size": [224, 224], 114 | "preprocess": 1.0, 115 | "resize_size": [100, 100], 116 | "is_flow": False, 117 | "is_flow_from_directory": True, 118 | "is_flow_from_dataframe": False, 119 | # "is_lr_finder": False, 120 | "is_lr_finder": True, 121 | "is_class_weight": True, 122 | } 123 | -------------------------------------------------------------------------------- /code/config/param_2day_label_trainable85.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | # tensorflowのINFOレベルのログを出さないようにする 4 | os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2" 5 | import tensorflow as tf 6 | from tensorflow import keras 7 | 8 | 9 | def get_class_fine_tuning_parameter_base() -> dict: 10 | """ 11 | Get parameter sample for class fine_tuning (like Keras) 12 | Returns: 13 | dict: parameter sample generated by trial object 14 | """ 15 | my_IDG_options = { 16 | "rescale": 1.0 / 255.0, 17 | #'width_shift_range': 0.2, 18 | #'height_shift_range': 0.2, 19 | #'horizontal_flip': True, 20 | #'vertical_flip': True, 21 | #'shear_range': 20, 22 | #'zoom_range': 0.2, 23 | #'rotation_range': 20, 24 | #'channel_shift_range': 50, 25 | #'brightness_range': [0.3, 1.0], 26 | # "random_erasing_prob": 0.5, 27 | # "random_erasing_maxpixel": 255, 28 | #'mix_up_alpha': 0.2, 29 | #'random_crop': [224,224], 30 | #'ricap_beta': 0.3, 31 | #'ricap_use_same_random_value_on_batch': True, 32 | "randaugment_N": 3, 33 | "randaugment_M": 4, 34 | #'is_kuzushiji_gen': True, 35 | "cutmix_alpha": 1.0, 36 | } 37 | 38 | ## Augmentor使う場合のoption 39 | # train_augmentor_options = { 40 | # 'input_width': 80, 41 | # 'input_height': 80, 42 | # 'random_dist_prob': 0.3, 43 | # 'zoom_prob': 0.3, 44 | # 'zoom_min': 0.5 45 | # , 'zoom_max': 1.9 46 | # , 'flip_left_right': 0.3 47 | # , 'flip_top_bottom': 0.3 48 | # , 'random_erasing_prob': 0.3 49 | # , 'random_erasing_area': 0.3 50 | # } 51 | 52 | return { 53 | "output_dir": r"D:\work\candlestick_model\output\model\ts_dataset_all_2day_label\Xception\trainable\_85", 54 | # "output_dir": r"D:\work\candlestick_model\output\model\ts_dataset_all_2day_label\model_paper", 55 | "gpu_count": 1, 56 | "img_rows": 80, 57 | "img_cols": 80, 58 | "channels": 3, 59 | "batch_size": 256, 60 | "classes": ["0", "1", "2"], 61 | "num_classes": 3, 62 | # "classes": ["0", "1"], 63 | # "num_classes": 2, 64 | "train_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label\train", 65 | "validation_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label\test", 66 | "test_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label\test", 67 | "color_mode": "rgb", 68 | "class_mode": "categorical", # generatorのラベルをone-hotベクトルに変換する場合。generatorのラベルを0か1のどちらかに変えるだけなら'binary' 69 | "activation": "softmax", 70 | # "loss": "categorical_crossentropy", 71 | "loss": keras.losses.CategoricalCrossentropy(label_smoothing=0.1), 72 | "metrics": [ 73 | "accuracy", 74 | keras.metrics.Precision(name="precision"), 75 | keras.metrics.Recall(name="recall"), 76 | keras.metrics.AUC(name="auc"), 77 | ], 78 | "model_path": None, 79 | # 初期モデル指定する!!! 80 | # "model_path": r"D:\work\candlestick_model\output\model\ts_dataset_all_2day_label\best_val_loss_20200727.h5", 81 | "num_epoch": 200, 82 | "n_multitask": 1, # マルチタスクのタスク数 83 | "multitask_pred_n_node": 1, # マルチタスクの各クラス数 84 | # model param 85 | "weights": "imagenet", 86 | "choice_model": "Xception", 87 | # "choice_model": "model_paper", 88 | "fcpool": "GlobalAveragePooling2D", 89 | "is_skip_bn": False, 90 | # "trainable": "all", # 249, 91 | # "trainable": 25, 92 | # "trainable": 45, 93 | # "trainable": 65, 94 | "trainable": 85, 95 | # "trainable": 105, 96 | # "trainable": 125, 97 | "efficientnet_num": 3, 98 | # full layer param 99 | # "fcs": [], 100 | "fcs": [100], 101 | "drop": 0.3, 102 | "is_add_batchnorm": False, # True, 103 | "l2_rate": 1e-4, 104 | # optimizer param 105 | "choice_optim": "sgd", 106 | "lr": 1e-1, 107 | "decay": 1e-5, 108 | "my_IDG_options": my_IDG_options, 109 | #'train_augmentor_options': train_augmentor_options, 110 | "TTA": "", # 'flip', 111 | "TTA_rotate_deg": 0, 112 | "TTA_crop_num": 0, 113 | "TTA_crop_size": [224, 224], 114 | "preprocess": 1.0, 115 | "resize_size": [100, 100], 116 | "is_flow": False, 117 | "is_flow_from_directory": True, 118 | "is_flow_from_dataframe": False, 119 | # "is_lr_finder": False, 120 | "is_lr_finder": True, 121 | "is_class_weight": True, 122 | } 123 | -------------------------------------------------------------------------------- /code/config/param_2day_label_small.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | # tensorflowのINFOレベルのログを出さないようにする 4 | os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2" 5 | import tensorflow as tf 6 | from tensorflow import keras 7 | 8 | 9 | def get_class_fine_tuning_parameter_base() -> dict: 10 | """ 11 | Get parameter sample for class fine_tuning (like Keras) 12 | Returns: 13 | dict: parameter sample generated by trial object 14 | """ 15 | my_IDG_options = { 16 | "rescale": 1.0 / 255.0, 17 | #'width_shift_range': 0.2, 18 | #'height_shift_range': 0.2, 19 | #'horizontal_flip': True, 20 | #'vertical_flip': True, 21 | #'shear_range': 20, 22 | #'zoom_range': 0.2, 23 | #'rotation_range': 20, 24 | #'channel_shift_range': 50, 25 | #'brightness_range': [0.3, 1.0], 26 | # "random_erasing_prob": 0.5, 27 | # "random_erasing_maxpixel": 255, 28 | #'mix_up_alpha': 0.2, 29 | #'random_crop': [224,224], 30 | #'ricap_beta': 0.3, 31 | #'ricap_use_same_random_value_on_batch': True, 32 | "randaugment_N": 3, 33 | "randaugment_M": 4, 34 | #'is_kuzushiji_gen': True, 35 | "cutmix_alpha": 1.0, 36 | } 37 | 38 | ## Augmentor使う場合のoption 39 | # train_augmentor_options = { 40 | # 'input_width': 80, 41 | # 'input_height': 80, 42 | # 'random_dist_prob': 0.3, 43 | # 'zoom_prob': 0.3, 44 | # 'zoom_min': 0.5 45 | # , 'zoom_max': 1.9 46 | # , 'flip_left_right': 0.3 47 | # , 'flip_top_bottom': 0.3 48 | # , 'random_erasing_prob': 0.3 49 | # , 'random_erasing_area': 0.3 50 | # } 51 | 52 | return { 53 | "output_dir": r"D:\work\candlestick_model\output\model\ts_dataset_all_2day_label_small\Xception\all", 54 | "gpu_count": 1, 55 | "img_rows": 80, 56 | "img_cols": 80, 57 | "channels": 3, 58 | "batch_size": 256, 59 | "classes": ["0", "1", "2"], 60 | "num_classes": 3, 61 | # "classes": ["0", "1"], 62 | # "num_classes": 2, 63 | # "train_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small\train", 64 | # "validation_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small\test", 65 | # "test_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small\test", 66 | "train_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small_class2_reduce\train", 67 | "validation_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small_class2_reduce\test", 68 | "test_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small_class2_reduce\test", 69 | "color_mode": "rgb", 70 | "class_mode": "categorical", # generatorのラベルをone-hotベクトルに変換する場合。generatorのラベルを0か1のどちらかに変えるだけなら'binary' 71 | "activation": "softmax", 72 | # "loss": "categorical_crossentropy", 73 | "loss": keras.losses.CategoricalCrossentropy(label_smoothing=0.1), 74 | "metrics": [ 75 | "accuracy", 76 | keras.metrics.Precision(name="precision"), 77 | keras.metrics.Recall(name="recall"), 78 | keras.metrics.AUC(name="auc"), 79 | ], 80 | "model_path": None, 81 | # "model_path": r"D:\work\candlestick_model\output\model\ts_dataset_all_2day_label\best_val_loss_20200727.h5", 82 | "num_epoch": 3, # 200, 83 | "n_multitask": 1, # マルチタスクのタスク数 84 | "multitask_pred_n_node": 1, # マルチタスクの各クラス数 85 | # model param 86 | "weights": "imagenet", 87 | "choice_model": "Xception", 88 | # "choice_model": "model_paper", 89 | "fcpool": "GlobalAveragePooling2D", 90 | "is_skip_bn": False, 91 | "trainable": "all", # 249, 92 | # "trainable": 45, 93 | "efficientnet_num": 3, 94 | # full layer param 95 | "fcs": [100], 96 | "drop": 0.3, 97 | "is_add_batchnorm": False, # True, 98 | "l2_rate": 1e-4, 99 | # optimizer param 100 | "choice_optim": "sgd", 101 | "lr": 1e-1, 102 | "decay": 1e-5, 103 | "my_IDG_options": my_IDG_options, 104 | #'train_augmentor_options': train_augmentor_options, 105 | "TTA": "", # 'flip', 106 | "TTA_rotate_deg": 0, 107 | "TTA_crop_num": 0, 108 | "TTA_crop_size": [224, 224], 109 | "preprocess": 1.0, 110 | "resize_size": [100, 100], 111 | "is_flow": False, 112 | "is_flow_from_directory": True, 113 | "is_flow_from_dataframe": False, 114 | # "is_lr_finder": False, 115 | "is_lr_finder": True, 116 | "is_class_weight": True, 117 | } 118 | -------------------------------------------------------------------------------- /code/config/param_2day_label_small_trainable25.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | # tensorflowのINFOレベルのログを出さないようにする 4 | os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2" 5 | import tensorflow as tf 6 | from tensorflow import keras 7 | 8 | 9 | def get_class_fine_tuning_parameter_base() -> dict: 10 | """ 11 | Get parameter sample for class fine_tuning (like Keras) 12 | Returns: 13 | dict: parameter sample generated by trial object 14 | """ 15 | my_IDG_options = { 16 | "rescale": 1.0 / 255.0, 17 | #'width_shift_range': 0.2, 18 | #'height_shift_range': 0.2, 19 | #'horizontal_flip': True, 20 | #'vertical_flip': True, 21 | #'shear_range': 20, 22 | #'zoom_range': 0.2, 23 | #'rotation_range': 20, 24 | #'channel_shift_range': 50, 25 | #'brightness_range': [0.3, 1.0], 26 | # "random_erasing_prob": 0.5, 27 | # "random_erasing_maxpixel": 255, 28 | #'mix_up_alpha': 0.2, 29 | #'random_crop': [224,224], 30 | #'ricap_beta': 0.3, 31 | #'ricap_use_same_random_value_on_batch': True, 32 | "randaugment_N": 3, 33 | "randaugment_M": 4, 34 | #'is_kuzushiji_gen': True, 35 | "cutmix_alpha": 1.0, 36 | } 37 | 38 | ## Augmentor使う場合のoption 39 | # train_augmentor_options = { 40 | # 'input_width': 80, 41 | # 'input_height': 80, 42 | # 'random_dist_prob': 0.3, 43 | # 'zoom_prob': 0.3, 44 | # 'zoom_min': 0.5 45 | # , 'zoom_max': 1.9 46 | # , 'flip_left_right': 0.3 47 | # , 'flip_top_bottom': 0.3 48 | # , 'random_erasing_prob': 0.3 49 | # , 'random_erasing_area': 0.3 50 | # } 51 | 52 | return { 53 | "output_dir": r"D:\work\candlestick_model\output\model\ts_dataset_all_2day_label_small\Xception\_25", 54 | "gpu_count": 1, 55 | "img_rows": 80, 56 | "img_cols": 80, 57 | "channels": 3, 58 | "batch_size": 256, 59 | "classes": ["0", "1", "2"], 60 | "num_classes": 3, 61 | # "classes": ["0", "1"], 62 | # "num_classes": 2, 63 | # "train_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small\train", 64 | # "validation_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small\test", 65 | # "test_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small\test", 66 | "train_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small_class2_reduce\train", 67 | "validation_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small_class2_reduce\test", 68 | "test_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small_class2_reduce\test", 69 | "color_mode": "rgb", 70 | "class_mode": "categorical", # generatorのラベルをone-hotベクトルに変換する場合。generatorのラベルを0か1のどちらかに変えるだけなら'binary' 71 | "activation": "softmax", 72 | # "loss": "categorical_crossentropy", 73 | "loss": keras.losses.CategoricalCrossentropy(label_smoothing=0.1), 74 | "metrics": [ 75 | "accuracy", 76 | keras.metrics.Precision(name="precision"), 77 | keras.metrics.Recall(name="recall"), 78 | keras.metrics.AUC(name="auc"), 79 | ], 80 | "model_path": None, 81 | # "model_path": r"D:\work\candlestick_model\output\model\ts_dataset_all_2day_label\best_val_loss_20200727.h5", 82 | "num_epoch": 3, # 200, 83 | "n_multitask": 1, # マルチタスクのタスク数 84 | "multitask_pred_n_node": 1, # マルチタスクの各クラス数 85 | # model param 86 | "weights": "imagenet", 87 | "choice_model": "Xception", 88 | # "choice_model": "model_paper", 89 | "fcpool": "GlobalAveragePooling2D", 90 | "is_skip_bn": False, 91 | # "trainable": "all", # 249, 92 | "trainable": 25, 93 | "efficientnet_num": 3, 94 | # full layer param 95 | "fcs": [100], 96 | "drop": 0.3, 97 | "is_add_batchnorm": False, # True, 98 | "l2_rate": 1e-4, 99 | # optimizer param 100 | "choice_optim": "sgd", 101 | "lr": 1e-1, 102 | "decay": 1e-5, 103 | "my_IDG_options": my_IDG_options, 104 | #'train_augmentor_options': train_augmentor_options, 105 | "TTA": "", # 'flip', 106 | "TTA_rotate_deg": 0, 107 | "TTA_crop_num": 0, 108 | "TTA_crop_size": [224, 224], 109 | "preprocess": 1.0, 110 | "resize_size": [100, 100], 111 | "is_flow": False, 112 | "is_flow_from_directory": True, 113 | "is_flow_from_dataframe": False, 114 | # "is_lr_finder": False, 115 | "is_lr_finder": True, 116 | "is_class_weight": True, 117 | } 118 | -------------------------------------------------------------------------------- /code/config/param_2day_label_small_trainable45.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | # tensorflowのINFOレベルのログを出さないようにする 4 | os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2" 5 | import tensorflow as tf 6 | from tensorflow import keras 7 | 8 | 9 | def get_class_fine_tuning_parameter_base() -> dict: 10 | """ 11 | Get parameter sample for class fine_tuning (like Keras) 12 | Returns: 13 | dict: parameter sample generated by trial object 14 | """ 15 | my_IDG_options = { 16 | "rescale": 1.0 / 255.0, 17 | #'width_shift_range': 0.2, 18 | #'height_shift_range': 0.2, 19 | #'horizontal_flip': True, 20 | #'vertical_flip': True, 21 | #'shear_range': 20, 22 | #'zoom_range': 0.2, 23 | #'rotation_range': 20, 24 | #'channel_shift_range': 50, 25 | #'brightness_range': [0.3, 1.0], 26 | # "random_erasing_prob": 0.5, 27 | # "random_erasing_maxpixel": 255, 28 | #'mix_up_alpha': 0.2, 29 | #'random_crop': [224,224], 30 | #'ricap_beta': 0.3, 31 | #'ricap_use_same_random_value_on_batch': True, 32 | "randaugment_N": 3, 33 | "randaugment_M": 4, 34 | #'is_kuzushiji_gen': True, 35 | "cutmix_alpha": 1.0, 36 | } 37 | 38 | ## Augmentor使う場合のoption 39 | # train_augmentor_options = { 40 | # 'input_width': 80, 41 | # 'input_height': 80, 42 | # 'random_dist_prob': 0.3, 43 | # 'zoom_prob': 0.3, 44 | # 'zoom_min': 0.5 45 | # , 'zoom_max': 1.9 46 | # , 'flip_left_right': 0.3 47 | # , 'flip_top_bottom': 0.3 48 | # , 'random_erasing_prob': 0.3 49 | # , 'random_erasing_area': 0.3 50 | # } 51 | 52 | return { 53 | "output_dir": r"D:\work\candlestick_model\output\model\ts_dataset_all_2day_label_small\Xception\_45", 54 | "gpu_count": 1, 55 | "img_rows": 80, 56 | "img_cols": 80, 57 | "channels": 3, 58 | "batch_size": 256, 59 | "classes": ["0", "1", "2"], 60 | "num_classes": 3, 61 | # "classes": ["0", "1"], 62 | # "num_classes": 2, 63 | # "train_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small\train", 64 | # "validation_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small\test", 65 | # "test_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small\test", 66 | "train_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small_class2_reduce\train", 67 | "validation_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small_class2_reduce\test", 68 | "test_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small_class2_reduce\test", 69 | "color_mode": "rgb", 70 | "class_mode": "categorical", # generatorのラベルをone-hotベクトルに変換する場合。generatorのラベルを0か1のどちらかに変えるだけなら'binary' 71 | "activation": "softmax", 72 | # "loss": "categorical_crossentropy", 73 | "loss": keras.losses.CategoricalCrossentropy(label_smoothing=0.1), 74 | "metrics": [ 75 | "accuracy", 76 | keras.metrics.Precision(name="precision"), 77 | keras.metrics.Recall(name="recall"), 78 | keras.metrics.AUC(name="auc"), 79 | ], 80 | "model_path": None, 81 | # "model_path": r"D:\work\candlestick_model\output\model\ts_dataset_all_2day_label\best_val_loss_20200727.h5", 82 | "num_epoch": 3, # 200, 83 | "n_multitask": 1, # マルチタスクのタスク数 84 | "multitask_pred_n_node": 1, # マルチタスクの各クラス数 85 | # model param 86 | "weights": "imagenet", 87 | "choice_model": "Xception", 88 | # "choice_model": "model_paper", 89 | "fcpool": "GlobalAveragePooling2D", 90 | "is_skip_bn": False, 91 | # "trainable": "all", # 249, 92 | "trainable": 45, 93 | "efficientnet_num": 3, 94 | # full layer param 95 | "fcs": [100], 96 | "drop": 0.3, 97 | "is_add_batchnorm": False, # True, 98 | "l2_rate": 1e-4, 99 | # optimizer param 100 | "choice_optim": "sgd", 101 | "lr": 1e-1, 102 | "decay": 1e-5, 103 | "my_IDG_options": my_IDG_options, 104 | #'train_augmentor_options': train_augmentor_options, 105 | "TTA": "", # 'flip', 106 | "TTA_rotate_deg": 0, 107 | "TTA_crop_num": 0, 108 | "TTA_crop_size": [224, 224], 109 | "preprocess": 1.0, 110 | "resize_size": [100, 100], 111 | "is_flow": False, 112 | "is_flow_from_directory": True, 113 | "is_flow_from_dataframe": False, 114 | # "is_lr_finder": False, 115 | "is_lr_finder": True, 116 | "is_class_weight": True, 117 | } 118 | -------------------------------------------------------------------------------- /code/config/param_2day_label_small_trainable65.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | # tensorflowのINFOレベルのログを出さないようにする 4 | os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2" 5 | import tensorflow as tf 6 | from tensorflow import keras 7 | 8 | 9 | def get_class_fine_tuning_parameter_base() -> dict: 10 | """ 11 | Get parameter sample for class fine_tuning (like Keras) 12 | Returns: 13 | dict: parameter sample generated by trial object 14 | """ 15 | my_IDG_options = { 16 | "rescale": 1.0 / 255.0, 17 | #'width_shift_range': 0.2, 18 | #'height_shift_range': 0.2, 19 | #'horizontal_flip': True, 20 | #'vertical_flip': True, 21 | #'shear_range': 20, 22 | #'zoom_range': 0.2, 23 | #'rotation_range': 20, 24 | #'channel_shift_range': 50, 25 | #'brightness_range': [0.3, 1.0], 26 | # "random_erasing_prob": 0.5, 27 | # "random_erasing_maxpixel": 255, 28 | #'mix_up_alpha': 0.2, 29 | #'random_crop': [224,224], 30 | #'ricap_beta': 0.3, 31 | #'ricap_use_same_random_value_on_batch': True, 32 | "randaugment_N": 3, 33 | "randaugment_M": 4, 34 | #'is_kuzushiji_gen': True, 35 | "cutmix_alpha": 1.0, 36 | } 37 | 38 | ## Augmentor使う場合のoption 39 | # train_augmentor_options = { 40 | # 'input_width': 80, 41 | # 'input_height': 80, 42 | # 'random_dist_prob': 0.3, 43 | # 'zoom_prob': 0.3, 44 | # 'zoom_min': 0.5 45 | # , 'zoom_max': 1.9 46 | # , 'flip_left_right': 0.3 47 | # , 'flip_top_bottom': 0.3 48 | # , 'random_erasing_prob': 0.3 49 | # , 'random_erasing_area': 0.3 50 | # } 51 | 52 | return { 53 | "output_dir": r"D:\work\candlestick_model\output\model\ts_dataset_all_2day_label_small\Xception\_65", 54 | "gpu_count": 1, 55 | "img_rows": 80, 56 | "img_cols": 80, 57 | "channels": 3, 58 | "batch_size": 256, 59 | "classes": ["0", "1", "2"], 60 | "num_classes": 3, 61 | # "classes": ["0", "1"], 62 | # "num_classes": 2, 63 | # "train_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small\train", 64 | # "validation_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small\test", 65 | # "test_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small\test", 66 | "train_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small_class2_reduce\train", 67 | "validation_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small_class2_reduce\test", 68 | "test_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small_class2_reduce\test", 69 | "color_mode": "rgb", 70 | "class_mode": "categorical", # generatorのラベルをone-hotベクトルに変換する場合。generatorのラベルを0か1のどちらかに変えるだけなら'binary' 71 | "activation": "softmax", 72 | # "loss": "categorical_crossentropy", 73 | "loss": keras.losses.CategoricalCrossentropy(label_smoothing=0.1), 74 | "metrics": [ 75 | "accuracy", 76 | keras.metrics.Precision(name="precision"), 77 | keras.metrics.Recall(name="recall"), 78 | keras.metrics.AUC(name="auc"), 79 | ], 80 | "model_path": None, 81 | # "model_path": r"D:\work\candlestick_model\output\model\ts_dataset_all_2day_label\best_val_loss_20200727.h5", 82 | "num_epoch": 3, # 200, 83 | "n_multitask": 1, # マルチタスクのタスク数 84 | "multitask_pred_n_node": 1, # マルチタスクの各クラス数 85 | # model param 86 | "weights": "imagenet", 87 | "choice_model": "Xception", 88 | # "choice_model": "model_paper", 89 | "fcpool": "GlobalAveragePooling2D", 90 | "is_skip_bn": False, 91 | # "trainable": "all", # 249, 92 | "trainable": 65, 93 | "efficientnet_num": 3, 94 | # full layer param 95 | "fcs": [100], 96 | "drop": 0.3, 97 | "is_add_batchnorm": False, # True, 98 | "l2_rate": 1e-4, 99 | # optimizer param 100 | "choice_optim": "sgd", 101 | "lr": 1e-1, 102 | "decay": 1e-5, 103 | "my_IDG_options": my_IDG_options, 104 | #'train_augmentor_options': train_augmentor_options, 105 | "TTA": "", # 'flip', 106 | "TTA_rotate_deg": 0, 107 | "TTA_crop_num": 0, 108 | "TTA_crop_size": [224, 224], 109 | "preprocess": 1.0, 110 | "resize_size": [100, 100], 111 | "is_flow": False, 112 | "is_flow_from_directory": True, 113 | "is_flow_from_dataframe": False, 114 | # "is_lr_finder": False, 115 | "is_lr_finder": True, 116 | "is_class_weight": True, 117 | } 118 | -------------------------------------------------------------------------------- /code/config/param_2day_label_small_trainable85.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | # tensorflowのINFOレベルのログを出さないようにする 4 | os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2" 5 | import tensorflow as tf 6 | from tensorflow import keras 7 | 8 | 9 | def get_class_fine_tuning_parameter_base() -> dict: 10 | """ 11 | Get parameter sample for class fine_tuning (like Keras) 12 | Returns: 13 | dict: parameter sample generated by trial object 14 | """ 15 | my_IDG_options = { 16 | "rescale": 1.0 / 255.0, 17 | #'width_shift_range': 0.2, 18 | #'height_shift_range': 0.2, 19 | #'horizontal_flip': True, 20 | #'vertical_flip': True, 21 | #'shear_range': 20, 22 | #'zoom_range': 0.2, 23 | #'rotation_range': 20, 24 | #'channel_shift_range': 50, 25 | #'brightness_range': [0.3, 1.0], 26 | # "random_erasing_prob": 0.5, 27 | # "random_erasing_maxpixel": 255, 28 | #'mix_up_alpha': 0.2, 29 | #'random_crop': [224,224], 30 | #'ricap_beta': 0.3, 31 | #'ricap_use_same_random_value_on_batch': True, 32 | "randaugment_N": 3, 33 | "randaugment_M": 4, 34 | #'is_kuzushiji_gen': True, 35 | "cutmix_alpha": 1.0, 36 | } 37 | 38 | ## Augmentor使う場合のoption 39 | # train_augmentor_options = { 40 | # 'input_width': 80, 41 | # 'input_height': 80, 42 | # 'random_dist_prob': 0.3, 43 | # 'zoom_prob': 0.3, 44 | # 'zoom_min': 0.5 45 | # , 'zoom_max': 1.9 46 | # , 'flip_left_right': 0.3 47 | # , 'flip_top_bottom': 0.3 48 | # , 'random_erasing_prob': 0.3 49 | # , 'random_erasing_area': 0.3 50 | # } 51 | 52 | return { 53 | "output_dir": r"D:\work\candlestick_model\output\model\ts_dataset_all_2day_label_small\Xception\_85", 54 | "gpu_count": 1, 55 | "img_rows": 80, 56 | "img_cols": 80, 57 | "channels": 3, 58 | "batch_size": 256, 59 | "classes": ["0", "1", "2"], 60 | "num_classes": 3, 61 | # "classes": ["0", "1"], 62 | # "num_classes": 2, 63 | # "train_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small\train", 64 | # "validation_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small\test", 65 | # "test_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small\test", 66 | "train_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small_class2_reduce\train", 67 | "validation_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small_class2_reduce\test", 68 | "test_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small_class2_reduce\test", 69 | "color_mode": "rgb", 70 | "class_mode": "categorical", # generatorのラベルをone-hotベクトルに変換する場合。generatorのラベルを0か1のどちらかに変えるだけなら'binary' 71 | "activation": "softmax", 72 | # "loss": "categorical_crossentropy", 73 | "loss": keras.losses.CategoricalCrossentropy(label_smoothing=0.1), 74 | "metrics": [ 75 | "accuracy", 76 | keras.metrics.Precision(name="precision"), 77 | keras.metrics.Recall(name="recall"), 78 | keras.metrics.AUC(name="auc"), 79 | ], 80 | "model_path": None, 81 | # "model_path": r"D:\work\candlestick_model\output\model\ts_dataset_all_2day_label\best_val_loss_20200727.h5", 82 | "num_epoch": 3, # 200, 83 | "n_multitask": 1, # マルチタスクのタスク数 84 | "multitask_pred_n_node": 1, # マルチタスクの各クラス数 85 | # model param 86 | "weights": "imagenet", 87 | "choice_model": "Xception", 88 | # "choice_model": "model_paper", 89 | "fcpool": "GlobalAveragePooling2D", 90 | "is_skip_bn": False, 91 | # "trainable": "all", # 249, 92 | "trainable": 85, 93 | "efficientnet_num": 3, 94 | # full layer param 95 | "fcs": [100], 96 | "drop": 0.3, 97 | "is_add_batchnorm": False, # True, 98 | "l2_rate": 1e-4, 99 | # optimizer param 100 | "choice_optim": "sgd", 101 | "lr": 1e-1, 102 | "decay": 1e-5, 103 | "my_IDG_options": my_IDG_options, 104 | #'train_augmentor_options': train_augmentor_options, 105 | "TTA": "", # 'flip', 106 | "TTA_rotate_deg": 0, 107 | "TTA_crop_num": 0, 108 | "TTA_crop_size": [224, 224], 109 | "preprocess": 1.0, 110 | "resize_size": [100, 100], 111 | "is_flow": False, 112 | "is_flow_from_directory": True, 113 | "is_flow_from_dataframe": False, 114 | # "is_lr_finder": False, 115 | "is_lr_finder": True, 116 | "is_class_weight": True, 117 | } 118 | -------------------------------------------------------------------------------- /code/config/param_2day_label_small_trainable105.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | # tensorflowのINFOレベルのログを出さないようにする 4 | os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2" 5 | import tensorflow as tf 6 | from tensorflow import keras 7 | 8 | 9 | def get_class_fine_tuning_parameter_base() -> dict: 10 | """ 11 | Get parameter sample for class fine_tuning (like Keras) 12 | Returns: 13 | dict: parameter sample generated by trial object 14 | """ 15 | my_IDG_options = { 16 | "rescale": 1.0 / 255.0, 17 | #'width_shift_range': 0.2, 18 | #'height_shift_range': 0.2, 19 | #'horizontal_flip': True, 20 | #'vertical_flip': True, 21 | #'shear_range': 20, 22 | #'zoom_range': 0.2, 23 | #'rotation_range': 20, 24 | #'channel_shift_range': 50, 25 | #'brightness_range': [0.3, 1.0], 26 | # "random_erasing_prob": 0.5, 27 | # "random_erasing_maxpixel": 255, 28 | #'mix_up_alpha': 0.2, 29 | #'random_crop': [224,224], 30 | #'ricap_beta': 0.3, 31 | #'ricap_use_same_random_value_on_batch': True, 32 | "randaugment_N": 3, 33 | "randaugment_M": 4, 34 | #'is_kuzushiji_gen': True, 35 | "cutmix_alpha": 1.0, 36 | } 37 | 38 | ## Augmentor使う場合のoption 39 | # train_augmentor_options = { 40 | # 'input_width': 80, 41 | # 'input_height': 80, 42 | # 'random_dist_prob': 0.3, 43 | # 'zoom_prob': 0.3, 44 | # 'zoom_min': 0.5 45 | # , 'zoom_max': 1.9 46 | # , 'flip_left_right': 0.3 47 | # , 'flip_top_bottom': 0.3 48 | # , 'random_erasing_prob': 0.3 49 | # , 'random_erasing_area': 0.3 50 | # } 51 | 52 | return { 53 | "output_dir": r"D:\work\candlestick_model\output\model\ts_dataset_all_2day_label_small\Xception\_105", 54 | "gpu_count": 1, 55 | "img_rows": 80, 56 | "img_cols": 80, 57 | "channels": 3, 58 | "batch_size": 256, 59 | "classes": ["0", "1", "2"], 60 | "num_classes": 3, 61 | # "classes": ["0", "1"], 62 | # "num_classes": 2, 63 | # "train_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small\train", 64 | # "validation_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small\test", 65 | # "test_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small\test", 66 | "train_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small_class2_reduce\train", 67 | "validation_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small_class2_reduce\test", 68 | "test_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small_class2_reduce\test", 69 | "color_mode": "rgb", 70 | "class_mode": "categorical", # generatorのラベルをone-hotベクトルに変換する場合。generatorのラベルを0か1のどちらかに変えるだけなら'binary' 71 | "activation": "softmax", 72 | # "loss": "categorical_crossentropy", 73 | "loss": keras.losses.CategoricalCrossentropy(label_smoothing=0.1), 74 | "metrics": [ 75 | "accuracy", 76 | keras.metrics.Precision(name="precision"), 77 | keras.metrics.Recall(name="recall"), 78 | keras.metrics.AUC(name="auc"), 79 | ], 80 | "model_path": None, 81 | # "model_path": r"D:\work\candlestick_model\output\model\ts_dataset_all_2day_label\best_val_loss_20200727.h5", 82 | "num_epoch": 3, # 200, 83 | "n_multitask": 1, # マルチタスクのタスク数 84 | "multitask_pred_n_node": 1, # マルチタスクの各クラス数 85 | # model param 86 | "weights": "imagenet", 87 | "choice_model": "Xception", 88 | # "choice_model": "model_paper", 89 | "fcpool": "GlobalAveragePooling2D", 90 | "is_skip_bn": False, 91 | # "trainable": "all", # 249, 92 | "trainable": 105, 93 | "efficientnet_num": 3, 94 | # full layer param 95 | "fcs": [100], 96 | "drop": 0.3, 97 | "is_add_batchnorm": False, # True, 98 | "l2_rate": 1e-4, 99 | # optimizer param 100 | "choice_optim": "sgd", 101 | "lr": 1e-1, 102 | "decay": 1e-5, 103 | "my_IDG_options": my_IDG_options, 104 | #'train_augmentor_options': train_augmentor_options, 105 | "TTA": "", # 'flip', 106 | "TTA_rotate_deg": 0, 107 | "TTA_crop_num": 0, 108 | "TTA_crop_size": [224, 224], 109 | "preprocess": 1.0, 110 | "resize_size": [100, 100], 111 | "is_flow": False, 112 | "is_flow_from_directory": True, 113 | "is_flow_from_dataframe": False, 114 | # "is_lr_finder": False, 115 | "is_lr_finder": True, 116 | "is_class_weight": True, 117 | } 118 | -------------------------------------------------------------------------------- /code/config/param_2day_label_small_trainable125.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | # tensorflowのINFOレベルのログを出さないようにする 4 | os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2" 5 | import tensorflow as tf 6 | from tensorflow import keras 7 | 8 | 9 | def get_class_fine_tuning_parameter_base() -> dict: 10 | """ 11 | Get parameter sample for class fine_tuning (like Keras) 12 | Returns: 13 | dict: parameter sample generated by trial object 14 | """ 15 | my_IDG_options = { 16 | "rescale": 1.0 / 255.0, 17 | #'width_shift_range': 0.2, 18 | #'height_shift_range': 0.2, 19 | #'horizontal_flip': True, 20 | #'vertical_flip': True, 21 | #'shear_range': 20, 22 | #'zoom_range': 0.2, 23 | #'rotation_range': 20, 24 | #'channel_shift_range': 50, 25 | #'brightness_range': [0.3, 1.0], 26 | # "random_erasing_prob": 0.5, 27 | # "random_erasing_maxpixel": 255, 28 | #'mix_up_alpha': 0.2, 29 | #'random_crop': [224,224], 30 | #'ricap_beta': 0.3, 31 | #'ricap_use_same_random_value_on_batch': True, 32 | "randaugment_N": 3, 33 | "randaugment_M": 4, 34 | #'is_kuzushiji_gen': True, 35 | "cutmix_alpha": 1.0, 36 | } 37 | 38 | ## Augmentor使う場合のoption 39 | # train_augmentor_options = { 40 | # 'input_width': 80, 41 | # 'input_height': 80, 42 | # 'random_dist_prob': 0.3, 43 | # 'zoom_prob': 0.3, 44 | # 'zoom_min': 0.5 45 | # , 'zoom_max': 1.9 46 | # , 'flip_left_right': 0.3 47 | # , 'flip_top_bottom': 0.3 48 | # , 'random_erasing_prob': 0.3 49 | # , 'random_erasing_area': 0.3 50 | # } 51 | 52 | return { 53 | "output_dir": r"D:\work\candlestick_model\output\model\ts_dataset_all_2day_label_small\Xception\_125", 54 | "gpu_count": 1, 55 | "img_rows": 80, 56 | "img_cols": 80, 57 | "channels": 3, 58 | "batch_size": 256, 59 | "classes": ["0", "1", "2"], 60 | "num_classes": 3, 61 | # "classes": ["0", "1"], 62 | # "num_classes": 2, 63 | # "train_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small\train", 64 | # "validation_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small\test", 65 | # "test_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small\test", 66 | "train_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small_class2_reduce\train", 67 | "validation_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small_class2_reduce\test", 68 | "test_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_2day_label_small_class2_reduce\test", 69 | "color_mode": "rgb", 70 | "class_mode": "categorical", # generatorのラベルをone-hotベクトルに変換する場合。generatorのラベルを0か1のどちらかに変えるだけなら'binary' 71 | "activation": "softmax", 72 | # "loss": "categorical_crossentropy", 73 | "loss": keras.losses.CategoricalCrossentropy(label_smoothing=0.1), 74 | "metrics": [ 75 | "accuracy", 76 | keras.metrics.Precision(name="precision"), 77 | keras.metrics.Recall(name="recall"), 78 | keras.metrics.AUC(name="auc"), 79 | ], 80 | "model_path": None, 81 | # "model_path": r"D:\work\candlestick_model\output\model\ts_dataset_all_2day_label\best_val_loss_20200727.h5", 82 | "num_epoch": 3, # 200, 83 | "n_multitask": 1, # マルチタスクのタスク数 84 | "multitask_pred_n_node": 1, # マルチタスクの各クラス数 85 | # model param 86 | "weights": "imagenet", 87 | "choice_model": "Xception", 88 | # "choice_model": "model_paper", 89 | "fcpool": "GlobalAveragePooling2D", 90 | "is_skip_bn": False, 91 | # "trainable": "all", # 249, 92 | "trainable": 125, 93 | "efficientnet_num": 3, 94 | # full layer param 95 | "fcs": [100], 96 | "drop": 0.3, 97 | "is_add_batchnorm": False, # True, 98 | "l2_rate": 1e-4, 99 | # optimizer param 100 | "choice_optim": "sgd", 101 | "lr": 1e-1, 102 | "decay": 1e-5, 103 | "my_IDG_options": my_IDG_options, 104 | #'train_augmentor_options': train_augmentor_options, 105 | "TTA": "", # 'flip', 106 | "TTA_rotate_deg": 0, 107 | "TTA_crop_num": 0, 108 | "TTA_crop_size": [224, 224], 109 | "preprocess": 1.0, 110 | "resize_size": [100, 100], 111 | "is_flow": False, 112 | "is_flow_from_directory": True, 113 | "is_flow_from_dataframe": False, 114 | # "is_lr_finder": False, 115 | "is_lr_finder": True, 116 | "is_class_weight": True, 117 | } 118 | -------------------------------------------------------------------------------- /code/config/param_positive_negative_line_label.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | # tensorflowのINFOレベルのログを出さないようにする 4 | os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2" 5 | import tensorflow as tf 6 | from tensorflow import keras 7 | 8 | 9 | def get_class_fine_tuning_parameter_base() -> dict: 10 | """ 11 | Get parameter sample for class fine_tuning (like Keras) 12 | Returns: 13 | dict: parameter sample generated by trial object 14 | """ 15 | my_IDG_options = { 16 | "rescale": 1.0 / 255.0, 17 | #'width_shift_range': 0.2, 18 | #'height_shift_range': 0.2, 19 | #'horizontal_flip': True, 20 | #'vertical_flip': True, 21 | #'shear_range': 20, 22 | #'zoom_range': 0.2, 23 | #'rotation_range': 20, 24 | #'channel_shift_range': 50, 25 | #'brightness_range': [0.3, 1.0], 26 | # "random_erasing_prob": 0.5, 27 | # "random_erasing_maxpixel": 255, 28 | #'mix_up_alpha': 0.2, 29 | #'random_crop': [224,224], 30 | #'ricap_beta': 0.3, 31 | #'ricap_use_same_random_value_on_batch': True, 32 | # "randaugment_N": 3, 33 | # "randaugment_M": 4, 34 | #'is_kuzushiji_gen': True, 35 | # "cutmix_alpha": 1.0, 36 | } 37 | 38 | ## Augmentor使う場合のoption 39 | # train_augmentor_options = { 40 | # 'input_width': 80, 41 | # 'input_height': 80, 42 | # 'random_dist_prob': 0.3, 43 | # 'zoom_prob': 0.3, 44 | # 'zoom_min': 0.5 45 | # , 'zoom_max': 1.9 46 | # , 'flip_left_right': 0.3 47 | # , 'flip_top_bottom': 0.3 48 | # , 'random_erasing_prob': 0.3 49 | # , 'random_erasing_area': 0.3 50 | # } 51 | 52 | return { 53 | "output_dir": r"D:\work\candlestick_model\output\model\ts_dataset_all_positive_negative_line_label", 54 | # "output_dir": r"D:\work\candlestick_model\output\model\ts_dataset_all_positive_negative_line_label\model_paper", 55 | "gpu_count": 1, 56 | "img_rows": 80, 57 | "img_cols": 80, 58 | "channels": 3, 59 | "batch_size": 256, 60 | "classes": ["0", "1", "2", "3"], 61 | "num_classes": 4, 62 | # "classes": ["0", "1"], 63 | # "num_classes": 2, 64 | "train_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_positive_negative_line_label\train", 65 | "validation_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_positive_negative_line_label\test", 66 | "test_data_dir": r"D:\work\candlestick_model\output\ts_dataset_all_positive_negative_line_label\test", 67 | "color_mode": "rgb", 68 | "class_mode": "categorical", # generatorのラベルをone-hotベクトルに変換する場合。generatorのラベルを0か1のどちらかに変えるだけなら'binary' 69 | "activation": "softmax", 70 | # "loss": "categorical_crossentropy", 71 | "loss": keras.losses.CategoricalCrossentropy(label_smoothing=0.1), 72 | "metrics": [ 73 | "accuracy", 74 | keras.metrics.Precision(name="precision"), 75 | keras.metrics.Recall(name="recall"), 76 | keras.metrics.AUC(name="auc"), 77 | ], 78 | "model_path": None, 79 | # 初期モデル指定する!!! 80 | # "model_path": r"D:\work\candlestick_model\output\model\ts_dataset_all_positive_negative_line_label\best_val_loss_20200727.h5", 81 | "num_epoch": 15, 82 | "n_multitask": 1, # マルチタスクのタスク数 83 | "multitask_pred_n_node": 1, # マルチタスクの各クラス数 84 | # model param 85 | "weights": "imagenet", 86 | # "choice_model": "Xception", 87 | "choice_model": "model_paper", 88 | "fcpool": "GlobalAveragePooling2D", 89 | "is_skip_bn": False, 90 | "trainable": "all", # 249, 91 | # "trainable": 25, 92 | # "trainable": 45, 93 | # "trainable": 65, 94 | # "trainable": 85, 95 | # "trainable": 105, 96 | # "trainable": 125, 97 | "efficientnet_num": 3, 98 | # full layer param 99 | "fcs": [], 100 | # "fcs": [100], 101 | "drop": 0.3, 102 | "is_add_batchnorm": False, # True, 103 | "l2_rate": 1e-4, 104 | # optimizer param 105 | "choice_optim": "sgd", 106 | "lr": 1e-1, 107 | "decay": 1e-5, 108 | "my_IDG_options": my_IDG_options, 109 | #'train_augmentor_options': train_augmentor_options, 110 | "TTA": "", # 'flip', 111 | "TTA_rotate_deg": 0, 112 | "TTA_crop_num": 0, 113 | "TTA_crop_size": [224, 224], 114 | "preprocess": 1.0, 115 | "resize_size": [100, 100], 116 | "is_flow": False, 117 | "is_flow_from_directory": True, 118 | "is_flow_from_dataframe": False, 119 | "is_lr_finder": False, 120 | # "is_lr_finder": True, 121 | "is_class_weight": True, 122 | } 123 | -------------------------------------------------------------------------------- /GitHub/mplfinance/tests/test_addplot.py: -------------------------------------------------------------------------------- 1 | import os 2 | import os.path 3 | import glob 4 | import mplfinance as mpf 5 | import matplotlib.pyplot as plt 6 | from matplotlib.testing.compare import compare_images 7 | 8 | print('mpf.__version__ =',mpf.__version__) # for the record 9 | print("plt.rcParams['backend'] =",plt.rcParams['backend']) # for the record 10 | 11 | base='addplot' 12 | tdir = os.path.join('tests','test_images') 13 | refd = os.path.join('tests','reference_images') 14 | 15 | globpattern = os.path.join(tdir,base+'*.png') 16 | oldtestfiles = glob.glob(globpattern) 17 | 18 | for fn in oldtestfiles: 19 | try: 20 | os.remove(fn) 21 | except: 22 | print('Error removing file "'+fn+'"') 23 | 24 | # IMGCOMP_TOLERANCE = 7.0 # this works fine for linux 25 | IMGCOMP_TOLERANCE = 11.0 # required for a windows pass. (really 10.25 may do it). 26 | 27 | def test_addplot01(bolldata): 28 | 29 | df = bolldata 30 | 31 | fname = base+'01.png' 32 | tname = os.path.join(tdir,fname) 33 | rname = os.path.join(refd,fname) 34 | 35 | fig_axis = mpf.plot(df,volume=True,savefig=tname,returnfig=True) 36 | plt.close(fig_axis[0]) 37 | 38 | tsize = os.path.getsize(tname) 39 | print(glob.glob(tname),'[',tsize,'bytes',']') 40 | 41 | rsize = os.path.getsize(rname) 42 | print(glob.glob(rname),'[',rsize,'bytes',']') 43 | 44 | result = compare_images(rname,tname,tol=IMGCOMP_TOLERANCE) 45 | if result is not None: 46 | print('result=',result) 47 | assert result is None 48 | 49 | def test_addplot02(bolldata): 50 | df = bolldata 51 | 52 | fname = base+'02.png' 53 | tname = os.path.join(tdir,fname) 54 | rname = os.path.join(refd,fname) 55 | 56 | apdict = mpf.make_addplot(df['LowerB']) 57 | fig_axis = mpf.plot(df,volume=True,addplot=apdict,savefig=tname,returnfig=True) 58 | plt.close(fig_axis[0]) 59 | 60 | tsize = os.path.getsize(tname) 61 | print(glob.glob(tname),'[',tsize,'bytes',']') 62 | 63 | rsize = os.path.getsize(rname) 64 | print(glob.glob(rname),'[',rsize,'bytes',']') 65 | 66 | result = compare_images(rname,tname,tol=IMGCOMP_TOLERANCE) 67 | if result is not None: 68 | print('result=',result) 69 | assert result is None 70 | 71 | def percentB_aboveone(percentB,price): 72 | import numpy as np 73 | signal = [] 74 | previous = 2 75 | for date,value in percentB.iteritems(): 76 | if value > 1 and previous <= 1: 77 | signal.append(price[date]*1.01) 78 | else: 79 | signal.append(np.nan) 80 | previous = value 81 | return signal 82 | 83 | def percentB_belowzero(percentB,price): 84 | import numpy as np 85 | signal = [] 86 | previous = -1.0 87 | for date,value in percentB.iteritems(): 88 | if value < 0 and previous >= 0: 89 | signal.append(price[date]*0.99) 90 | else: 91 | signal.append(np.nan) 92 | previous = value 93 | return signal 94 | 95 | def test_addplot03(bolldata): 96 | df = bolldata 97 | 98 | fname = base+'03.png' 99 | tname = os.path.join(tdir,fname) 100 | rname = os.path.join(refd,fname) 101 | 102 | tcdf = df[['LowerB','UpperB']] # DataFrame with two columns 103 | 104 | low_signal = percentB_belowzero(df['PercentB'], df['Close']) 105 | high_signal = percentB_aboveone(df['PercentB'], df['Close']) 106 | 107 | apds = [ mpf.make_addplot(tcdf), 108 | mpf.make_addplot(low_signal,scatter=True,markersize=200,marker='^'), 109 | mpf.make_addplot(high_signal,scatter=True,markersize=200,marker='v'), 110 | mpf.make_addplot((df['PercentB']),panel='lower',color='g') 111 | ] 112 | 113 | fig_axis = mpf.plot(df,addplot=apds,figscale=1.3,volume=True,savefig=tname,returnfig=True) 114 | plt.close(fig_axis[0]) 115 | 116 | tsize = os.path.getsize(tname) 117 | print(glob.glob(tname),'[',tsize,'bytes',']') 118 | 119 | rsize = os.path.getsize(rname) 120 | print(glob.glob(rname),'[',rsize,'bytes',']') 121 | 122 | result = compare_images(rname,tname,tol=IMGCOMP_TOLERANCE) 123 | if result is not None: 124 | print('result=',result) 125 | assert result is None 126 | 127 | def test_addplot04(bolldata): 128 | df = bolldata 129 | 130 | fname = base+'04.png' 131 | tname = os.path.join(tdir,fname) 132 | rname = os.path.join(refd,fname) 133 | 134 | tcdf = df[['LowerB','UpperB']] # DataFrame with two columns 135 | 136 | low_signal = percentB_belowzero(df['PercentB'], df['Close']) 137 | high_signal = percentB_aboveone(df['PercentB'], df['Close']) 138 | 139 | apds = [ mpf.make_addplot(tcdf,linestyle='dashdot'), 140 | mpf.make_addplot(low_signal,scatter=True,markersize=200,marker='^'), 141 | mpf.make_addplot(high_signal,scatter=True,markersize=200,marker='v'), 142 | mpf.make_addplot((df['PercentB']),panel='lower',color='g',linestyle='dotted') 143 | ] 144 | 145 | fig_axis = mpf.plot(df,addplot=apds,figscale=1.5,volume=True, 146 | style='starsandstripes',savefig=tname,returnfig=True) 147 | plt.close(fig_axis[0]) 148 | 149 | tsize = os.path.getsize(tname) 150 | print(glob.glob(tname),'[',tsize,'bytes',']') 151 | 152 | rsize = os.path.getsize(rname) 153 | print(glob.glob(rname),'[',rsize,'bytes',']') 154 | 155 | result = compare_images(rname,tname,tol=IMGCOMP_TOLERANCE) 156 | if result is not None: 157 | print('result=',result) 158 | assert result is None 159 | -------------------------------------------------------------------------------- /GitHub/mplfinance/src/mplfinance/_arg_validators.py: -------------------------------------------------------------------------------- 1 | import matplotlib.dates as mdates 2 | import pandas as pd 3 | import numpy as np 4 | 5 | def _check_and_prepare_data(data, config): 6 | ''' 7 | Check and Prepare the data input: 8 | For now, data must be a Pandas DataFrame with a DatetimeIndex 9 | and columns named 'Open', 'High', 'Low', 'Close', and optionally 'Volume' 10 | 11 | Later (if there is demand for it) we may accept all of the following data formats: 12 | 1. Pandas DataFrame with DatetimeIndex (as described above) 13 | 2. Pandas Series with DatetimeIndex: 14 | Values are close prices, and Series generates a line plot 15 | 3. Tuple of Lists, or List of Lists: 16 | The inner Lists are each columns, in the order: DateTime, Open, High, Low, Close, Volume 17 | 4. Tuple of Tuples or List of Tuples: 18 | The inner tuples are each row, containing values in the order: DateTime, Open, High, Low, Close, Volume 19 | 20 | Return a Tuple of Lists: datetimes, opens, highs, lows, closes, volumes 21 | ''' 22 | if not isinstance(data, pd.core.frame.DataFrame): 23 | raise TypeError('Expect data as DataFrame') 24 | 25 | if not isinstance(data.index,pd.core.indexes.datetimes.DatetimeIndex): 26 | raise TypeError('Expect data.index as DatetimeIndex') 27 | 28 | o, h, l, c, v = config["columns"] 29 | cols = [o, h, l, c] 30 | 31 | dates = mdates.date2num(data.index.to_pydatetime()) 32 | opens = data[o].values 33 | highs = data[h].values 34 | lows = data[l].values 35 | closes = data[c].values 36 | if v in data.columns: 37 | volumes = data[v].values 38 | cols.append(v) 39 | else: 40 | volumes = None 41 | 42 | for col in cols: 43 | if not all( isinstance(v,(float,int)) for v in data[col] ): 44 | raise ValueError('Data for column "'+str(col)+'" must be ALL float or int.') 45 | 46 | return dates, opens, highs, lows, closes, volumes 47 | 48 | 49 | def _mav_validator(mav_value): 50 | ''' 51 | Value for mav (moving average) keyword may be: 52 | scalar int greater than 1, or tuple of ints, or list of ints (greater than 1). 53 | tuple or list limited to length of 7 moving averages (to keep the plot clean). 54 | ''' 55 | if isinstance(mav_value,int) and mav_value > 1: 56 | return True 57 | elif not isinstance(mav_value,tuple) and not isinstance(mav_value,list): 58 | return False 59 | 60 | if not len(mav_value) < 8: 61 | return False 62 | for num in mav_value: 63 | if not isinstance(num,int) and num > 1: 64 | return False 65 | return True 66 | 67 | 68 | def _bypass_kwarg_validation(value): 69 | ''' For some kwargs, we either don't know enough, or 70 | the validation is too complex to make it worth while, 71 | so we bypass kwarg validation. If the kwarg is 72 | invalid, then eventually an exception will be 73 | raised at the time the kwarg value is actually used. 74 | ''' 75 | return True 76 | 77 | def _kwarg_not_implemented(value): 78 | ''' If you want to list a kwarg in a valid_kwargs dict for a given 79 | function, but you have not yet, or don't yet want to, implement 80 | the kwarg; or you simply want to (temporarily) disable the kwarg, 81 | then use this function as the kwarg validator 82 | ''' 83 | raise NotImplementedError('kwarg NOT implemented.') 84 | 85 | def _validate_vkwargs_dict(vkwargs): 86 | # Check that we didn't make a typo in any of the things 87 | # that should be the same for all vkwargs dict items: 88 | for key, value in vkwargs.items(): 89 | if len(value) != 2: 90 | raise ValueError('Items != 2 in valid kwarg table, for kwarg "'+key+'"') 91 | if 'Default' not in value: 92 | raise ValueError('Missing "Default" value for kwarg "'+key+'"') 93 | if 'Validator' not in value: 94 | raise ValueError('Missing "Validator" function for kwarg "'+key+'"') 95 | 96 | def _process_kwargs(kwargs, vkwargs): 97 | ''' 98 | Given a "valid kwargs table" and some kwargs, verify that each key-word 99 | is valid per the kwargs table, and that the value of the kwarg is the 100 | correct type. Fill a configuration dictionary with the default value 101 | for each kwarg, and then substitute in any values that were provided 102 | as kwargs and return the configuration dictionary. 103 | ''' 104 | # initialize configuration from valid_kwargs_table: 105 | config = {} 106 | for key, value in vkwargs.items(): 107 | config[key] = value['Default'] 108 | 109 | # now validate kwargs, and for any valid kwargs 110 | # replace the appropriate value in config: 111 | for key in kwargs.keys(): 112 | if key not in vkwargs: 113 | raise KeyError('Unrecognized kwarg="'+str(key)+'"') 114 | else: 115 | value = kwargs[key] 116 | try: 117 | valid = vkwargs[key]['Validator'](value) 118 | except Exception as ex: 119 | ex.extra_info = 'kwarg "'+key+'" validator raised exception to value: "'+str(value)+'"' 120 | raise 121 | if not valid: 122 | import inspect 123 | v = inspect.getsource(vkwargs[key]['Validator']).strip() 124 | raise TypeError('kwarg "'+key+'" validator returned False for value: "'+str(value)+'"\n '+v) 125 | 126 | # --------------------------------------------------------------- 127 | # At this point in the loop, if we have not raised an exception, 128 | # then kwarg is valid as far as we can tell, therefore, 129 | # go ahead and replace the appropriate value in config: 130 | 131 | config[key] = value 132 | 133 | return config 134 | -------------------------------------------------------------------------------- /jpx400_nikkei225_500.txt: -------------------------------------------------------------------------------- 1 | 1332 2 | 1333 3 | 1379 4 | 1518 5 | 1605 6 | 1662 7 | 1719 8 | 1720 9 | 1721 10 | 1801 11 | 1802 12 | 1803 13 | 1808 14 | 1812 15 | 1820 16 | 1821 17 | 1824 18 | 1860 19 | 1861 20 | 1878 21 | 1881 22 | 1893 23 | 1911 24 | 1925 25 | 1928 26 | 1942 27 | 1944 28 | 1951 29 | 1959 30 | 1963 31 | 2002 32 | 2121 33 | 2124 34 | 2127 35 | 2146 36 | 2175 37 | 2181 38 | 2201 39 | 2206 40 | 2212 41 | 2229 42 | 2264 43 | 2267 44 | 2269 45 | 2270 46 | 2282 47 | 2296 48 | 2327 49 | 2331 50 | 2337 51 | 2371 52 | 2379 53 | 2412 54 | 2413 55 | 2427 56 | 2432 57 | 2433 58 | 2501 59 | 2502 60 | 2503 61 | 2531 62 | 2579 63 | 2587 64 | 2593 65 | 2607 66 | 2651 67 | 2670 68 | 2702 69 | 2730 70 | 2768 71 | 2782 72 | 2784 73 | 2801 74 | 2802 75 | 2809 76 | 2810 77 | 2811 78 | 2815 79 | 2871 80 | 2875 81 | 2897 82 | 2914 83 | 3003 84 | 3038 85 | 3048 86 | 3064 87 | 3086 88 | 3088 89 | 3092 90 | 3099 91 | 3101 92 | 3103 93 | 3105 94 | 3107 95 | 3116 96 | 3141 97 | 3148 98 | 3167 99 | 3197 100 | 3231 101 | 3254 102 | 3288 103 | 3289 104 | 3291 105 | 3349 106 | 3360 107 | 3382 108 | 3391 109 | 3401 110 | 3402 111 | 3405 112 | 3407 113 | 3436 114 | 3543 115 | 3549 116 | 3626 117 | 3632 118 | 3656 119 | 3659 120 | 3668 121 | 3738 122 | 3765 123 | 3769 124 | 3861 125 | 3863 126 | 3865 127 | 3932 128 | 3938 129 | 3941 130 | 4004 131 | 4005 132 | 4021 133 | 4041 134 | 4042 135 | 4043 136 | 4061 137 | 4062 138 | 4063 139 | 4088 140 | 4091 141 | 4114 142 | 4118 143 | 4151 144 | 4182 145 | 4183 146 | 4185 147 | 4188 148 | 4202 149 | 4203 150 | 4204 151 | 4205 152 | 4206 153 | 4208 154 | 4246 155 | 4272 156 | 4307 157 | 4321 158 | 4324 159 | 4403 160 | 4452 161 | 4502 162 | 4503 163 | 4506 164 | 4507 165 | 4516 166 | 4519 167 | 4521 168 | 4523 169 | 4527 170 | 4528 171 | 4530 172 | 4536 173 | 4540 174 | 4543 175 | 4544 176 | 4555 177 | 4568 178 | 4578 179 | 4581 180 | 4587 181 | 4612 182 | 4613 183 | 4631 184 | 4661 185 | 4666 186 | 4676 187 | 4680 188 | 4681 189 | 4684 190 | 4689 191 | 4704 192 | 4716 193 | 4732 194 | 4739 195 | 4751 196 | 4755 197 | 4768 198 | 4819 199 | 4849 200 | 4901 201 | 4902 202 | 4911 203 | 4912 204 | 4921 205 | 4922 206 | 4927 207 | 4967 208 | 4974 209 | 5019 210 | 5020 211 | 5021 212 | 5101 213 | 5105 214 | 5108 215 | 5110 216 | 5201 217 | 5202 218 | 5214 219 | 5232 220 | 5233 221 | 5301 222 | 5332 223 | 5333 224 | 5334 225 | 5393 226 | 5401 227 | 5406 228 | 5411 229 | 5423 230 | 5444 231 | 5463 232 | 5471 233 | 5486 234 | 5541 235 | 5631 236 | 5703 237 | 5706 238 | 5707 239 | 5711 240 | 5713 241 | 5714 242 | 5741 243 | 5801 244 | 5802 245 | 5803 246 | 5901 247 | 5929 248 | 5938 249 | 5947 250 | 5975 251 | 5991 252 | 6028 253 | 6098 254 | 6103 255 | 6113 256 | 6135 257 | 6136 258 | 6141 259 | 6146 260 | 6178 261 | 6201 262 | 6268 263 | 6269 264 | 6273 265 | 6301 266 | 6302 267 | 6305 268 | 6324 269 | 6326 270 | 6361 271 | 6367 272 | 6370 273 | 6383 274 | 6395 275 | 6412 276 | 6417 277 | 6432 278 | 6448 279 | 6460 280 | 6463 281 | 6465 282 | 6471 283 | 6472 284 | 6473 285 | 6479 286 | 6481 287 | 6501 288 | 6503 289 | 6504 290 | 6506 291 | 6586 292 | 6588 293 | 6592 294 | 6594 295 | 6632 296 | 6641 297 | 6645 298 | 6674 299 | 6701 300 | 6702 301 | 6703 302 | 6723 303 | 6724 304 | 6727 305 | 6728 306 | 6740 307 | 6750 308 | 6752 309 | 6753 310 | 6754 311 | 6755 312 | 6758 313 | 6762 314 | 6770 315 | 6806 316 | 6807 317 | 6841 318 | 6845 319 | 6849 320 | 6856 321 | 6857 322 | 6861 323 | 6869 324 | 6877 325 | 6902 326 | 6920 327 | 6923 328 | 6925 329 | 6952 330 | 6954 331 | 6963 332 | 6965 333 | 6967 334 | 6971 335 | 6976 336 | 6981 337 | 6988 338 | 6995 339 | 7003 340 | 7004 341 | 7011 342 | 7012 343 | 7013 344 | 7014 345 | 7148 346 | 7164 347 | 7167 348 | 7180 349 | 7181 350 | 7182 351 | 7186 352 | 7189 353 | 7201 354 | 7202 355 | 7203 356 | 7205 357 | 7211 358 | 7224 359 | 7231 360 | 7240 361 | 7251 362 | 7259 363 | 7261 364 | 7267 365 | 7269 366 | 7270 367 | 7272 368 | 7276 369 | 7282 370 | 7309 371 | 7313 372 | 7419 373 | 7453 374 | 7458 375 | 7459 376 | 7518 377 | 7532 378 | 7550 379 | 7564 380 | 7575 381 | 7606 382 | 7649 383 | 7701 384 | 7717 385 | 7729 386 | 7731 387 | 7732 388 | 7733 389 | 7735 390 | 7741 391 | 7747 392 | 7751 393 | 7752 394 | 7762 395 | 7832 396 | 7846 397 | 7867 398 | 7911 399 | 7912 400 | 7915 401 | 7936 402 | 7951 403 | 7956 404 | 7974 405 | 7988 406 | 8001 407 | 8002 408 | 8015 409 | 8016 410 | 8020 411 | 8028 412 | 8031 413 | 8035 414 | 8053 415 | 8056 416 | 8058 417 | 8060 418 | 8086 419 | 8088 420 | 8111 421 | 8113 422 | 8136 423 | 8227 424 | 8233 425 | 8242 426 | 8252 427 | 8253 428 | 8267 429 | 8273 430 | 8279 431 | 8282 432 | 8283 433 | 8303 434 | 8304 435 | 8306 436 | 8308 437 | 8309 438 | 8316 439 | 8331 440 | 8334 441 | 8354 442 | 8355 443 | 8358 444 | 8359 445 | 8369 446 | 8377 447 | 8379 448 | 8382 449 | 8385 450 | 8410 451 | 8411 452 | 8418 453 | 8424 454 | 8439 455 | 8473 456 | 8515 457 | 8524 458 | 8570 459 | 8572 460 | 8585 461 | 8586 462 | 8591 463 | 8593 464 | 8595 465 | 8601 466 | 8604 467 | 8609 468 | 8616 469 | 8628 470 | 8630 471 | 8697 472 | 8698 473 | 8725 474 | 8729 475 | 8750 476 | 8766 477 | 8795 478 | 8801 479 | 8802 480 | 8804 481 | 8830 482 | 8848 483 | 8850 484 | 8876 485 | 8905 486 | 9001 487 | 9003 488 | 9005 489 | 9006 490 | 9007 491 | 9008 492 | 9009 493 | 9020 494 | 9021 495 | 9022 496 | 9024 497 | 9041 498 | 9042 499 | 9044 500 | 9045 501 | 9048 502 | 9062 503 | 9064 504 | 9065 505 | 9076 506 | 9086 507 | 9101 508 | 9104 509 | 9107 510 | 9142 511 | 9143 512 | 9201 513 | 9202 514 | 9232 515 | 9301 516 | 9303 517 | 9364 518 | 9401 519 | 9404 520 | 9412 521 | 9432 522 | 9433 523 | 9435 524 | 9437 525 | 9449 526 | 9468 527 | 9501 528 | 9502 529 | 9503 530 | 9504 531 | 9505 532 | 9506 533 | 9507 534 | 9508 535 | 9509 536 | 9513 537 | 9531 538 | 9532 539 | 9533 540 | 9602 541 | 9603 542 | 9613 543 | 9627 544 | 9678 545 | 9681 546 | 9684 547 | 9697 548 | 9706 549 | 9719 550 | 9735 551 | 9744 552 | 9766 553 | 9783 554 | 9810 555 | 9831 556 | 9843 557 | 9962 558 | 9983 559 | 9984 560 | 9987 561 | 9989 562 | -------------------------------------------------------------------------------- /GitHub/mplfinance/examples/original_flavor/finance_work2.py: -------------------------------------------------------------------------------- 1 | import matplotlib.dates as mdates 2 | import matplotlib.font_manager as font_manager 3 | import matplotlib.pyplot as plt 4 | import matplotlib.ticker as mticker 5 | import numpy as np 6 | import pandas as pd 7 | from pandas.plotting import register_matplotlib_converters 8 | register_matplotlib_converters() 9 | import os.path 10 | 11 | ticker = 'SPY' 12 | infile = os.path.join('data','yahoofinance-SPY-20080101-20180101.csv') 13 | r = pd.read_csv(infile, 14 | index_col=0, 15 | parse_dates=True, 16 | infer_datetime_format=True) 17 | 18 | 19 | def moving_average(x, n, type='simple'): 20 | """ 21 | compute an n period moving average. 22 | 23 | type is 'simple' | 'exponential' 24 | 25 | """ 26 | x = np.asarray(x) 27 | if type == 'simple': 28 | weights = np.ones(n) 29 | else: 30 | weights = np.exp(np.linspace(-1., 0., n)) 31 | 32 | weights /= weights.sum() 33 | 34 | a = np.convolve(x, weights, mode='full')[:len(x)] 35 | a[:n] = a[n] 36 | return a 37 | 38 | 39 | def relative_strength(prices, n=14): 40 | """ 41 | compute the n period relative strength indicator 42 | http://stockcharts.com/school/doku.php?id=chart_school:glossary_r#relativestrengthindex 43 | http://www.investopedia.com/terms/r/rsi.asp 44 | """ 45 | 46 | deltas = np.diff(prices) 47 | seed = deltas[:n + 1] 48 | up = seed[seed >= 0].sum() / n 49 | down = -seed[seed < 0].sum() / n 50 | rs = up / down 51 | rsi = np.zeros_like(prices) 52 | rsi[:n] = 100. - 100. / (1. + rs) 53 | 54 | for i in range(n, len(prices)): 55 | delta = deltas[i - 1] # cause the diff is 1 shorter 56 | 57 | if delta > 0: 58 | upval = delta 59 | downval = 0. 60 | else: 61 | upval = 0. 62 | downval = -delta 63 | 64 | up = (up * (n - 1) + upval) / n 65 | down = (down * (n - 1) + downval) / n 66 | 67 | rs = up / down 68 | rsi[i] = 100. - 100. / (1. + rs) 69 | 70 | return rsi 71 | 72 | 73 | def moving_average_convergence(x, nslow=26, nfast=12): 74 | """ 75 | compute the MACD (Moving Average Convergence/Divergence) using a fast and 76 | slow exponential moving avg 77 | 78 | return value is emaslow, emafast, macd which are len(x) arrays 79 | """ 80 | emaslow = moving_average(x, nslow, type='exponential') 81 | emafast = moving_average(x, nfast, type='exponential') 82 | return emaslow, emafast, emafast - emaslow 83 | 84 | 85 | plt.rc('axes', grid=True) 86 | plt.rc('grid', color='0.75', linestyle='-', linewidth=0.5) 87 | 88 | textsize = 9 89 | left, width = 0.1, 0.8 90 | rect1 = [left, 0.7, width, 0.2] 91 | rect2 = [left, 0.3, width, 0.4] 92 | rect3 = [left, 0.1, width, 0.2] 93 | 94 | 95 | fig = plt.figure(facecolor='white') 96 | axescolor = '#f6f6f6' # the axes background color 97 | 98 | ax1 = fig.add_axes(rect1, facecolor=axescolor) # left, bottom, width, height 99 | ax2 = fig.add_axes(rect2, facecolor=axescolor, sharex=ax1) 100 | ax2t = ax2.twinx() 101 | ax3 = fig.add_axes(rect3, facecolor=axescolor, sharex=ax1) 102 | 103 | 104 | # plot the relative strength indicator 105 | prices = r["Adj Close"] 106 | rsi = relative_strength(prices) 107 | fillcolor = 'darkgoldenrod' 108 | 109 | ax1.plot(r.index, rsi, color=fillcolor) 110 | ax1.axhline(70, color=fillcolor) 111 | ax1.axhline(30, color=fillcolor) 112 | ax1.fill_between(r.index, rsi, 70, where=(rsi >= 70), 113 | facecolor=fillcolor, edgecolor=fillcolor) 114 | ax1.fill_between(r.index, rsi, 30, where=(rsi <= 30), 115 | facecolor=fillcolor, edgecolor=fillcolor) 116 | ax1.text(0.6, 0.9, '>70 = overbought', va='top', 117 | transform=ax1.transAxes, fontsize=textsize) 118 | ax1.text(0.6, 0.1, '<30 = oversold', 119 | transform=ax1.transAxes, fontsize=textsize) 120 | ax1.set_ylim(0, 100) 121 | ax1.set_yticks([30, 70]) 122 | ax1.text(0.025, 0.95, 'RSI (14)', va='top', 123 | transform=ax1.transAxes, fontsize=textsize) 124 | ax1.set_title('%s daily' % ticker) 125 | 126 | # plot the price and volume data 127 | dx = r["Adj Close"] - r.Close 128 | low = r.Low + dx 129 | high = r.High + dx 130 | 131 | deltas = np.zeros_like(prices) 132 | deltas[1:] = np.diff(prices) 133 | up = deltas > 0 134 | ax2.vlines(r.index[up], low[up], high[up], color='black', label='_nolegend_') 135 | ax2.vlines(r.index[~up], low[~up], high[~up], 136 | color='black', label='_nolegend_') 137 | ma20 = moving_average(prices, 20, type='simple') 138 | ma200 = moving_average(prices, 200, type='simple') 139 | 140 | linema20, = ax2.plot(r.index, ma20, color='blue', lw=2, label='MA (20)') 141 | linema200, = ax2.plot(r.index, ma200, color='red', lw=2, label='MA (200)') 142 | 143 | last = r.tail(1) 144 | s = '%s O:%1.2f H:%1.2f L:%1.2f C:%1.2f, V:%1.1fM Chg:%+1.2f' % ( 145 | last.index.strftime('%Y.%m.%d')[0], 146 | last.Open, last.High, 147 | last.Low, last.Close, 148 | last.Volume * 1e-6, 149 | last.Close - last.Open) 150 | t4 = ax2.text(0.3, 0.9, s, transform=ax2.transAxes, fontsize=textsize) 151 | 152 | props = font_manager.FontProperties(size=10) 153 | leg = ax2.legend(loc='center left', shadow=True, fancybox=True, prop=props) 154 | leg.get_frame().set_alpha(0.5) 155 | 156 | 157 | volume = (r.Close * r.Volume) / 1e6 # dollar volume in millions 158 | vmax = volume.max() 159 | poly = ax2t.fill_between(r.index, volume, 0, label='Volume', 160 | facecolor=fillcolor, edgecolor=fillcolor) 161 | ax2t.set_ylim(0, 5 * vmax) 162 | ax2t.set_yticks([]) 163 | 164 | 165 | # compute the MACD indicator 166 | fillcolor = 'darkslategrey' 167 | nslow = 26 168 | nfast = 12 169 | nema = 9 170 | emaslow, emafast, macd = moving_average_convergence( 171 | prices, nslow=nslow, nfast=nfast) 172 | ema9 = moving_average(macd, nema, type='exponential') 173 | ax3.plot(r.index, macd, color='black', lw=2) 174 | ax3.plot(r.index, ema9, color='blue', lw=1) 175 | ax3.fill_between(r.index, macd - ema9, 0, alpha=0.5, 176 | facecolor=fillcolor, edgecolor=fillcolor) 177 | 178 | 179 | ax3.text(0.025, 0.95, 'MACD (%d, %d, %d)' % (nfast, nslow, nema), va='top', 180 | transform=ax3.transAxes, fontsize=textsize) 181 | 182 | # ax3.set_yticks([]) 183 | # turn off upper axis tick labels, rotate the lower ones, etc 184 | for ax in ax1, ax2, ax2t, ax3: 185 | if ax != ax3: 186 | for label in ax.get_xticklabels(): 187 | label.set_visible(False) 188 | else: 189 | for label in ax.get_xticklabels(): 190 | label.set_rotation(30) 191 | label.set_horizontalalignment('right') 192 | 193 | ax.fmt_xdata = mdates.DateFormatter('%Y-%m-%d') 194 | 195 | 196 | class MyLocator(mticker.MaxNLocator): 197 | def __init__(self, *args, **kwargs): 198 | mticker.MaxNLocator.__init__(self, *args, **kwargs) 199 | 200 | def __call__(self, *args, **kwargs): 201 | return mticker.MaxNLocator.__call__(self, *args, **kwargs) 202 | 203 | # at most 5 ticks, pruning the upper and lower so they don't overlap 204 | # with other ticks 205 | # ax2.yaxis.set_major_locator(mticker.MaxNLocator(5, prune='both')) 206 | # ax3.yaxis.set_major_locator(mticker.MaxNLocator(5, prune='both')) 207 | 208 | 209 | ax2.yaxis.set_major_locator(MyLocator(5, prune='both')) 210 | ax3.yaxis.set_major_locator(MyLocator(5, prune='both')) 211 | 212 | plt.show() 213 | -------------------------------------------------------------------------------- /GitHub/mplfinance/tests/original_flavor/test_finance_work2.py: -------------------------------------------------------------------------------- 1 | import matplotlib.dates as mdates 2 | import matplotlib.font_manager as font_manager 3 | import matplotlib.pyplot as plt 4 | import matplotlib.ticker as mticker 5 | import numpy as np 6 | import pandas as pd 7 | from pandas.plotting import register_matplotlib_converters 8 | register_matplotlib_converters() 9 | import os.path 10 | import io 11 | 12 | def test_finance_work2(): 13 | 14 | ticker = 'SPY' 15 | infile = os.path.join('examples','data','yahoofinance-SPY-20080101-20180101.csv') 16 | r = pd.read_csv(infile, 17 | index_col=0, 18 | parse_dates=True, 19 | infer_datetime_format=True) 20 | 21 | 22 | def moving_average(x, n, type='simple'): 23 | """ 24 | compute an n period moving average. 25 | 26 | type is 'simple' | 'exponential' 27 | 28 | """ 29 | x = np.asarray(x) 30 | if type == 'simple': 31 | weights = np.ones(n) 32 | else: 33 | weights = np.exp(np.linspace(-1., 0., n)) 34 | 35 | weights /= weights.sum() 36 | 37 | a = np.convolve(x, weights, mode='full')[:len(x)] 38 | a[:n] = a[n] 39 | return a 40 | 41 | 42 | def relative_strength(prices, n=14): 43 | """ 44 | compute the n period relative strength indicator 45 | http://stockcharts.com/school/doku.php?id=chart_school:glossary_r#relativestrengthindex 46 | http://www.investopedia.com/terms/r/rsi.asp 47 | """ 48 | 49 | deltas = np.diff(prices) 50 | seed = deltas[:n + 1] 51 | up = seed[seed >= 0].sum() / n 52 | down = -seed[seed < 0].sum() / n 53 | rs = up / down 54 | rsi = np.zeros_like(prices) 55 | rsi[:n] = 100. - 100. / (1. + rs) 56 | 57 | for i in range(n, len(prices)): 58 | delta = deltas[i - 1] # cause the diff is 1 shorter 59 | 60 | if delta > 0: 61 | upval = delta 62 | downval = 0. 63 | else: 64 | upval = 0. 65 | downval = -delta 66 | 67 | up = (up * (n - 1) + upval) / n 68 | down = (down * (n - 1) + downval) / n 69 | 70 | rs = up / down 71 | rsi[i] = 100. - 100. / (1. + rs) 72 | 73 | return rsi 74 | 75 | 76 | def moving_average_convergence(x, nslow=26, nfast=12): 77 | """ 78 | compute the MACD (Moving Average Convergence/Divergence) using a fast and 79 | slow exponential moving avg 80 | 81 | return value is emaslow, emafast, macd which are len(x) arrays 82 | """ 83 | emaslow = moving_average(x, nslow, type='exponential') 84 | emafast = moving_average(x, nfast, type='exponential') 85 | return emaslow, emafast, emafast - emaslow 86 | 87 | 88 | plt.rc('axes', grid=True) 89 | plt.rc('grid', color='0.75', linestyle='-', linewidth=0.5) 90 | 91 | textsize = 9 92 | left, width = 0.1, 0.8 93 | rect1 = [left, 0.7, width, 0.2] 94 | rect2 = [left, 0.3, width, 0.4] 95 | rect3 = [left, 0.1, width, 0.2] 96 | 97 | 98 | fig = plt.figure(facecolor='white') 99 | axescolor = '#f6f6f6' # the axes background color 100 | 101 | ax1 = fig.add_axes(rect1, facecolor=axescolor) # left, bottom, width, height 102 | ax2 = fig.add_axes(rect2, facecolor=axescolor, sharex=ax1) 103 | ax2t = ax2.twinx() 104 | ax3 = fig.add_axes(rect3, facecolor=axescolor, sharex=ax1) 105 | 106 | 107 | # plot the relative strength indicator 108 | prices = r["Adj Close"] 109 | rsi = relative_strength(prices) 110 | fillcolor = 'darkgoldenrod' 111 | 112 | ax1.plot(r.index.values, rsi, color=fillcolor) 113 | ax1.axhline(70, color=fillcolor) 114 | ax1.axhline(30, color=fillcolor) 115 | ax1.fill_between(r.index.values, rsi, 70, where=(rsi >= 70), 116 | facecolor=fillcolor, edgecolor=fillcolor) 117 | ax1.fill_between(r.index.values, rsi, 30, where=(rsi <= 30), 118 | facecolor=fillcolor, edgecolor=fillcolor) 119 | ax1.text(0.6, 0.9, '>70 = overbought', va='top', 120 | transform=ax1.transAxes, fontsize=textsize) 121 | ax1.text(0.6, 0.1, '<30 = oversold', 122 | transform=ax1.transAxes, fontsize=textsize) 123 | ax1.set_ylim(0, 100) 124 | ax1.set_yticks([30, 70]) 125 | ax1.text(0.025, 0.95, 'RSI (14)', va='top', 126 | transform=ax1.transAxes, fontsize=textsize) 127 | ax1.set_title('%s daily' % ticker) 128 | 129 | # plot the price and volume data 130 | dx = r["Adj Close"] - r.Close 131 | low = r.Low + dx 132 | high = r.High + dx 133 | 134 | deltas = np.zeros_like(prices) 135 | deltas[1:] = np.diff(prices) 136 | up = deltas > 0 137 | ax2.vlines(r.index[up], low[up], high[up], color='black', label='_nolegend_') 138 | ax2.vlines(r.index[~up], low[~up], high[~up], 139 | color='black', label='_nolegend_') 140 | ma20 = moving_average(prices, 20, type='simple') 141 | ma200 = moving_average(prices, 200, type='simple') 142 | 143 | linema20, = ax2.plot(r.index.values, ma20, color='blue', lw=2, label='MA (20)') 144 | linema200, = ax2.plot(r.index.values, ma200, color='red', lw=2, label='MA (200)') 145 | 146 | last = r.tail(1) 147 | s = '%s O:%1.2f H:%1.2f L:%1.2f C:%1.2f, V:%1.1fM Chg:%+1.2f' % ( 148 | last.index.strftime('%Y.%m.%d')[0], 149 | last.Open, last.High, 150 | last.Low, last.Close, 151 | last.Volume * 1e-6, 152 | last.Close - last.Open) 153 | t4 = ax2.text(0.3, 0.9, s, transform=ax2.transAxes, fontsize=textsize) 154 | 155 | props = font_manager.FontProperties(size=10) 156 | leg = ax2.legend(loc='center left', shadow=True, fancybox=True, prop=props) 157 | leg.get_frame().set_alpha(0.5) 158 | 159 | 160 | volume = (r.Close * r.Volume) / 1e6 # dollar volume in millions 161 | vmax = volume.max() 162 | poly = ax2t.fill_between(r.index, volume, 0, label='Volume', 163 | facecolor=fillcolor, edgecolor=fillcolor) 164 | ax2t.set_ylim(0, 5 * vmax) 165 | ax2t.set_yticks([]) 166 | 167 | 168 | # compute the MACD indicator 169 | fillcolor = 'darkslategrey' 170 | nslow = 26 171 | nfast = 12 172 | nema = 9 173 | emaslow, emafast, macd = moving_average_convergence( 174 | prices, nslow=nslow, nfast=nfast) 175 | ema9 = moving_average(macd, nema, type='exponential') 176 | ax3.plot(r.index.values, macd, color='black', lw=2) 177 | ax3.plot(r.index.values, ema9, color='blue', lw=1) 178 | ax3.fill_between(r.index, macd - ema9, 0, alpha=0.5, 179 | facecolor=fillcolor, edgecolor=fillcolor) 180 | 181 | 182 | ax3.text(0.025, 0.95, 'MACD (%d, %d, %d)' % (nfast, nslow, nema), va='top', 183 | transform=ax3.transAxes, fontsize=textsize) 184 | 185 | # ax3.set_yticks([]) 186 | # turn off upper axis tick labels, rotate the lower ones, etc 187 | for ax in ax1, ax2, ax2t, ax3: 188 | if ax != ax3: 189 | for label in ax.get_xticklabels(): 190 | label.set_visible(False) 191 | else: 192 | for label in ax.get_xticklabels(): 193 | label.set_rotation(30) 194 | label.set_horizontalalignment('right') 195 | 196 | ax.fmt_xdata = mdates.DateFormatter('%Y-%m-%d') 197 | 198 | 199 | class MyLocator(mticker.MaxNLocator): 200 | def __init__(self, *args, **kwargs): 201 | mticker.MaxNLocator.__init__(self, *args, **kwargs) 202 | 203 | def __call__(self, *args, **kwargs): 204 | return mticker.MaxNLocator.__call__(self, *args, **kwargs) 205 | 206 | # at most 5 ticks, pruning the upper and lower so they don't overlap 207 | # with other ticks 208 | # ax2.yaxis.set_major_locator(mticker.MaxNLocator(5, prune='both')) 209 | # ax3.yaxis.set_major_locator(mticker.MaxNLocator(5, prune='both')) 210 | 211 | 212 | ax2.yaxis.set_major_locator(MyLocator(5, prune='both')) 213 | ax3.yaxis.set_major_locator(MyLocator(5, prune='both')) 214 | 215 | buf = io.BytesIO() 216 | plt.savefig(buf) 217 | --------------------------------------------------------------------------------