mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-27 03:33:24 +00:00
Small bugs (#534)
This commit is contained in:
@@ -7,6 +7,8 @@ from typing import Union
|
||||
from matplotlib import pyplot as plt
|
||||
from pandas.plotting import register_matplotlib_converters
|
||||
import bt
|
||||
import yfinance as yf
|
||||
import pandas as pd
|
||||
from gamestonk_terminal.helper_funcs import plot_autoscale
|
||||
from gamestonk_terminal.config_plot import PLOT_DPI
|
||||
from gamestonk_terminal import feature_flags as gtff
|
||||
@@ -14,7 +16,28 @@ from gamestonk_terminal import feature_flags as gtff
|
||||
register_matplotlib_converters()
|
||||
|
||||
|
||||
def buy_and_hold(ticker: str, start: Union[str, datetime], name: str):
|
||||
def get_data(ticker: str, start_date: Union[str, datetime]):
|
||||
"""
|
||||
Function to replace bt.get, Gets Adjusted close of ticker
|
||||
Parameters
|
||||
----------
|
||||
ticker: str
|
||||
Ticker to get data for
|
||||
start_date:
|
||||
Start date
|
||||
|
||||
Returns
|
||||
-------
|
||||
prices: pd.DataFrame
|
||||
Dataframe of Adj Close with columns = [ticker]
|
||||
"""
|
||||
prices = yf.download(ticker, start=start_date, progress=False)
|
||||
prices = pd.DataFrame(prices["Adj Close"])
|
||||
prices.columns = [ticker]
|
||||
return prices
|
||||
|
||||
|
||||
def buy_and_hold(ticker: str, start_date: Union[str, datetime], name: str):
|
||||
"""
|
||||
Generates a backtest object for the given ticker
|
||||
Parameters
|
||||
@@ -30,7 +53,8 @@ def buy_and_hold(ticker: str, start: Union[str, datetime], name: str):
|
||||
-------
|
||||
bt.Backtest object for buy and hold strategy
|
||||
"""
|
||||
prices = bt.get(ticker, start=start)
|
||||
# prices = bt.get(ticker, start=start)
|
||||
prices = get_data(ticker, start_date)
|
||||
bt_strategy = bt.Strategy(
|
||||
name,
|
||||
[
|
||||
|
||||
@@ -3,11 +3,14 @@ __docformat__ = "numpy"
|
||||
import argparse
|
||||
from typing import List, Union
|
||||
from datetime import datetime
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
import bt
|
||||
import pandas_ta as ta
|
||||
from gamestonk_terminal.helper_funcs import parse_known_args_and_warn
|
||||
from gamestonk_terminal.backtesting.bt_helper import buy_and_hold, plot_bt
|
||||
from gamestonk_terminal.backtesting.bt_helper import buy_and_hold, plot_bt, get_data
|
||||
|
||||
np.seterr(divide="ignore")
|
||||
|
||||
|
||||
def simple_ema(ticker: str, start_date: Union[str, datetime], other_args: List[str]):
|
||||
@@ -53,7 +56,9 @@ def simple_ema(ticker: str, start_date: Union[str, datetime], other_args: List[s
|
||||
return
|
||||
ticker = ticker.lower()
|
||||
ema = pd.DataFrame()
|
||||
prices = bt.get(ticker, start=start_date)
|
||||
# prices = bt.get(ticker, start=start_date)
|
||||
# bt.get not working
|
||||
prices = get_data(ticker, start_date)
|
||||
ema[ticker] = ta.ema(prices[ticker], ns_parser.length)
|
||||
bt_strategy = bt.Strategy(
|
||||
"AboveEMA",
|
||||
@@ -145,7 +150,8 @@ def ema_cross(ticker: str, start_date: Union[str, datetime], other_args: List[st
|
||||
print("Short EMA period is longer than Long EMA period\n")
|
||||
return
|
||||
ticker = ticker.lower()
|
||||
prices = bt.get(ticker, start=start_date)
|
||||
# prices = bt.get(ticker, start=start_date)
|
||||
prices = get_data(ticker, start_date)
|
||||
short_ema = pd.DataFrame(ta.ema(prices[ticker], ns_parser.short))
|
||||
short_ema.columns = [ticker]
|
||||
long_ema = pd.DataFrame(ta.ema(prices[ticker], ns_parser.long))
|
||||
@@ -257,8 +263,8 @@ def rsi_strat(ticker: str, start_date: Union[datetime, str], other_args: List[st
|
||||
print("Low RSI value is higher than Low RSI value\n")
|
||||
return
|
||||
ticker = ticker.lower()
|
||||
prices = bt.get(ticker, start=start_date)
|
||||
|
||||
# prices = bt.get(ticker, start=start_date)
|
||||
prices = get_data(ticker, start_date)
|
||||
rsi = pd.DataFrame(ta.rsi(prices[ticker], ns_parser.periods))
|
||||
rsi.columns = [ticker]
|
||||
|
||||
@@ -294,6 +300,5 @@ def rsi_strat(ticker: str, start_date: Union[datetime, str], other_args: List[st
|
||||
print("")
|
||||
|
||||
except Exception as e:
|
||||
print(e)
|
||||
print("")
|
||||
print(e, "\n")
|
||||
return
|
||||
|
||||
@@ -81,7 +81,7 @@ usage: compare [-n --names]
|
||||
```
|
||||
* -n/--names : ETFs to compare. Input as comma separated (ETF1,ETF2,..)
|
||||
|
||||
Campares the overview of different ETFs. Unknown tickers show nan
|
||||
Campares the overview of different ETFs.
|
||||
|
||||
Example:
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ packages = [
|
||||
]
|
||||
|
||||
[tool.poetry.scripts]
|
||||
gst = 'terminal:main'
|
||||
gst = 'terminal:terminal'
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.6.8"
|
||||
|
||||
Reference in New Issue
Block a user