forked from lab/TPM
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.5 KiB
52 lines
1.5 KiB
import os |
|
import time |
|
from datetime import datetime, date, timedelta |
|
from urllib.parse import urlparse |
|
|
|
# PARAMETERS |
|
CONFIGS = { |
|
"SECRET_KEY": os.environ.get("SECRET_KEY", os.urandom(30).hex()), # Set the secret key for session authentication |
|
"PERMANENT_SESSION_LIFETIME": timedelta(minutes=60) |
|
} |
|
|
|
# PostgreSQL config - support both Railway and local Docker |
|
DATABASE_URL = os.environ.get('DATABASE_URL') |
|
if DATABASE_URL: |
|
# Railway provides DATABASE_URL |
|
url = urlparse(DATABASE_URL) |
|
SQL_CONFIG = dict( |
|
database=url.path[1:], |
|
user=url.username, |
|
host=url.hostname, |
|
port=url.port or 5432, |
|
password=url.password |
|
) |
|
else: |
|
# Local Docker fallback |
|
SQL_CONFIG = dict( |
|
database="portfolio_platform", |
|
user="postgres", |
|
host="db", |
|
port="5432", |
|
password="thiispassword1qaz!QAZ" |
|
) |
|
|
|
# Redis config - support both Railway and local Docker |
|
REDIS_URL = os.environ.get('REDIS_URL') |
|
if REDIS_URL: |
|
# Railway provides REDIS_URL |
|
CACHE_CONFIG = { |
|
'CACHE_TYPE': 'redis', |
|
'CACHE_REDIS_URL': REDIS_URL, |
|
} |
|
else: |
|
# Local Docker fallback |
|
CACHE_CONFIG = { |
|
'CACHE_TYPE': 'redis', |
|
'CACHE_REDIS_HOST': 'redis', |
|
'CACHE_REDIS_PORT': 6379, |
|
} |
|
role_map = dict(max_sharpe='最大化夏普比率', |
|
max_sortino='最大化索提諾比率', |
|
min_volatility='最小化波動率', |
|
quadratic_utility='最大化效用函數')
|
|
|