This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| 2 Pre-Requisites - install the package, and get an OpenAI API key | |
| pip install openai | |
| """ | |
| #import the package and add your key | |
| import openai | |
| openai.api_key = "YOUR_API_KEY_HERE" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Normalized st. deviation | |
| def std_normalized(vals): | |
| return np.std(vals) / np.mean(vals) | |
| # Ratio of diff between last price and mean value to last price | |
| def ma_ratio(vals): | |
| return (vals[-1] - np.mean(vals)) / vals[-1] | |
| # z-score for volumes and price | |
| def values_deviation(vals): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| start_date_string = '2014-04-01' | |
| asset = 'BITFINEX/BTCUSD' | |
| column_price = 'Last' | |
| column_high = 'High' | |
| column_low = 'Low' | |
| column_volume = 'Volume' | |
| quandl.ApiConfig.api_key = YOUR_QUANDL_API | |
| dataset = quandl.get(asset, collapse = 'daily', | |
| trim_start = start_date_string) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import quandl | |
| import numpy as np | |
| import pandas as pd | |
| import statsmodels.api as sm | |
| from scipy import stats | |
| from matplotlib import cm, pyplot as plt | |
| from hmmlearn.hmm import GaussianHMM | |
| import scipy | |
| import datetime | |
| import json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from matplotlib import pyplot | |
| import pandas as pd | |
| from IPython.core.display import display, HTML | |
| display(HTML("<style>.container { width:90% !important; }</style>")) | |
| pd.options.display.max_columns = 999 | |
| pd.options.display.max_rows = 999 | |
| # function สำหรับ preprocess ข้อมูล time series หลายตัวแปร | |
| def series_to_supervised(data, n_in=1, n_out=1, dropnan=True,feat_name=None): | |