代码拉取完成,页面将自动刷新
from cvxpy.reductions.solvers import solver
from fundopt.fundopt import FundTargetRetMinCVaROptimiser, FundTargetRetMinVarianceOptimiser
import pandas as pd
import numpy as np
import datetime as dt
import logging
import cvxpy as cvx
if __name__ == "__main__":
logging.basicConfig( level = logging.INFO )
start = dt.date(2020, 1, 1)
end = dt.date(2021, 5, 28)
holding = 20
fund_returns = pd.read_pickle('./{}_{}_{}.pkl'.format(start, end, holding))
fund_returns.drop(['003064'], axis=1, inplace=True)
lookback = pd.bdate_range('2020-11-28', '2021-05-28')
print( f"Look back period from {lookback.min()} to {lookback.max()}" )
print( "Top 5 high return funds:")
print( fund_returns.reindex(lookback).fillna(0.0).mean(axis=0).sort_values(ascending=False).head() )
opt = FundTargetRetMinCVaROptimiser(
targetRet=0.05,
returns=fund_returns)
current=pd.Series(dtype=float)
current['163406'] = 117108.0
current['020005'] = 44499.0
solver_options = {
'verbose' : True,
'solver' : cvx.ECOS,
}
opt.getOptimalPosition(current, lookbackPeriod=lookback, solver_options=solver_options)
print(opt.targetRet.value, opt.cvxProblem.value)
# for target_ret in [0.055, 0.05, 0.04, 0.03, 0.02, 0.01]:
# opt.set_target_ret_and_rerun(target_ret, solver_options)
# print(opt.targetRet.value, opt.cvxProblem.value)
# final = current.add(opt_trade, fill_value=0.0)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。