Skip to content

Instantly share code, notes, and snippets.

View ProAek11's full-sized avatar

Yuttakan Sangchai ProAek11

  • AI-Frendersis - Strategy Trading
  • Thailand
  • 21:13 (UTC +07:00)
View GitHub Profile
"""
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"
def mean_confidence_interval(vals, confidence):
a = 1.0 * np.array(vals)
n = len(a)
m, se = np.mean(a), scipy.stats.sem(a)
h = se * scipy.stats.t.ppf((1 + confidence) / 2., n-1)
return m - h, m, m + h
def compare_hidden_states(hmm_model, cols_features, conf_interval, iters = 1000):
plt.figure(figsize=(15, 15))
fig, axs = plt.subplots(len(cols_features), hmm_model.n_components, figsize = (15, 15))
# 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):
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)
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
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):