Auto-fill routine scripts and add new scripts (#1889)

* Auto-fill routine scripts and add new scripts

* Get rid of 'routines' folder in all autocomplete statements

Co-authored-by: Theodore Aptekarev <aptekarev@gmail.com>
Co-authored-by: didierlopes.eth <dro.lopes@campus.fct.unl.pt>
This commit is contained in:
Jeroen Bouma
2022-06-02 16:57:22 +02:00
committed by GitHub
parent 3fdc1363d6
commit b976503860
11 changed files with 161 additions and 89 deletions

7
routines/README.md vendored
View File

@@ -4,5 +4,10 @@ This folder introduces the concept of routines, which are meant for the user to
Try out with:
```
python terminal.py routines/didier_gme_job.gst
python terminal.py routines/example.openbb
```
Or within the Terminal, use:
```
exe routines/example.openbb
```

View File

@@ -1,27 +1,20 @@
# Select location folder to export data to (if doesn't exist, will be created by default)
# export didier_analysis_on_$ARGV[0]
# Go into the stocks context
stocks
# Load a ticker that's given as a first argument of the routine
load WMT
load USB
# Go into the Comparison Analysis Menu
ca
# Get similar companies
getfinnhub
getfinviz
getpoly
set C,USB,WFC,JPM,TD,GS,PNC,TFC,BAC,COF
# Remove and add a ticker
rmv JCP
add SHOP
# Show the historical prices
historical -n
# Show a correlation matrix with different periods.
# Show a correlation matrix
hcorr
hcorr -s 2022-01-01
# Compare valuations
valuation
@@ -29,25 +22,8 @@ valuation
# Compare performance
performance
# Sentiment of companaies over the last ten days
sentiment
# Chart the NASDAQ 100 Index with futures contracts
..
..
stocks
ca
set ^NDX,NQH23.CME,NQZ22.CME,NQ=F
historical -s 2022-01-01
# Show the price-normalized history of S&P, NASDAQ, and Bitcoin futures
set ES=F,NQ=F,BTC=F
historical -n
# Compare financial statements of the ten largest US Banks
set C,USB,WFC,JPM,TD,GS,PNC,TFC,BAC,COF
# Show cashflows
cashflow
income
# Take the list of similar companies to the Portfolio Optimization Menu
po
# Return to home
/

View File

@@ -13,11 +13,6 @@ shorted
# Show the stocks with the highest short interest on https://highshortinterest.com
hsi
# Get the top five NMS and OTCE symbols with increasing dark pool volume from https://otctransparency.finra.org/otctransparency/AtsIssueData
prom -n 50 -l 5 -t T1
prom -n 50 -l 5 -t T2
prom -n 50 -l 5 -t OTCE
# Show the top 25 largest Dark Pool positions from https://stockgrid.io
pos -l 25
pos -l 25 -a
@@ -38,11 +33,8 @@ spos
# Price vs. Short Interest
psi
# Get two years of FTD data
ftd -s 2020-05-30
# Bar graph of Dark Pool and OTC volume
dpotc
# Export the Cost-to-Borrow list as a spreadsheet to examine.
ctb -n 6000 --export xlsx
ctb
# Return to home
/

View File

@@ -1,32 +0,0 @@
stocks
load gme -s 2021-01-01
candle -m
ba
headlines
bullbear
mentions
../dps/psi
../ins/stats
../gov/gtrades
../dd
analyst
rating
pt
sec
../ta
bbands
rsi
fib
../pred
mc
lstm -l 3 --epochs 20 -d 20
../options
exp 0
info
chains
parity
../qa
pick adjclose
bw
skew
cusum

16
routines/discovery_demo.openbb vendored Normal file
View File

@@ -0,0 +1,16 @@
# Enter the discovery menu
stocks/disc
# Show a dividend calendar
divcal -l 25
# Show Ark trades
arkord
# Show upcoming earnings
upcoming
# See news from Alpha Vantage
cnews -t issuance
# Return to home
/

View File

@@ -1,10 +1,27 @@
export example
# Go to the stocks menu
stocks
# Load Palantir Technologies (PLTR)
load pltr
# Enter the Due Dilligence (dd) menu
dd
# Show price targets, both the chart and the table
pt
rot
pt --raw
# Enter the Insider menu
../ins
# Show open insider filtered data for Palantir Technologies
stats
# Enter the Technical Analysis (ta) menu
../ta
fib
# Show the fibonacci retracement levels
fib
# Return to home
/

View File

@@ -1,7 +1,26 @@
# This script requires you to use arguments. This can be done with the following:
# exe routines/example_with_inputs.openbb -i TSLA,AAPL,MSFT
# Go to the stocks menu
stocks
# Load a ticker, given the argument used. E.g. -i TSLA
load $ARGV[0]
# Enter the Technical Analysis (ta) menu
ta
# Show the fibonacci retracement levels
fib
# Enter the comparison analysis (ca) menu
../ca
# Set two extra tickers based on the arguments used. E.g. -i TSLA,AAPL,MSFT
set $ARGV[1],$ARGV[2]
historical
# Plot the historical prices
historical
# Return to home
/

View File

@@ -1,3 +1,6 @@
# This script requires you to use an argument. This can be done with the following:
# exe routines/example_with_inputs_saved.openbb -i AMZN
# Select location folder to export data to (if doesn't exist, will be created by default)
export didier_analysis_on_$ARGV[0]
@@ -71,4 +74,7 @@ pt --export jpg
../ca/getfinnhub
# Compare their volume
volume --export jpg
volume --export jpg
# Return to home
/

View File

@@ -0,0 +1,26 @@
# Go to the Portfolio Optimization (po) menu
portfolio/po
# Load in an allocation sheet with all S&P 500 tickers
load SP_500_Portfolio.xlsx
# Load in a parameters file
file OpenBB_Parameters_Template_v1.0.0.xlsx
# Apply the Hierarchical Risk Parity (hrp) technique
hrp
# Show HRP results based on sector
show HRP_0 -ct SECTOR
# Plot the sector distribution
plot HRP_0 -ct SECTOR -pi
# Show a histogram of returns and drawdowns
plot HRP_0 -ct SECTOR -hi -dd
# Show assets clustermap and risk contribution
plot HRP_0 -ct SECTOR -rc -he
# Return to home
/

36
routines/stocks_demo.openbb vendored Normal file
View File

@@ -0,0 +1,36 @@
# Go into the stocks context
stocks
# Load a company ticker, e.g. Amazon
load AMZN
# Show a simple plot of the ticker, adding in any basic indicator.
candle --ma 20,30
# Switch over to the due diligence menu
dd
# Show the price targets of Amazon, both the graph as well as the table
pt
pt --raw
# Show estimates of annual and quarterly earnings as well as quarterly revenue estimates
est
# Open the comparison analysis menu (ca)
../ca
# Pick stocks that are competitors to Amazon
add ebay,wmt,tgt,baba,jd
# Determine the valuations of each company
valuation
# Show correlations between each company
hcorr
# Figure out the sentiment perceived of each company
sentiment
# Return to home
/

View File

@@ -7,6 +7,7 @@ import difflib
import logging
import os
import platform
import random
import sys
from typing import List
from pathlib import Path
@@ -19,7 +20,6 @@ from prompt_toolkit.formatted_text import HTML
from openbb_terminal.core.config.constants import REPO_DIR, ENV_FILE, USER_HOME
from openbb_terminal import feature_flags as obbff
from openbb_terminal.helper_funcs import (
check_path,
get_flair,
parse_known_args_and_warn,
)
@@ -72,6 +72,9 @@ class TerminalController(BaseController):
]
PATH = "/"
ROUTINE_CHOICES = {
file: None for file in os.listdir("routines") if file.endswith(".openbb")
}
def __init__(self, jobs_cmds: List[str] = None):
"""Constructor"""
@@ -80,6 +83,7 @@ class TerminalController(BaseController):
if session and obbff.USE_PROMPT_TOOLKIT:
choices: dict = {c: {} for c in self.controller_choices}
choices["support"] = self.SUPPORT_CHOICES
choices["exe"] = self.ROUTINE_CHOICES
self.completer = NestedCompleter.from_nested_dict(choices)
@@ -283,10 +287,9 @@ class TerminalController(BaseController):
parser_exe.add_argument(
"-p",
"--path",
help="The path or .gst file to run.",
help="The path or .openbb file to run.",
dest="path",
default="",
type=check_path,
required="-h" not in args,
)
parser_exe.add_argument(
@@ -295,14 +298,18 @@ class TerminalController(BaseController):
help="Select multiple inputs to be replaced in the routine and separated by commas. E.g. GME,AMC,BTC-USD",
dest="routine_args",
type=lambda s: [str(item) for item in s.split(",")],
default=None,
)
if args and "-" not in args[0][0]:
args.insert(0, "-p")
ns_parser_exe = parse_known_args_and_warn(parser_exe, args)
if ns_parser_exe:
if ns_parser_exe.path:
with open(ns_parser_exe.path) as fp:
if ns_parser_exe.path in self.ROUTINE_CHOICES:
path = f"routines/{ns_parser_exe.path}"
else:
path = ns_parser_exe.path
with open(path) as fp:
raw_lines = [
x for x in fp if (not is_reset(x)) and ("#" not in x) and x
]
@@ -313,7 +320,6 @@ class TerminalController(BaseController):
]
if ns_parser_exe.routine_args:
lines = list()
idx = 0
for rawline in raw_lines:
templine = rawline
for i, arg in enumerate(ns_parser_exe.routine_args):
@@ -442,13 +448,18 @@ def terminal(jobs_cmds: List[str] = None, appName: str = "gst"):
if session and obbff.USE_PROMPT_TOOLKIT:
try:
if obbff.TOOLBAR_HINT:
random_routine = [
file
for file in os.listdir("routines")
if file.endswith(".openbb")
]
an_input = session.prompt(
f"{get_flair()} / $ ",
completer=t_controller.completer,
search_ignore_case=True,
bottom_toolbar=HTML(
"Execute routine scripts to automate your research workflow. "
"E.g.: $ exe routines/example.openbb"
f"E.g.: $ exe {random_routine[random.randint(0, len(random_routine) - 1)]}"
),
style=Style.from_dict(
{