Commit c25eaf4a authored by Dr.李's avatar Dr.李

fixed linear builder when bm sum not to 1

parent 4ffafbb4
# -*- coding: utf-8 -*-
"""
Created on 2017-5-17
@author: cheng.li
"""
# -*- coding: utf-8 -*-
"""
Created on 2017-5-18
@author: cheng.li
"""
import pandas as pd
def calculate_turn_over(pos_table):
turn_over_table = {}
total_factors = pos_table.columns.difference(['Code'])
pos_table.reset_index()
for name in total_factors:
pivot_position = pos_table.pivot(values=name, columns='Code').fillna(0.)
turn_over_series = pivot_position.diff().abs().sum(axis=1)
turn_over_table[name] = turn_over_series.values
turn_over_table = pd.DataFrame(turn_over_table, index=pos_table.Date.unique())
return turn_over_table[total_factors]
......@@ -82,7 +82,7 @@ else:
'industry': total_data['申万一级行业'].values,
'zz500': total_data[index_components].values}, index=total_data.Code)
portfolio.to_csv(r'\\10.63.6.71\sharespace\personal\licheng\portfolio\{0}.csv'.format(ref_date))
portfolio.to_csv(r'\\10.63.6.71\sharespace\personal\licheng\portfolio\zz500\{0}.csv'.format(ref_date))
......
......@@ -34,13 +34,13 @@ def linear_build(er: np.ndarray,
constraints = [w >= lbound,
w <= ubound,
curr_risk_exposure == risk_eq_target,
cvxpy.sum_entries(w) == 1.]
cvxpy.sum_entries(w) == bm.sum()]
else:
constraints = [w >= lbound,
w <= ubound,
curr_risk_exposure >= risk_target[0] * np.abs(risk_exposure.T @ bm),
curr_risk_exposure <= risk_target[1] * np.abs(risk_exposure.T @ bm),
cvxpy.sum_entries(w) == 1.]
cvxpy.sum_entries(w) == bm.sum()]
if exchange_flag is not None:
constraints.append(exchange_flag @ w <= exchange_limit[1])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment