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
| def handle_data(context, data): | |
| RSI_periods = 14 | |
| context.i += 1 | |
| if context.i < RSI_periods: | |
| return | |
| RSI_data = data.history(context.asset, | |
| "price", |
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
| def initialize(context): | |
| context.asset = symbol("btc_usd") | |
| context.i = 0 | |
| context.base_price = None |
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 numpy as np | |
| import pandas as pd | |
| import matplotlib.pyplot as plt | |
| from logbook import Logger | |
| from math import floor, ceil | |
| from catalyst import run_algorithm | |
| from catalyst.api import order_target_percent, record, symbol | |
| from catalyst.exchange.utils.stats_utils import extract_transactions |
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
| new_prediction = regressor.predict(1.5) |
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
| # Visualizing the test set results | |
| plt.figure(figsize = (12, 6)) | |
| plt.scatter(X_test, y_test, alpha = 0.4, label = 'Observation Points') | |
| plt.plot(X_train, regressor.predict(X_train), color = 'green', lw = 0.7, alpha = 0.8, label = 'Best Fit Line') | |
| plt.title('Linear Regression (Test Set)') | |
| plt.xlabel('Years of Experience') | |
| plt.ylabel('Salary') | |
| plt.legend() |
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
| # Visualizing the training set results | |
| plt.figure(figsize = (12, 6)) | |
| plt.scatter(X_train, y_train, alpha = 0.4, label = 'Observation Points') | |
| plt.plot(X_train, regressor.predict(X_train), color = 'green', lw = 0.7, alpha = 0.8, label = 'Best Fit Line') | |
| plt.title('Linear Regression (Training Set)') | |
| plt.xlabel('Years of Experience') | |
| plt.ylabel('Salary') | |
| plt.legend() |
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 sklearn.linear_model import LinearRegression | |
| regressor = LinearRegression() | |
| regressor.fit(X_train, y_train) |
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
| # Creating the matrix of features and the vector of labels | |
| X = df.iloc[:, :-1].values | |
| y = df.iloc[:, 1].values |
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
| # Dividing data up into training sets and test sets | |
| from sklearn.model_selection import train_test_split | |
| X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 1/3) |
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
| Random starting synaptic weights: Synaptic weights after training: | |
| [-0.16595599] [ 9.67299303] | |
| [ 0.44064899] [-0.2078435 ] | |
| [-0.99977125] [-4.62963669] | |
| Output after training: | |
| [0.00966449] | |
| [0.99211957] |