mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-28 21:12:16 +00:00
merge main + small changes
This commit is contained in:
@@ -63,7 +63,7 @@ def k_nearest_neighbors(other_args: List[str], s_ticker: str, df_stock: pd.DataF
|
||||
dest="n_inputs",
|
||||
type=check_positive,
|
||||
default=40,
|
||||
help="number of days to use for prediction.",
|
||||
help="number of days to use as input for prediction.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-d",
|
||||
@@ -99,7 +99,16 @@ def k_nearest_neighbors(other_args: List[str], s_ticker: str, df_stock: pd.DataF
|
||||
type=valid_date,
|
||||
dest="s_end_date",
|
||||
default=None,
|
||||
help="The end date (format YYYY-MM-DD) to select - Backtesting",
|
||||
help="The end date (format YYYY-MM-DD) to select for testing",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-t",
|
||||
"--test_size",
|
||||
default = .2,
|
||||
dest="test_size",
|
||||
type = float,
|
||||
help = "Percentage of data to validate in sample"
|
||||
)
|
||||
|
||||
try:
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
"""Helper functions"""
|
||||
__docformat__ = "numpy"
|
||||
from typing import List, Tuple
|
||||
from datetime import datetime
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
from matplotlib import pyplot as plt
|
||||
from gamestonk_terminal.helper_funcs import (
|
||||
get_next_stock_market_days,
|
||||
patch_pandas_text_adjustment,
|
||||
plot_autoscale,
|
||||
)
|
||||
@@ -26,10 +26,12 @@ from gamestonk_terminal.config_plot import PLOT_DPI
|
||||
register_matplotlib_converters()
|
||||
|
||||
|
||||
def prepare_test_train_valid(
|
||||
def prepare_train_valid_test(
|
||||
df_stock, parsed_end_date, n_input_days, n_predict_days, test_size
|
||||
):
|
||||
|
||||
df_test = df_stock[df_stock.index >= parsed_end_date]
|
||||
df_stock = df_stock[df_stock.index < parsed_end_date]
|
||||
dates = df_stock.index
|
||||
prices = df_stock["5. adjusted close"].values
|
||||
|
||||
@@ -38,7 +40,12 @@ def prepare_test_train_valid(
|
||||
next_n_day_prices = []
|
||||
next_n_day_dates = []
|
||||
|
||||
test_days = []
|
||||
test_inputs = []
|
||||
test_next_n_days = []
|
||||
|
||||
for idx in range(len(prices) - n_input_days - n_predict_days):
|
||||
|
||||
input_prices.append(prices[idx : idx + n_input_days])
|
||||
input_dates.append(dates[idx : idx + n_input_days])
|
||||
next_n_day_prices.append(
|
||||
@@ -55,13 +62,13 @@ def prepare_test_train_valid(
|
||||
|
||||
(
|
||||
X_train,
|
||||
X_test,
|
||||
X_valid,
|
||||
y_train,
|
||||
y_test,
|
||||
y_valid,
|
||||
X_dates_train,
|
||||
X_dates_test,
|
||||
X_dates_valid,
|
||||
y_dates_train,
|
||||
y_dates_test,
|
||||
y_dates_valid,
|
||||
) = train_test_split(
|
||||
input_prices,
|
||||
next_n_day_prices,
|
||||
@@ -69,6 +76,16 @@ def prepare_test_train_valid(
|
||||
next_n_day_dates,
|
||||
test_size=test_size,
|
||||
)
|
||||
return (
|
||||
X_train,
|
||||
X_valid,
|
||||
y_train,
|
||||
y_valid,
|
||||
X_dates_train,
|
||||
X_dates_valid,
|
||||
y_dates_train,
|
||||
y_dates_valid,
|
||||
)
|
||||
|
||||
|
||||
def get_backtesting_data(
|
||||
|
||||
Reference in New Issue
Block a user