1 Star 0 Fork 0

yutiansut/FundOptimizer

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.py 1.46 KB
一键复制 编辑 原始数据 按行查看 历史
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)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yutiansut/FundOptimizer.git
[email protected]:yutiansut/FundOptimizer.git
yutiansut
FundOptimizer
FundOptimizer
master

搜索帮助