Commit 3bf550ac authored by Dr.李's avatar Dr.李

FEATURE: update examples

parent fdb2e572
"""
Created on 2020-11-21
@author: cheng.li
"""
import os
import datetime as dt
import numpy as np
import pandas as pd
from PyFin.api import *
from alphamind.api import *
start_date = '2020-01-01'
end_date = '2020-02-21'
freq = '10b'
horizon = map_freq(freq)
neutralized_risk = risk_styles + industry_styles
universe = Universe('hs300')
data_source = "mysql+mysqldb://reader:Reader#2020@121.37.138.1:13317/vision?charset=utf8"
offset = 1
method = 'ls'
industry_name = 'sw'
industry_level = 1
risk_model = 'short'
executor = NaiveExecutor()
ref_dates = makeSchedule(start_date, end_date, freq, 'china.sse')
engine = SqlEngine(data_source)
alpha_factors = {
'f01': LAST('EMA5D'),
'f02': LAST('EMV6D')
}
weights = dict(f01=1.0,
f02=1.0,
)
alpha_model = ConstLinearModel(features=alpha_factors, weights=weights)
def predict_worker(params):
data_meta = DataMeta(freq=freq,
universe=universe,
batch=1,
neutralized_risk=neutralized_risk,
risk_model='short',
pre_process=[winsorize_normal, standardize],
post_process=[standardize],
warm_start=0,
data_source=data_source)
ref_date, model = params
er, _ = predict_by_model(ref_date, model, data_meta)
return er
predicts = [predict_worker((d.strftime('%Y-%m-%d'), alpha_model)) for d in ref_dates]
...@@ -87,7 +87,7 @@ ...@@ -87,7 +87,7 @@
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"Wall time: 1.98 ms\n" "Wall time: 3.22 ms\n"
] ]
} }
], ],
...@@ -134,17 +134,17 @@ ...@@ -134,17 +134,17 @@
" warm start: on, polish: on, time_limit: off\n", " warm start: on, polish: on, time_limit: off\n",
"\n", "\n",
"iter objective pri res dua res rho time\n", "iter objective pri res dua res rho time\n",
" 1 -7.8878e+03 4.61e+00 6.68e+04 1.00e-01 1.10e-03s\n", " 1 -7.8878e+03 4.61e+00 6.68e+04 1.00e-01 1.28e-03s\n",
" 125 -2.4830e+02 3.58e-07 2.76e-05 5.82e-01 3.80e-03s\n", " 125 -2.4830e+02 3.58e-07 2.76e-05 5.82e-01 5.35e-03s\n",
"\n", "\n",
"status: solved\n", "status: solved\n",
"solution polish: unsuccessful\n", "solution polish: unsuccessful\n",
"number of iterations: 125\n", "number of iterations: 125\n",
"optimal objective: -248.2989\n", "optimal objective: -248.2989\n",
"run time: 4.54e-03s\n", "run time: 7.43e-03s\n",
"optimal rho estimate: 1.87e+00\n", "optimal rho estimate: 1.87e+00\n",
"\n", "\n",
"Wall time: 48 ms\n" "Wall time: 43 ms\n"
] ]
}, },
{ {
...@@ -211,9 +211,9 @@ ...@@ -211,9 +211,9 @@
"12 -2.483e+02 -2.483e+02 +3e-07 5e-13 2e-15 1e-10 8e-10 0.9775 1e-04 1 1 1 | 0 0\n", "12 -2.483e+02 -2.483e+02 +3e-07 5e-13 2e-15 1e-10 8e-10 0.9775 1e-04 1 1 1 | 0 0\n",
"\n", "\n",
"OPTIMAL (within feastol=5.3e-13, reltol=1.3e-09, abstol=3.2e-07).\n", "OPTIMAL (within feastol=5.3e-13, reltol=1.3e-09, abstol=3.2e-07).\n",
"Runtime: 0.013942 seconds.\n", "Runtime: 0.013621 seconds.\n",
"\n", "\n",
"Wall time: 51.3 ms\n" "Wall time: 52 ms\n"
] ]
}, },
{ {
...@@ -277,7 +277,7 @@ ...@@ -277,7 +277,7 @@
"12: -2.4829e+02 -2.4831e+02 1e-02 2e-16 4e-16\n", "12: -2.4829e+02 -2.4831e+02 1e-02 2e-16 4e-16\n",
"13: -2.4830e+02 -2.4830e+02 1e-04 2e-16 1e-15\n", "13: -2.4830e+02 -2.4830e+02 1e-04 2e-16 1e-15\n",
"Optimal solution found.\n", "Optimal solution found.\n",
"Wall time: 108 ms\n" "Wall time: 80.5 ms\n"
] ]
} }
], ],
...@@ -315,7 +315,7 @@ ...@@ -315,7 +315,7 @@
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"Wall time: 24 ms\n" "Wall time: 20.6 ms\n"
] ]
}, },
{ {
...@@ -465,9 +465,9 @@ ...@@ -465,9 +465,9 @@
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"Scale(n) cvxpy cvxopt ipopt\n", "Scale(n) cvxpy cvxopt ipopt\n",
"100 0.0527 0.0660 0.0142\n", "100 0.0520 0.0440 0.0070\n",
"200 0.0710 0.3040 0.0601\n", "200 0.0413 0.0520 0.0120\n",
"300 0.1614 0.0690 0.0155\n" "300 0.0420 0.0630 0.0170\n"
] ]
} }
], ],
......
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