├── .gitignore ├── .vscode └── settings.json ├── CUSUMDECT ├── CUSUMDECT.py └── bar5rb8888.csv ├── GeneticOptimizeforVNPYStrategy ├── .idea │ ├── GeneticOptimizeforVNPYStrategy.iml │ ├── encodings.xml │ ├── misc.xml │ ├── modules.xml │ ├── vcs.xml │ └── workspace.xml ├── .vscode │ └── settings.json ├── GeneticOptimize.py ├── GeneticOptimizev2.py ├── GeneticTrain.py ├── Knapsack.py ├── MultiTest.py ├── checkMutiple.py └── file.txt ├── JDDataService ├── JQDataload.py └── config.json ├── LSMT ├── .vscode │ ├── launch.json │ └── settings.json ├── LSTM.py └── Stat1.py ├── MarketDataAnalyzer.py ├── PSOOptimize └── PSOOptimize.py ├── README.md ├── Risk and Portfolio Knowledge Sharing ├── Basic and VaR.ipynb ├── README.md ├── RiskandPortfolio.pdf └── Untitled.ipynb ├── TestData └── rb1910.csv └── TraderbySklearn └── AnalyzebySklearn.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | MANIFEST 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | .pytest_cache/ 49 | 50 | # Translations 51 | *.mo 52 | *.pot 53 | 54 | # Django stuff: 55 | *.log 56 | local_settings.py 57 | db.sqlite3 58 | 59 | # Flask stuff: 60 | instance/ 61 | .webassets-cache 62 | 63 | # Scrapy stuff: 64 | .scrapy 65 | 66 | # Sphinx documentation 67 | docs/_build/ 68 | 69 | # PyBuilder 70 | target/ 71 | 72 | # Jupyter Notebook 73 | .ipynb_checkpoints 74 | 75 | # pyenv 76 | .python-version 77 | 78 | # celery beat schedule file 79 | celerybeat-schedule 80 | 81 | # SageMath parsed files 82 | *.sage.py 83 | 84 | # Environments 85 | .env 86 | .venv 87 | env/ 88 | venv/ 89 | ENV/ 90 | env.bak/ 91 | venv.bak/ 92 | 93 | # Spyder project settings 94 | .spyderproject 95 | .spyproject 96 | 97 | # Rope project settings 98 | .ropeproject 99 | 100 | # mkdocs documentation 101 | /site 102 | 103 | # mypy 104 | .mypy_cache/ 105 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "python.pythonPath": "C:\\Anaconda2\\python.exe", 3 | "python.linting.pylintEnabled": false, 4 | "python.linting.enabled": true, 5 | "python.linting.flake8Enabled": false, 6 | "python.linting.banditEnabled": true, 7 | "python.formatting.provider": "black" 8 | } -------------------------------------------------------------------------------- /CUSUMDECT/CUSUMDECT.py: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | import numpy as np 4 | import pandas as pd 5 | import matplotlib.pyplot as plt 6 | import talib 7 | 8 | 9 | 10 | def detect_via_cusum_lg(ts, istart=30, threshold_times=5): 11 | """ 12 | detect a time series using cusum algorithm 13 | :param ts: the time series to be detected 14 | :param istart: the data from index 0 to index istart will be used as cold startup data to train 15 | :param threshold_times: the times for setting threshold 16 | :return: 17 | """ 18 | 19 | S_h = 0 20 | S_l = 0 21 | S_list = np.zeros(istart) 22 | 23 | meanArray = talib.SMA(ts,timeperiod = istart) 24 | stdArray = talib.STDDEV(np.log(ts/meanArray),timeperiod = istart) 25 | for i in range(istart+1, len(ts)-1): 26 | tslog = np.log(ts[i] / meanArray[i - 1]) 27 | 28 | S_h_ = max(0, S_h + tslog - stdArray[i-1]) 29 | S_l_ = min(0, S_l + tslog + stdArray[i-1]) 30 | 31 | if S_h_> threshold_times * stdArray[i-1]: 32 | S_list = np.append(S_list,1) 33 | S_h_ = 0 34 | elif abs(S_l_)> threshold_times * stdArray[i-1]: 35 | S_list = np.append(S_list, -1) 36 | S_l_ = 0 37 | else: 38 | S_list = np.append(S_list, 0) 39 | S_h = S_h_ 40 | S_l = S_l_ 41 | return S_list 42 | 43 | 44 | #数据导入 45 | df5min = pd.read_csv("bar5rb8888.csv") 46 | dt0 = np.array(df5min["close"]) 47 | 48 | listup,listdown = [],[] 49 | s_list = detect_via_cusum_lg(dt0,istart=30, threshold_times=5) 50 | for i in range(0,len(s_list)): 51 | if s_list[i] == 1: 52 | listup.append(i) 53 | elif s_list[i] == -1 : 54 | listdown.append(i) 55 | 56 | 57 | plt.subplot(2,1,1) 58 | plt.plot(dt0, color='y', lw=2.) 59 | plt.plot(dt0, '^', markersize=5, color='r', label='UP signal', markevery=listup) 60 | plt.plot(dt0, 'v', markersize=5, color='g', label='DOWN signal', markevery=listdown) 61 | plt.legend() 62 | plt.subplot(2,1,2) 63 | plt.title('s_list') 64 | plt.plot(s_list,'r-') 65 | 66 | plt.show() 67 | -------------------------------------------------------------------------------- /GeneticOptimizeforVNPYStrategy/.idea/GeneticOptimizeforVNPYStrategy.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 12 | -------------------------------------------------------------------------------- /GeneticOptimizeforVNPYStrategy/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /GeneticOptimizeforVNPYStrategy/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /GeneticOptimizeforVNPYStrategy/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /GeneticOptimizeforVNPYStrategy/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /GeneticOptimizeforVNPYStrategy/.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 93 | 94 | 95 | 96 | creator 97 | parameterlist 98 | evaluate 99 | object_func 100 | mid 101 | 102 | 103 | 104 | 106 | 107 | 120 | 121 | 122 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 |