This file contains 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
#!/usr/bin/python | |
import json | |
import pandas as pd | |
import seaborn as sns | |
import python_bitbankcc | |
# Ticker information | |
def get_btc(obj): | |
ret = obj.get_ticker('btc_jpy') | |
return ret |
This file contains 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
# df copy | |
df_ = df.copy() | |
df_["ma25"] = df_.close.rolling(window=25).mean() | |
df_["ma75"] = df_.close.rolling(window=75).mean() | |
df_["diff"] = df_.ma25-df_.ma75 | |
df_["unixtime"] = [datetime.timestamp(t) for t in df.index] | |
# line and Moving Average | |
xdate = [x.date() for x in df_.index] | |
plt.figure(figsize=(15,5)) |
This file contains 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
def Bollinger(df, window=25): | |
df1 = df.copy() | |
df1["ma"] = df1.close.rolling(window=window).mean() | |
df1["sigma"] = df1.close.rolling(window=window).std() | |
df1["ma+2sigma"] = df1.ma + 2*df1.sigma | |
df1["ma-2sigma"] = df1.ma - 2*df1.sigma | |
df1["diffplus"] = df1.close - df1["ma+2sigma"] | |
df1["diffminus"] = df1["ma-2sigma"] - df1.close | |
s_up = df1[df1["diffplus"] > 0]["close"] | |
s_down = df1[df1["diffminus"] > 0]["close"] |
This file contains 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
def MACD(df): | |
df1 = df.copy() | |
df1["MACD"] = df1.close.ewm(span=12, min_periods=1).mean() - df1.close.ewm(span=26, min_periods=1).mean() | |
df1["signal"] = df1.MACD.ewm(span=9, min_periods=1).mean() | |
df1["macd_diff"] = df1["MACD"] - df1["signal"] | |
xdate = [x.date() for x in df1.index] | |
plt.figure(figsize=(15,10)) | |
# plot the original | |
plt.subplot(211) |
This file contains 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
def plot_RSI(df, window): | |
df1 = df.copy() | |
diff = df1.close.diff(periods=1).values | |
xdate = [x.date() for x in df1.index] | |
RSI = [] | |
for i in range(window+1, len(xdate)): | |
neg = 0 | |
pos = 0 | |
for value in diff[i-window:i+1]: | |
if value > 0: |
This file contains 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 pubnub.pubnub import PubNub | |
from pubnub.enums import PNStatusCategory | |
from pubnub.callbacks import SubscribeCallback | |
from pubnub.pnconfiguration import PNConfiguration | |
SUBSCRIBE_KEY = 'sub-c-e12e9174-dd60-11e6-806b-02ee2ddab7fe' | |
TICKER_CHANNEL = 'ticker_btc_jpy' | |
class BitbankSubscriberCallback(SubscribeCallback): | |
def presence(self, pubnub, presence): |
This file contains 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
def SMA_TaLib(df): | |
df1 = df.copy() | |
df1["ma5"] = talib.SMA(df1['close'], timeperiod=5) | |
df1["ma15"] = talib.SMA(df1['close'], timeperiod=15) | |
df1["diff"] = df1.ma5 - df1.ma15 | |
df1["unixtime"] = [datetime.timestamp(t) for t in df1.index] | |
# line and Moving Average | |
fig = plt.figure(figsize=(15,5)) | |
ax = fig.add_subplot(1, 1, 1) |
This file contains 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
# pct_change | |
f = lambda x: 1 if x>0.0001 else -1 if x<-0.0001 else 0 if -0.0001<=x<=0.0001 else np.nan | |
y = df.rename(columns={'close': 'y'}).loc[:, 'y'].pct_change(1).shift(-1).fillna(0) | |
X = df.copy() | |
y_ = pd.DataFrame(y.map(f), columns=['y']) | |
df_ = pd.concat([df, y_], axis=1) | |
# check the shape | |
print('----------------------------------------------------------------------------------------') | |
print('X shape: (%i,%i)' % X.shape) |
This file contains 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 sklearn.pipeline import Pipeline | |
from sklearn.preprocessing import StandardScaler | |
from sklearn.neighbors import KNeighborsClassifier | |
from sklearn.linear_model import LogisticRegression | |
from sklearn.ensemble import RandomForestClassifier, GradientBoostingClassifier | |
from sklearn.model_selection import train_test_split | |
from sklearn.metrics import accuracy_score, f1_score | |
X_train, X_test, y_train, y_test = train_test_split(X_, y_, test_size=0.33, random_state=42) | |
print('X_train shape: {}'.format(X_train.shape)) |
This file contains 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
pragma solidity ^0.4.23; | |
import "./CowBreeding.sol"; | |
import "openzeppelin-solidity/contracts/token/ERC721/ERC721.sol"; | |
/** | |
* @title ERC721 compatible Cow Standard Basic Implementation | |
* @dev Implements Cow transfer with inherited OpenZeppelin ERC721 | |
*/ | |
contract CowOwnership is CowBreeding, ERC721 { |