WIP Adding Benchmarking Capability
This commit is contained in:
16
config.py
16
config.py
@@ -1,25 +1,27 @@
|
||||
### --------- PROGRAMM CONFIGUARTION
|
||||
|
||||
# Program Functionality Switch
|
||||
update_notion = True
|
||||
update_TRMNL = True
|
||||
calculate_benchmark = False
|
||||
|
||||
# Program Functionality Configuration
|
||||
programm_cooldown_time = 15 # Programm cooldown timer in minutes
|
||||
api_cooldowm_time = 0.1 # API cooldown timer in minutes
|
||||
trmnl_granularity = 70 # Days in between two data points in the TRMNL chart
|
||||
ticker_benchmark = "VGWL.DE" # Ticker to benchmark the trades against
|
||||
|
||||
### Logging
|
||||
# Programm Execution Configuration
|
||||
selected_logging_level = "warning" # must be one from the list below
|
||||
logging_levels = ("none", "error", "success", "warning", "info", "debug") # ordered by amount of logs
|
||||
|
||||
class log_colors:
|
||||
# Code for start of coloring (MUST match logging-levels above)
|
||||
error = '\033[91m'
|
||||
warning = '\033[93m'
|
||||
success = '\033[92m'
|
||||
info = '\033[90m'
|
||||
debug = '\033[4m'
|
||||
# Code for end of coloring
|
||||
endcode = '\033[0m'
|
||||
|
||||
# Fuctionality
|
||||
update_notion = True
|
||||
update_TRMNL = True
|
||||
|
||||
### --------- API CONFIGURATION
|
||||
# NOTION
|
||||
|
||||
22
functions.py
22
functions.py
@@ -146,6 +146,24 @@ def fetch_last_key_from_dict(dict):
|
||||
last_key = key_list[-1] # select the last entry from the list as it is the most current entry
|
||||
return last_key
|
||||
|
||||
# ADD BENCHMARK-TICKER TO TICKER-DICT
|
||||
def add_benchmark_ticker(tickers, ticker_benchmarkt):
|
||||
tickers.append(ticker_benchmarkt)
|
||||
logging(logging_level="success")
|
||||
|
||||
# CREATE BENCHMARK TRADES
|
||||
def create_benchmark_trades(trades):
|
||||
try:
|
||||
benchmark_trades = trades
|
||||
for trade_id in benchmark_trades:
|
||||
benchmark_trades[trade_id]['ticker'] = config.ticker_benchmark
|
||||
logging(logging_level="success")
|
||||
return benchmark_trades
|
||||
except Exception as error_message:
|
||||
logging(logging_level="error")
|
||||
logging(logging_level="error", message=f"Failed with error: {error_message}")
|
||||
return False
|
||||
|
||||
|
||||
|
||||
# -------------------------- #
|
||||
@@ -695,7 +713,7 @@ def calc_history_per_trade(trades, yf_data):
|
||||
return False
|
||||
|
||||
# CALC THE HISTORY PER TRADE & OVERALL
|
||||
def calc_history_per_ticker(history_per_trade, tickers, trades):
|
||||
def calc_history_per_ticker(history_per_trade, tickers):
|
||||
|
||||
# ------------------ CREATE JSON OBJECT
|
||||
# Create the json-dict
|
||||
@@ -812,8 +830,6 @@ def calc_history_per_ticker(history_per_trade, tickers, trades):
|
||||
logging(logging_level="error", message=f"Failed with error message: {error_message}")
|
||||
return False
|
||||
|
||||
|
||||
|
||||
# --------------------------- #
|
||||
# HISTORY SELECTION FUNCTIONS #
|
||||
# --------------------------- #
|
||||
|
||||
33
main.py
33
main.py
@@ -15,6 +15,13 @@ while True:
|
||||
print("Creating a list of unique tickers...", end=" ", flush=True)
|
||||
tickers = functions.filter_list_of_tickers(trades)
|
||||
|
||||
# Configuration dependent execution:
|
||||
if config.calculate_benchmark == True:
|
||||
|
||||
# Add the benchmark-ticker to the list of tickers to download data from yfinance from
|
||||
print("Adding benchmark-ticker...", end="", flush=True)
|
||||
tickers = functions.add_benchmark_ticker(tickers, config.ticker_benchmark)
|
||||
|
||||
# Fetches & formats the complete history per ticker from yfinance
|
||||
print("Fetching & formating yfinance data", end="", flush=True)
|
||||
yf_data = functions.fetch_format_yf_data(tickers)
|
||||
@@ -35,6 +42,28 @@ while True:
|
||||
functions.push_notion_trades_update(trades)
|
||||
|
||||
|
||||
|
||||
# ----------------------------------------- #
|
||||
# PART 2: Calculating Benchmark performance #
|
||||
# ----------------------------------------- #
|
||||
# Configuration dependent execution:
|
||||
if config.calculate_benchmark == True:
|
||||
|
||||
# Creating benchmark trades
|
||||
print("Creating 'benchmark trades'...", end="", flush=True)
|
||||
benchmark_trades = functions.create_benchmark_trades(trades)
|
||||
|
||||
# Calculating benchmark trades
|
||||
print("Calculating the history per benchmark-trade...", end=" ", flush=True)
|
||||
history_per_benchmark_trade = functions.calc_history_per_trade(benchmark_trades, yf_data)
|
||||
|
||||
###
|
||||
# ICH BIN MIR UNSICHER, WIE ICH HIERMIT WEITER MACHEN SOLL
|
||||
# ICH GLAUBE, ICH MUSS DIE HISTORY PER BENCHMARK-TICKER UND PER TICKER MERGEN
|
||||
# DANN HABE ICH ABER DAS PROBLEM, DASS ICH DIE ECHTEN TRADES NICHT VON DEN BENCHMARKS UNTERSCHEIDEN KANN
|
||||
###
|
||||
|
||||
|
||||
# ------------------------------------------------ #
|
||||
# PART 2: Updating the notion investments database #
|
||||
# ------------------------------------------------ #
|
||||
@@ -44,7 +73,7 @@ while True:
|
||||
|
||||
# Calculates & stores a history per ticker AND a total across all tickers indexed by the ticker name
|
||||
print("Calculating history per ticker...", end=" ", flush=True)
|
||||
history_per_ticker = functions.calc_history_per_ticker(history_per_trade, tickers, trades)
|
||||
history_per_ticker = functions.calc_history_per_ticker(history_per_trade, tickers)
|
||||
|
||||
# Configuration dependent execution:
|
||||
if config.update_notion == True:
|
||||
@@ -61,7 +90,6 @@ while True:
|
||||
# --------------------------------- #
|
||||
# PART 3: Updating the TRMNL Screen #
|
||||
# --------------------------------- #
|
||||
|
||||
# Configuration dependent execution:
|
||||
if config.update_TRMNL == True:
|
||||
|
||||
@@ -101,6 +129,7 @@ while True:
|
||||
print("Updating a TERMNL screen...", end=" ", flush=True)
|
||||
functions.push_trmnl_update_chart(trmnl_update_object, config.trmnl_url_chart_2, config.trmnl_headers)
|
||||
|
||||
|
||||
# --------------------------- #
|
||||
# PART 4: Cool off and repeat #
|
||||
# --------------------------- #
|
||||
|
||||
Reference in New Issue
Block a user