import sys
sys.path.insert(0, "../")
%load_ext autoreload
%autoreload 2
import numpy as np
from matplotlib import pyplot as plt
import seaborn as sns
%matplotlib notebook
import xalpha as xa
xa.set_backend(backend="csv", path="../data", precached="20170103")
from lof.predict import estimate_table , analyse_all, estimate_table_with_pos
from lof.holdings import holdings
nfyy = \
estimate_table("20190101", "20200305", ("real", {"F501018": 100}), ("est", holdings["501018"]))
analyse_all(nfyy, "diff_real_est")
净值预测回测分析: 平均偏离: 0.13174461054574946 标准差偏离: 0.1932435798187427 预测偏差分位: 1% 分位: -0.684 5% 分位: -0.288 25% 分位: -0.089 50% 分位: 0.001 75% 分位: 0.083 95% 分位: 0.292 99% 分位: 0.389 涨跌偏差分析: 预测涨的比实际少: 0.34 预测涨的比实际多: 0.22 预测跌的比实际多: 0.17 预测跌的比实际少: 0.28
sns.distplot(list(nfyy["diff_real_est"]))
<matplotlib.axes._subplots.AxesSubplot at 0x1221e5400>
nfyy = \
estimate_table("20190101", "20200305", ("real", {"F501018": 100}), ("est", holdings["501018"]),
float_holdings=True, window=4, decay=0.65, smooth=0.2)
20190103 93.65447840120115 20190104 93.76823121561948 20190107 94.05076945846218 20190108 94.53989917677045 20190109 94.11820866519953 20190110 94.64001499429096 20190111 95.01318002397532 20190114 95.25781689416775 20190115 95.37636538508443 20190116 95.89909419328484 20190117 96.16955163653688 20190118 96.78493705275066 20190121 95.53522415568376 20190122 97.60285032195961 20190123 97.48150922483097 20190124 97.95451655511893 20190125 95.19108172819183 20190128 94.92971071063164 20190129 99.23867589460771 20190130 99.99999999999999 20190131 98.05699339075981 20190201 98.09306296337613 20190211 99.43323887302371 20190212 98.79898994873756 20190213 100.0 20190214 99.88131044941427 20190215 97.54548021289017 20190218 96.81871135841469 20190219 96.85780233934933 20190220 96.18607396169415 20190221 95.20892124329548 20190222 98.04444503632847 20190225 98.82618970060442 20190226 99.74365338954891 20190227 99.88341766288124 20190228 97.79486699295909 20190301 97.9267567344947 20190304 97.22425910330642 20190305 95.910365587022 20190306 99.677261324912 20190307 99.70610533639068 20190308 99.73006234036976 20190311 98.48235023896858 20190312 97.17880132302501 20190313 97.24206087176712 20190314 97.55092228258414 20190315 96.9968877421884 20190318 97.2642396934006 20190319 95.76353792613384 20190320 95.03649155186946 20190321 99.28667723693033 20190322 100.0 20190325 97.26758745518102 20190326 97.22956716530584 20190327 98.25122281496479 20190328 97.69119912494916 20190329 98.24944018530445 20190401 97.2655757717525 20190402 94.92986604939438 20190403 96.97053718680385 20190404 97.29466665083085 20190408 96.56394659904025 20190409 95.12076266114163 20190410 99.54866286929146 20190411 97.34492825871405 20190412 97.05319234562067 20190415 97.08903536812161 20190416 99.66931470619767 20190417 97.09807906328555 20190418 97.3674593564218 20190419 97.75067893718972 20190422 96.31677770505277 20190423 99.7456463679329 20190424 97.29559820684318 20190425 97.34794273496203 20190426 96.56678467597736 20190429 98.18792380617393 20190430 96.98676331581645 20190506 96.97707912513957 20190507 97.45493167445436 20190508 97.34696862103556 20190509 97.77563019023681 20190510 97.04496011674127 20190513 98.02975261251883 20190514 97.82441459690898 20190515 98.21099449242307 20190516 99.29871656216373 20190517 97.06110455867623 20190520 96.81916834152487 20190521 96.64960751612622 20190522 96.69020279852819 20190523 98.31308768611812 20190524 97.38832881255135 20190527 97.86828259790853 20190528 96.5912768154747 20190529 96.89881578774067 20190530 96.02619248542368 20190531 94.94339208437005 20190603 95.50038724369004 20190604 95.54016086505129 20190605 94.92232794114467 20190606 94.60054685289953 20190610 95.09069980155203 20190611 94.64074509798412 20190612 93.92377156151373 20190613 92.36677989687628 20190614 90.35476304146071 20190617 92.80031961840648 20190618 91.57712120181685 20190619 88.73651192026911 20190620 90.6266989984932 20190621 90.94905787491375 20190624 86.8984549750862 20190625 89.13707760107751 20190626 88.19573473409837 20190627 86.193553807514 20190628 87.31761706781599 20190701 88.7126826435418 20190702 86.99455046722262 20190703 91.61360179373837 20190704 91.20687271101387 20190705 89.88506640021727 20190708 89.49018822907516 20190709 90.5829462453055 20190710 91.45145770069323 20190711 91.76566273402348 20190712 93.01815381346235 20190715 92.0529107534956 20190716 92.39395313070543 20190717 95.4927001778484 20190718 95.72099521157816 20190719 94.37243547210491 20190722 93.37631319903207 20190723 94.29359518960005 20190724 94.40723944875124 20190725 93.2401060718849 20190726 94.97339927669387 20190729 95.67755132643181 20190730 96.95019995381554 20190731 95.64545374205018 20190801 97.47337469256973 20190802 95.34874853711882 20190805 92.46198670127994 20190806 93.6892092718156 20190807 90.96927337234254 20190808 92.597958601564 20190809 94.5280349695812 20190812 93.95185998709634 20190813 94.372670876075 20190814 95.56542205334783 20190815 95.4689973624791 20190816 94.37564982805695 20190819 94.37473776832783 20190820 92.57042893710461 20190821 93.92451406638433 20190822 94.1518889901149 20190823 93.54810925839877 20190826 92.3462625679791 20190827 96.1781884803884 20190828 94.29082369861767 20190829 92.0820053904515 20190830 96.73283452097574 20190902 95.84689202758707 20190903 96.6585506750083 20190904 94.53016196357505 20190905 95.06086545976878 20190906 95.63934716699639 20190909 93.9185564684255 20190910 91.33369685645081 20190911 92.04587774349261 20190912 92.29873488458942 20190916 89.8062935972953 20190917 92.84202798415694 20190918 92.43462942072114 20190919 92.65539111715827 20190920 92.0030470546091 20190923 91.99574275659674 20190924 91.30980344265903 20190925 90.31933336019264 20190926 91.6965813233175 20190927 93.77747478219858 20190930 93.93861267813871 20191008 95.05851983054474 20191009 95.55991963262576 20191010 94.70424775458869 20191011 94.6969707103485 20191014 94.29658193425988 20191015 96.6062426617909 20191016 94.43332767890877 20191017 97.1792516244434 20191018 98.12971030563334 20191021 97.23484104484713 20191022 95.78929298734353 20191023 93.06633431698712 20191024 95.55803640601529 20191025 96.11727742428688 20191028 96.97345160533871 20191029 95.1065951667566 20191030 97.77365492700207 20191031 98.90704936769589 20191101 96.7042475431054 20191104 96.69010848130661 20191105 97.29105955270792 20191106 97.42871187856204 20191107 96.14174595525786 20191108 96.31767336729915 20191111 95.23706242329341 20191112 94.14125511324706 20191113 91.31230590034812 20191114 92.7772778901933 20191115 96.32989503776075 20191118 95.53071837954214 20191119 93.94249844826365 20191120 95.897485484709 20191121 96.7880822033708 20191122 97.30504310982323 20191125 96.52198605165165 20191126 97.21906783717331 20191127 98.74032174508467 20191128 95.64329361518152 20191129 98.84223338520515 20191202 98.70002215364413 20191203 96.23953650463594 20191204 98.56818493020346 20191205 99.89892000006923 20191206 100.0 20191209 96.4295523744025 20191210 96.6857211169727 20191211 97.05476895234965 20191212 96.13421830760592 20191213 95.83913594233506 20191216 96.14701380033414 20191217 95.92273916839407 20191218 95.66556386285724 20191219 95.29111164999073 20191220 95.81072254375701 20191223 96.07298677177356 20191224 96.60003896437877 20191225 97.5819208138721 20191226 97.84674157882897 20191227 95.25260494493743 20191230 95.04374116451405 20191231 93.39947491687953 20200102 95.9293452802388 20200103 95.42913983761969 20200106 95.19868841266171 20200107 94.45171419684551 20200108 95.21723086463876 20200109 94.69168571149305 20200110 94.01272653305185 20200113 93.22840730938807 20200114 91.91960191526093 20200115 91.09947833666325 20200116 90.5875588334005 20200117 90.2306879696269 20200120 91.84029226085877 20200121 92.78298381270122 20200122 93.40135790797162 20200123 95.40129389475801 20200203 94.90541443824806 20200204 92.91172553278456 20200205 92.99172599134864 20200206 91.9742058693125 20200207 89.38378390276563 20200210 88.38204421968352 20200211 86.33783563050063 20200212 86.21365976322114 20200213 83.63014517928202 20200214 81.94941288202585 20200217 81.10958478007417 20200218 81.43897868407669 20200219 81.72217402800237 20200220 83.80321465736029 20200221 84.86542458438068 20200224 83.56560513230932 20200225 85.24253120634647 20200226 84.2307250076849 20200227 85.68627678672918 20200228 88.06714633732634 20200302 87.10920353481362 20200303 87.19342918748322 20200304 87.34939717091778 20200305 86.30072845206428
analyse_all(nfyy, "diff_real_est") ## 略改善
净值预测回测分析: 平均偏离: 0.1311503341239221 标准差偏离: 0.19041538962622517 预测偏差分位: 1% 分位: -0.614 5% 分位: -0.331 25% 分位: -0.086 50% 分位: -0.001 75% 分位: 0.081 95% 分位: 0.292 99% 分位: 0.408 涨跌偏差分析: 预测涨的比实际少: 0.29 预测涨的比实际多: 0.26 预测跌的比实际多: 0.2 预测跌的比实际少: 0.25
nfyy = \
estimate_table_with_pos("20190101", "20200305", ("real", {"F501018": 100}), ("est", holdings["501018"]),
)
analyse_all(nfyy, "diff_real_est")
净值预测回测分析: 平均偏离: 0.13673210395925103 标准差偏离: 0.19784112535689902 预测偏差分位: 1% 分位: -0.717 5% 分位: -0.305 25% 分位: -0.098 50% 分位: -0.005 75% 分位: 0.09 95% 分位: 0.325 99% 分位: 0.463 涨跌偏差分析: 预测涨的比实际少: 0.31 预测涨的比实际多: 0.24 预测跌的比实际多: 0.17 预测跌的比实际少: 0.28
hbyq = \
estimate_table("20190101", "20200305", ("real", {"F162411": 100}), ("est", holdings["162411"]))
analyse_all(hbyq, "diff_real_est")
净值预测回测分析: 平均偏离: 0.11067137837382375 标准差偏离: 0.1466540526054426 预测偏差分位: 1% 分位: -0.351 5% 分位: -0.235 25% 分位: -0.092 50% 分位: -0.005 75% 分位: 0.083 95% 分位: 0.183 99% 分位: 0.487 涨跌偏差分析: 预测涨的比实际少: 0.27 预测涨的比实际多: 0.25 预测跌的比实际多: 0.22 预测跌的比实际少: 0.27
sns.distplot(list(hbyq["diff_real_est"]))
<matplotlib.axes._subplots.AxesSubplot at 0x10b541b38>
hbyq = \
estimate_table("20190101", "20200305", ("real", {"F162411": 100}), ("est", holdings["162411"]),
float_holdings=True, window=4, decay=0.65, smooth=0.2)
/Users/shixin/Documents/newwork/quant finance/xalpha/xalpha/universal.py:111: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy df[k] = df[k].apply(_float)
20190103 91.02316508226221 20190104 91.18736806909216 20190107 91.42294464302962 20190108 91.31293026490012 20190109 91.47956245149223 20190110 91.64779927110968 20190111 91.4480866568967 20190114 92.88908979944209 20190115 93.26315381766078 20190116 90.5099246529659 20190117 89.30486689245382 20190118 92.15168621763824 20190121 92.99372549848364 20190122 92.79668932563207 20190123 92.6756540910683 20190124 94.42684208140221 20190125 93.09450736383893 20190128 92.63988656220975 20190129 92.77584558263577 20190130 92.97451594230357 20190131 92.26914844087126 20190201 91.50933803903732 20190211 92.90278673414241 20190212 92.65209222168077 20190213 91.92977284123937 20190214 92.48416332566121 20190215 92.4832972441177 20190218 92.48329724411768 20190219 92.03639294587313 20190220 92.48693261335598 20190221 91.62964296550406 20190222 90.81201875561115 20190225 93.00750204194448
../lof/predict.py:108: RuntimeWarning: invalid value encountered in double_scalars ratio = realf / estf
20190226 93.582304457362 20190227 94.33816810147552 20190228 95.81896979155046 20190301 95.89543406457042 20190304 97.84389948036407 20190305 96.4246891225797 20190306 96.23253636349062 20190307 96.56988329821014 20190308 96.26794961515462 20190311 96.20273551683181 20190312 96.24006602664714 20190313 95.86490873312889 20190315 94.963503868003 20190318 94.42954525359667 20190319 94.72598580619774 20190320 93.33631797621469 20190321 95.64823577512094 20190322 95.31409734009567 20190325 93.96994933301688 20190326 93.6445446898773 20190327 94.16862991650117 20190328 93.68952772323584 20190329 95.78771639813328 20190401 96.62399238326807 20190402 95.09486169935235 20190403 93.64960691258692 20190404 95.75551529747393 20190408 96.14761429337376 20190409 94.96445455675742 20190410 94.66289066114739 20190411 95.56211009460982 20190412 95.33598278730956 20190415 94.76299068168835 20190416 94.97399362404677 20190417 94.75415679385844 20190418 94.18951016144965 20190419 92.60091708793765 20190422 91.80290832238703 20190424 93.89846067512248 20190425 93.69895420976064 20190426 93.1102752231422 20190429 93.16510852674017 20190430 93.77927891556524 20190506 92.61716228014727 20190507 92.59050942013906 20190508 93.6284478497083 20190510 94.03478210564055 20190513 93.8741697213642 20190514 94.12715960081663 20190515 95.30706232417994 20190516 94.7961713306068 20190517 94.67939882680666 20190520 94.86092696767811 20190521 95.2243027360382 20190522 94.79388587959433 20190523 95.18300982669656 20190524 95.85355649001738 20190527 97.07105077946854 20190528 98.05156097805309 20190529 99.96186069736984 20190530 98.73163277852221 20190531 96.3351562040816 20190603 96.55563905124433 20190604 97.21156323787153 20190605 96.76261920541205 20190606 96.09681381641354 20190610 95.30348067795782 20190611 96.18952022011753 20190612 96.00952314767103 20190613 96.55155744008282 20190614 97.5026956883687 20190617 95.43758164174152 20190618 95.32451040195562 20190619 96.24810830375714 20190620 96.42764165878569 20190621 95.32198353962222 20190624 95.72203285641746 20190625 94.25217115015049 20190626 93.58052011266419 20190627 93.29535657056549 20190628 90.670686246542 20190701 90.67068624654202 20190702 90.6938498745462 20190703 89.75307379818743 20190704 89.75307379818744 20190705 92.47241937460998 20190708 92.9140824234127 20190709 93.36450278400405 20190710 91.44715125947677 20190711 91.8935664393573 20190712 92.18298032640016 20190715 93.10862802174513 20190716 92.5644530510635 20190717 92.1677146377275 20190718 92.9587315354924 20190719 94.13468340175312 20190722 93.28303995678155 20190723 93.57064827070177 20190724 92.01027336219398 20190725 89.92330456144151 20190726 91.90979635972518 20190729 91.62725105924793 20190730 91.31094280764738 20190731 91.31094280764735 20190801 90.44781682839397 20190802 90.79175144844568 20190805 90.75687719869562 20190806 90.54243628225605 20190807 90.54243628225606 20190808 90.644870325847 20190809 90.07328741006361 20190812 90.42807764576827 20190813 90.29415667406136 20190814 90.10997503904967 20190815 88.35784434709498 20190816 87.97238350917476 20190819 88.5265140700566 20190820 87.38464280010139 20190821 87.62905028080772 20190822 86.69570593827197 20190823 86.28380688480121 20190826 87.10389392497467 20190827 87.96091481008789 20190828 88.3739681139831 20190829 88.88414776718211 20190830 87.27390988681265 20190903 87.82330064989802 20190904 88.65867620655332 20190905 88.06156607643243 20190906 87.99893055655187 20190909 88.6344599754891 20190910 89.49534563658688 20190911 90.15820664399413 20190912 88.85256787723793 20190916 89.28533043350087 20190917 89.85111812260914 20190918 90.00653526866424 20190919 89.39211419574309 20190920 90.25080522906319 20190923 90.25080522906318 20190924 90.64289432209966 20190925 91.40166638662313 20190926 93.48333854414464 20190927 92.29956444658865 20190930 93.13302654919526 20191008 91.9384706848759 20191009 90.91179452860285 20191010 93.8013905374314 20191011 93.45003149133747 20191014 93.30194580274176 20191015 92.13346212878619 20191016 90.81055497857905 20191017 89.7076695202165 20191018 88.06949260012523 20191021 89.42390249187768 20191022 90.12019331626425 20191023 89.48278390601602 20191024 88.48904896770685 20191025 88.20634841989595 20191028 86.88285649315218 20191029 85.26656862352603 20191030 86.501520975376 20191031 86.31432549421694 20191101 86.42841027154788 20191104 87.39207465122772 20191106 88.52597005736399 20191107 87.21678907854887 20191108 87.49209507148299 20191111 88.46541187464948 20191112 88.66805478573718 20191113 89.19371891029766 20191114 87.68706294466892 20191115 87.25757726862165 20191118 86.72409064919658 20191119 85.219484851393 20191120 86.26225429701721 20191121 86.34178235591116 20191122 86.87310792266275 20191125 86.61388515484417 20191126 86.11392863367801 20191127 88.14745668177518 20191128 88.1474566817752 20191129 85.57956468888875 20191202 85.57956468888874 20191203 85.98363114131203 20191204 85.73050117465297 20191205 85.83449991421476 20191206 85.38918817546839 20191209 84.4197344628766 20191210 83.91416907517555 20191211 84.55875264348647 20191212 83.64844455405657 20191213 83.20547913670035 20191216 83.91654284308439 20191217 84.218657811513 20191218 83.60177292256124 20191219 84.0340994998693 20191220 83.26203895987828 20191223 82.63424047366718 20191224 82.63424047366719 20191225 82.63424047366718 20191226 82.63424047366719 20191227 84.11102619830689 20191230 84.11102619830687 20191231 82.28894219406196 20200102 84.69876541741158 20200103 86.00275480078278 20200106 86.0850652755 20200107 87.17455079254022 20200108 87.94735162126777 20200110 88.82741681149516 20200113 90.08332730226532 20200114 90.81033472969321 20200115 91.84805811530529 20200116 91.68677353090831 20200117 92.63912517450484 20200120 92.38119406449525 20200121 92.62454331254654 20200122 92.97275518641464 20200123 93.38775836005385 20200203 92.95941095054255 20200204 93.04832439489157 20200205 92.87266045001708 20200206 92.91611457870212 20200207 92.69833225426493 20200210 92.13280714394722 20200211 91.89042473137775 20200212 91.46973937238718 20200213 90.69404425831279 20200214 89.94297298839075 20200217 89.59415926235278 20200218 89.18072532365557 20200219 89.5449390566172 20200220 90.94525779199606 20200221 87.70369601486927 20200224 87.77498843723728 20200225 87.61441762494279 20200226 87.53458737228154 20200227 86.48161663019597 20200228 86.256249484961 20200302 85.90501760398607 20200303 85.57942817468518 20200304 85.12757328911255 20200305 84.9428088672791
analyse_all(hbyq, "diff_real_est") # 存在改善!
净值预测回测分析: 平均偏离: 0.09761915454118616 标准差偏离: 0.12635002727389924 预测偏差分位: 1% 分位: -0.308 5% 分位: -0.196 25% 分位: -0.073 50% 分位: 0.003 75% 分位: 0.085 95% 分位: 0.197 99% 分位: 0.332 涨跌偏差分析: 预测涨的比实际少: 0.27 预测涨的比实际多: 0.24 预测跌的比实际多: 0.25 预测跌的比实际少: 0.24
hbyq = \
estimate_table_with_pos("20190101", "20200305", ("real", {"F162411": 100}), ("est", holdings["162411"]))
/Users/shixin/Documents/newwork/quant finance/xalpha/xalpha/universal.py:138: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy df[k] = df[k].apply(_float)
analyse_all(hbyq, "diff_real_est") # 继续改善
净值预测回测分析: 平均偏离: 0.0889651321145134 标准差偏离: 0.11984714572662096 预测偏差分位: 1% 分位: -0.321 5% 分位: -0.219 25% 分位: -0.068 50% 分位: 0.002 75% 分位: 0.078 95% 分位: 0.161 99% 分位: 0.247 涨跌偏差分析: 预测涨的比实际少: 0.27 预测涨的比实际多: 0.24 预测跌的比实际多: 0.24 预测跌的比实际少: 0.25
hbyq.plot(x="date", y=["estpos", "estposld"])
<matplotlib.axes._subplots.AxesSubplot at 0x1187550b8>
yfd = \
estimate_table("20190101", "20200305", ("real", {"F161129": 100}), ("est", holdings["161129"]))
analyse_all(yfd, "diff_real_est") # 预测性超级差。。。
净值预测回测分析: 平均偏离: 0.14551683914747404 标准差偏离: 0.7442584240573993 预测偏差分位: 1% 分位: -0.868 5% 分位: -0.187 25% 分位: -0.035 50% 分位: -0.006 75% 分位: 0.019 95% 分位: 0.182 99% 分位: 0.867 涨跌偏差分析: 预测涨的比实际少: 0.31 预测涨的比实际多: 0.27 预测跌的比实际多: 0.13 预测跌的比实际少: 0.29
yfd = \
estimate_table("20190101", "20200305", ("real", {"F161129": 100}), ("est", holdings["161129"]),
float_holdings=True, window=4, decay=0.65, smooth=0.2)
20190103 94.35909958505378 20190104 94.29885283914926 20190107 94.10632834706732 20190108 93.89849682024727 20190109 94.15037825949103 20190110 93.00084911973276 20190111 92.80688500803618 20190114 91.89251253268004 20190115 90.7209254541996 20190116 93.85015008877576 20190117 93.30485137355123 20190118 93.0799361926993
../lof/predict.py:108: RuntimeWarning: invalid value encountered in double_scalars ratio = realf / estf
20190122 92.41406480317406 20190123 93.05723899047692 20190124 92.48351232237006 20190125 91.63841277969334 20190128 93.5172298621616 20190129 94.05332730641469 20190130 93.25565046779455 20190131 94.32575521391422 20190201 95.34466257496861 20190211 95.6196933962445 20190212 96.55421127268163 20190213 95.249406326432 20190214 95.32618006003132 20190215 95.51157085462339 20190218 95.5115708546234 20190219 96.33954801413765 20190220 96.31725936088765 20190221 97.8374073501235 20190222 99.86387197067124 20190225 98.54989786651848 20190226 99.99999999999999 20190227 100.00000000000001 20190228 98.15642549634896 20190301 99.10152029623447 20190304 97.20169470469563 20190305 96.22849433865704 20190306 98.14563572782856 20190307 97.45710954771694 20190308 95.14178881113892 20190311 96.47669566742192 20190312 96.86401749678036 20190313 96.28949704252715 20190314 95.042075350783 20190315 94.61042753395493 20190318 94.73237563959655 20190319 93.73461731412577 20190320 95.03048711287062 20190321 95.89286265462322 20190322 96.37743411169903 20190325 95.8203300047816 20190326 96.80177782429293 20190327 97.30953806778044 20190328 97.77804720699457 20190329 96.43607096549842 20190401 96.94866313730589 20190402 96.32083417523646 20190403 96.34280476591738 20190404 95.84543373988521 20190408 95.69950798285743 20190409 95.61370390373065 20190410 96.43941615016551 20190411 96.37673977430387 20190412 96.87893669514985 20190415 95.85852778255014 20190416 96.12931581177668 20190417 96.00455619854735 20190418 95.85258995695013 20190419 95.85258995695011 20190423 95.89176907256666 20190424 95.74638958039057 20190425 97.10102943372249 20190426 97.76110288580934 20190429 94.74679969089537 20190430 95.79928803916243 20190507 96.92430580427585 20190508 97.10644077360833 20190509 97.44583521878847 20190510 98.85795542204264 20190513 97.17126744328736 20190514 97.40781012699068 20190515 97.48073964903145 20190516 97.34338046843965 20190517 96.88095305914 20190520 96.60736733660401 20190521 96.12732710876901 20190522 95.6870435825128 20190523 96.18672340649447 20190524 96.07005486549615 20190527 96.07005486549613 20190528 95.18110550114392 20190529 94.72237322738344 20190530 94.34449963138448 20190531 93.31944473161617 20190603 94.84403646145948 20190604 94.61896579330052 20190605 94.27761484209582 20190606 94.28442416708002 20190610 94.60628196965233 20190611 94.33155212157145 20190612 93.97898232329172 20190613 93.75044037405998 20190614 93.81138741057767 20190617 93.9381569108144 20190618 93.8117594124685 20190619 93.42417056005314 20190620 93.77148632004061 20190621 93.20682106226752 20190624 92.43735135236844 20190625 93.40793733502444 20190626 93.20479176195798 20190627 93.37429953460345 20190628 93.56174450369166 20190701 93.22816147572496 20190702 93.15500688166445 20190705 94.29822092873485 20190708 94.40109561441739 20190709 95.21853794024501 20190710 96.12931493552033 20190711 94.43638978318181 20190712 95.3181012082776 20190715 95.31810120827762 20190716 96.34479473672125 20190717 97.0930440807886 20190718 98.51289398464245 20190719 98.83301947063522 20190722 96.86555794978257 20190723 96.98499870391429 20190724 97.43897820329185 20190725 96.95146807725 20190726 96.72226427660938 20190729 97.29184188167902 20190730 97.1452440997865 20190731 96.84685551678687 20190801 96.24545569887198 20190802 95.89416288292281 20190805 95.57089162340272 20190806 95.88251159746797 20190807 95.27411995301162 20190808 96.09977762820212 20190809 96.07525878877263 20190812 96.07525878877263 20190813 95.75938374244843 20190814 96.05652654800512 20190815 96.48877821148811 20190816 96.86989110662671 20190819 96.24703842938631 20190820 95.74343927199885 20190821 95.88833926258054 20190822 95.76260303083676 20190823 95.25093358180679 20190826 95.25093358180678 20190827 94.76445879207867 20190828 94.39804272166569 20190829 93.60009664493104 20190830 92.04883123175058 20190902 92.0488312317506 20190903 95.15738548588136 20190904 95.45374605728765 20190905 95.60509300113304 20190906 96.4555808861729 20190909 95.94133604690643 20190910 96.4184396951337 20190911 97.89104744898653 20190912 96.45789640593146 20190916 96.45789640593144 20190917 96.47737990684418 20190918 96.90875257307941 20190919 97.25341433460801 20190920 96.95611520097317 20190924 97.45357728941094 20190925 97.66423250459536 20190926 97.62652741605363 20190927 97.66502840951415 20190930 97.14721419342193 20191008 96.78433371784277 20191009 97.34096975146996 20191010 96.86083664624007 20191011 96.29631275972383 20191014 96.03394510236447 20191015 95.8944451977319 20191016 95.65605542696386 20191017 95.90502045358218 20191018 96.47199725606039 20191021 97.40570228583067 20191022 98.29775422436394 20191023 99.76010008006654 20191024 97.92495776254424 20191025 97.78337661508776 20191028 97.90196962854534 20191029 97.7126513969212 20191030 97.65930436689601 20191031 97.9191286569897 20191101 97.34406535311541 20191104 97.79078185626517 20191105 97.45084507710575 20191106 97.44875003920454 20191107 97.30418686298403 20191108 97.12808091153606 20191111 98.52144629173199 20191112 98.11728707553648 20191113 95.65583648133916 20191114 96.59209762703016 20191115 96.32651750312677 20191118 97.49231188424119 20191119 96.54443436282175 20191120 97.20342455079131 20191121 97.25952552216869 20191122 98.03313391555562 20191125 98.5927175430088 20191126 99.46659472029906 20191127 99.99999999999999 20191128 98.58133823047515 20191129 98.41807289499026 20191202 98.38302413074949 20191203 97.7949389127 20191204 96.10660689310619 20191205 94.31110435302892 20191206 97.39961105673119 20191209 95.79450150768811 20191210 94.53951335553364 20191211 94.72441280016075 20191212 95.00528507296845 20191213 95.0765961710922 20191216 94.73999726282348 20191217 94.37641993281208 20191218 94.39419542398882 20191219 94.18391638706828 20191220 94.89673405087817 20191223 95.49488959515517 20191224 95.7304844825557 20191225 95.76860686145623 20191226 96.59062343660524 20191227 93.56498838575334 20191230 92.86972299258287 20191231 94.77148877641264 20200102 95.12771238386411 20200103 94.42455847606539 20200106 94.04425148204508 20200107 94.75308318851387 20200108 94.8060046038879 20200109 94.53046659413491 20200110 94.68362225865964 20200113 94.72964490781683 20200114 94.6701582996827 20200115 94.84085363638393 20200116 94.74885934096335 20200117 94.51897180003246 20200120 94.60047161414033 20200121 94.86655359716906 20200122 95.03328182529155 20200123 96.33323217595849 20200203 94.88895387307295 20200204 95.55097367578851 20200205 96.02642103118973 20200206 95.9538501948689 20200207 95.87891175431673 20200210 93.34168332861374 20200211 91.80150986545213 20200212 93.24071644708069 20200213 93.11811494614359 20200214 92.27895110072691 20200217 91.22883572242804 20200218 90.63122091946846 20200219 90.63458670651661 20200220 89.8378833362987 20200221 92.0480330667887 20200224 90.99647356183755 20200225 91.27361223203862 20200226 91.55897733230482 20200227 91.99314687410877 20200228 91.36881685171706 20200302 91.10239704904794 20200303 90.25495471096008 20200304 90.25495471096006 20200305 89.26949937351488
analyse_all(yfd, "diff_real_est") # 无明显变化
净值预测回测分析: 平均偏离: 0.14552664698264714 标准差偏离: 0.7525197347974537 预测偏差分位: 1% 分位: -0.852 5% 分位: -0.2 25% 分位: -0.037 50% 分位: -0.007 75% 分位: 0.015 95% 分位: 0.186 99% 分位: 0.876 涨跌偏差分析: 预测涨的比实际少: 0.24 预测涨的比实际多: 0.34 预测跌的比实际多: 0.17 预测跌的比实际少: 0.25
yfd = \
estimate_table_with_pos("20190101", "20200305", ("real", {"F161129": 100}), ("est", holdings["161129"]))
analyse_all(yfd, "diff_real_est")
净值预测回测分析: 平均偏离: 0.15115824932756056 标准差偏离: 0.7545173942148973 预测偏差分位: 1% 分位: -0.871 5% 分位: -0.22 25% 分位: -0.039 50% 分位: -0.011 75% 分位: 0.019 95% 分位: 0.183 99% 分位: 0.867 涨跌偏差分析: 预测涨的比实际少: 0.26 预测涨的比实际多: 0.32 预测跌的比实际多: 0.12 预测跌的比实际少: 0.3
yfd = \
estimate_table("20200301", "20200319", ("real", {"F161129": 100}), ("est", holdings["161129"]),
float_holdings=True, window=4, decay=0.65, smooth=0.3)
20200303 93.67356452261032
../lof/predict.py:119: RuntimeWarning: invalid value encountered in double_scalars ratio = realf / estf
20200305 92.67795478801658 20200306 91.28124775416539 20200309 89.02570039922193 20200310 88.61025671965129 20200311 86.77313584841382 20200312 83.4295867629937 20200313 78.83150991223815 20200316 79.50797422018019 20200317 80.31698721386726 20200318 80.72404430865531 20200319 80.18286853978816
analyse_all(yfd, "diff_real_est") # 无明显变化
净值预测回测分析: 平均偏离: 0.7886797773559008 标准差偏离: 1.0781728431273583 预测偏差分位: 1% 分位: -2.325 5% 分位: -2.237 25% 分位: -0.427 50% 分位: -0.059 75% 分位: 0.476 95% 分位: 1.039 99% 分位: 1.123 涨跌偏差分析: 预测涨的比实际少: 0.0 预测涨的比实际多: 0.31 预测跌的比实际多: 0.46 预测跌的比实际少: 0.23
jsyy=\
estimate_table("20190101", "20200305", ("real", {"F160723": 100}), ("est", holdings["160723"]))
analyse_all(jsyy, "diff_real_est") # 原油基金中,预测性出奇的好!
净值预测回测分析: 平均偏离: 0.09408298326797263 标准差偏离: 0.14917499656769317 预测偏差分位: 1% 分位: -0.456 5% 分位: -0.213 25% 分位: -0.064 50% 分位: -0.012 75% 分位: 0.044 95% 分位: 0.215 99% 分位: 0.53 涨跌偏差分析: 预测涨的比实际少: 0.17 预测涨的比实际多: 0.37 预测跌的比实际多: 0.25 预测跌的比实际少: 0.22
jsyy=\
estimate_table("20190101", "20200305", ("real", {"F160723": 100}), ("est", holdings["160723"]), float_holdings=True,
window=4, decay=0.65, smooth=0.2)
20190103 99.29822206419422 20190104 99.55141988127797 20190107 99.91715215427388 20190108 100.0 20190109 97.04302618289408 20190110 97.01306569271324 20190111 97.42733639604523 20190114 97.31777302131505 20190115 96.18560083382205 20190116 97.37304524645579 20190117 97.42899994466062 20190118 97.17151600200435 20190121 96.60258546561575 20190122 96.89622685352987 20190123 97.48382711824088 20190124 97.7158223583916 20190125 97.91814704297691 20190128 98.91134407088727 20190129 97.56537108756571 20190130 98.75953232487856 20190131 97.99707843647612 20190201 97.94145473010512 20190211 98.06772184145757 20190212 99.1147382314877 20190213 98.31819463430388 20190214 98.16233428359024 20190215 97.9456955014084 20190218 98.47354745038493 20190219 97.68249289374225 20190220 96.13891186443742 20190221 95.6777939971009 20190222 95.3225788116609 20190225 97.52902887402169 20190226 96.89526679764079 20190227 96.63591880698213 20190228 96.14939796309372 20190301 96.10610153546028 20190304 96.3429849359328 20190305 95.12982365228417 20190306 95.3217691072385 20190307 94.47219739359564 20190308 93.58853761126181 20190311 95.49106687117538 20190312 95.5744632070197 20190313 95.19613699385104
../lof/predict.py:108: RuntimeWarning: invalid value encountered in double_scalars ratio = realf / estf
20190314 95.19613699385104 20190315 95.18827485157277 20190318 95.61157032652739 20190319 95.22867173457877 20190320 94.71961657964133 20190321 94.78118433445081 20190322 94.25725292239981 20190325 95.40630461750901 20190326 95.41281910498653 20190327 95.47507865724744 20190328 95.69359766771962 20190329 96.7119258056437 20190401 96.65426854958397 20190402 97.82774113301839 20190403 97.52144720415048 20190404 98.74753157300331 20190408 100.00000000000003 20190409 99.99999999999996 20190410 98.19327132100236 20190411 97.63001463753244 20190412 97.55377492417888 20190415 97.70854685306479 20190416 98.14385388550076 20190417 96.50886340613107 20190418 96.73555384199035 20190419 95.94343687627003 20190422 94.01396360368217 20190423 96.97130889595313 20190424 97.45384717956773 20190425 97.99683903635812 20190426 97.15247139724033 20190429 99.7487869746339 20190430 97.22759983873404 20190506 97.37395800139527 20190507 97.73376060478941 20190508 98.55141388554233 20190509 98.5817331205865 20190510 97.681583993134 20190513 98.64749371462385 20190514 98.72956581501182 20190515 99.17373727716145 20190516 100.0 20190517 97.43967945611652 20190520 96.94338453749727 20190521 96.84476284504541 20190522 96.24793881263668 20190523 97.584554731748 20190524 96.59003648882724 20190527 97.25867694766724 20190528 96.909906612747 20190529 97.21294644895089 20190530 97.36800831849857 20190531 95.04079963524836 20190603 95.62076309986318 20190604 95.86137642452107 20190605 95.30264649377428 20190606 94.37447450328995 20190610 94.21647404543306 20190611 94.03894174325923 20190612 93.49898054491793 20190613 92.1535010700763 20190614 93.4379103909606 20190617 93.69353279125795 20190618 93.26515871023017 20190619 92.00249455347556 20190620 92.22691878921194 20190621 91.18789028015455 20190624 88.43224289784386 20190625 90.47170504024238 20190626 89.04011830387248 20190627 86.74948903728196 20190628 87.58934989025475 20190701 89.26468727046739 20190702 87.88155886030543 20190703 91.6912518598451 20190704 91.67273871098428 20190705 90.77700533906638 20190708 90.21948814189479 20190709 91.95485842392085 20190710 92.95570222001206 20190711 92.52378388617922 20190712 94.42084541907037 20190715 93.6135478210084 20190716 94.21607755593737 20190717 95.90134004210788 20190718 96.59643875739657 20190719 95.7998756567572 20190722 95.01113243624813 20190723 94.87244259108111 20190724 94.88800299260956 20190725 96.45767865530125 20190726 98.21587909991936 20190729 100.0 20190730 99.84611571457685 20190731 100.00000000000003 20190801 98.76121864283179 20190802 97.9344001354589 20190805 95.69162568170961 20190806 96.18782992095112 20190807 93.64315363252084 20190808 95.09139645146449 20190809 96.5558606179694 20190812 95.76247765454666 20190813 95.95875175953552 20190814 96.94334447089092 20190815 97.4956756958637 20190816 95.45939915279043 20190819 96.03702465886907 20190820 95.75944205620505 20190821 95.22666036236069 20190822 94.46708957353285 20190823 93.51359596750264 20190826 94.20178365136991 20190827 96.72617129304749 20190828 94.4708593380956 20190829 91.87407686011711 20190830 96.38957527593094 20190902 95.81570433485635 20190903 96.03968178951631 20190904 94.38474039271559 20190905 95.12296399603117 20190906 95.17389496679598 20190909 93.28083489082819 20190911 91.86558928764978 20190912 92.6290937841457 20190916 94.75626736899683 20190917 94.5457286159569 20190918 94.34504636859322 20190919 95.02985355096953 20190920 95.56826044289417 20190923 95.7137730914727 20190924 95.80632959206658 20190925 96.2080787172079 20190926 96.23549105073639 20190927 95.88915356164459 20190930 95.46602755230614 20191008 95.74600109910973 20191009 98.8866844357554 20191010 96.78070682556405 20191011 96.54417107516988 20191014 96.13535991358867 20191015 97.8547308065685 20191016 95.4073357508953 20191017 97.3059561729405 20191018 99.37117912954177 20191021 98.28033096356008 20191022 98.66896162246776 20191023 96.84247656171596 20191024 96.36121556446489 20191025 97.0958338705519 20191028 98.19458826458491 20191029 97.5771792059499 20191030 99.04291503375107 20191031 100.0 20191101 99.7730437665297 20191104 97.9964276525329 20191105 98.83490615052247 20191106 99.02443807899579 20191107 98.30900768250184 20191108 97.86860796506772 20191111 96.92633603410039 20191112 95.1823450212678 20191113 93.1435388648091 20191114 94.73994280215756 20191115 92.70576372077427 20191118 95.08118076555392 20191119 94.07291003989175 20191120 94.63107063687617 20191121 94.61049212616904 20191122 95.74937114493505 20191125 94.34886123334579 20191126 94.56606300850926 20191127 94.44703750735773 20191128 92.60812388124386 20191129 96.28594515404579 20191202 94.76280667266508 20191203 91.45402660114289 20191204 94.85459861878124 20191205 95.64920203121768 20191206 96.54057302500418 20191209 93.93163123125068 20191210 94.5511572902784 20191211 94.92208771181933 20191212 94.68952345472042 20191213 94.67389174224688 20191216 95.1700782410705 20191217 95.0450819120455 20191218 94.67506554188327 20191219 94.22641800742534 20191220 95.44218778468057 20191223 96.16231899175959 20191224 96.65539001971531 20191225 97.49445414473801 20191226 97.69367962375458 20191227 95.00528737016681 20191230 94.6204105963189 20191231 93.21734056561081 20200102 95.71367937813825 20200103 94.71917515571782 20200106 93.7973431529509 20200107 92.45527814859472 20200108 94.4102351227919 20200109 93.24927662450345 20200110 93.05013592864526 20200113 92.90711569686977 20200114 92.80757561173147 20200115 92.77220059994936 20200116 92.49469177957532 20200117 92.27006145496026 20200120 93.96748841396068 20200121 95.11583424828166 20200122 96.55657990107169 20200123 97.12961761204274 20200203 96.2359771183458 20200204 95.0439002206545 20200205 95.3598337304895 20200206 94.02477209581278 20200207 92.34799736275346 20200210 91.13334226617478 20200211 89.11715048591475 20200212 90.04743341675153 20200213 88.25984690673168 20200214 86.5095048297471 20200217 85.499639091913 20200218 85.60056361265934 20200219 84.67021178885287 20200220 84.2716552242511 20200221 87.76481573456985 20200224 85.97910536286238 20200225 86.41065489870658 20200226 85.78068120264076 20200227 87.06884015479594 20200228 85.3628315650881 20200302 85.11765894886592 20200303 85.33101018270851 20200304 86.28343937131608 20200305 87.4194588190247
analyse_all(jsyy, "diff_real_est") # 在本来就准的基础上,又略微改善
净值预测回测分析: 平均偏离: 0.09025478055273216 标准差偏离: 0.1357400830918445 预测偏差分位: 1% 分位: -0.403 5% 分位: -0.215 25% 分位: -0.078 50% 分位: -0.011 75% 分位: 0.041 95% 分位: 0.183 99% 分位: 0.353 涨跌偏差分析: 预测涨的比实际少: 0.25 预测涨的比实际多: 0.29 预测跌的比实际多: 0.19 预测跌的比实际少: 0.27
gtsp=\
estimate_table("20190101", "20200305", ("real", {"F160216": 100}), ("est", holdings["160216"]))
analyse_all(gtsp, "diff_real_est") # 可预测性也极好
净值预测回测分析: 平均偏离: 0.09892164040568546 标准差偏离: 0.13543481510543717 预测偏差分位: 1% 分位: -0.345 5% 分位: -0.191 25% 分位: -0.089 50% 分位: -0.012 75% 分位: 0.061 95% 分位: 0.175 99% 分位: 0.382 涨跌偏差分析: 预测涨的比实际少: 0.24 预测涨的比实际多: 0.34 预测跌的比实际多: 0.21 预测跌的比实际少: 0.21
gtsp=\
estimate_table("20190101", "20200305", ("real", {"F160216": 100}), ("est", holdings["160216"]),
float_holdings=True, window=4, decay=0.65, smooth=0.2)
20190103 80.2702944117856 20190104 79.83495975133566 20190107 79.22576396208636 20190108 78.47724534301975 20190109 78.74360294698806 20190110 78.74360294698808
../lof/predict.py:108: RuntimeWarning: invalid value encountered in double_scalars ratio = realf / estf
20190111 78.9942948927742 20190114 79.3665022888935 20190115 79.34173531302416 20190116 79.73314015224061 20190117 80.5013589711213 20190118 80.78474608088835 20190121 80.78474608088837 20190122 81.03740845809476 20190123 82.28059718905827 20190124 80.91245607675934 20190125 80.61418020716302 20190128 81.88734883172489 20190129 81.27719388736816 20190130 80.00457539367515 20190131 80.50889479499325 20190201 80.3282372530879 20190211 80.52961323110256 20190212 80.37502132492328 20190213 80.41516091758463 20190214 80.59551298210076 20190215 80.27088655385529 20190218 80.97856424973104 20190219 80.39950513901316 20190220 80.5922662371534 20190221 81.35417082630728 20190222 79.31197325868325 20190225 82.27093710033559 20190226 82.87907408775469 20190227 82.71632379776572 20190228 81.31383487740028 20190301 81.9705166722793 20190304 80.55193307689726 20190306 79.60341609572546 20190307 81.35707635466373 20190308 81.01691208637 20190311 80.61465908930757 20190313 79.51874360336672 20190314 79.5187436033667 20190315 79.51874360336672 20190318 78.87594357663426 20190319 79.29885148268698 20190320 78.33402240683829 20190321 77.49931839009274 20190322 77.24269900955102 20190325 78.38727730970523 20190326 77.67731391291983 20190327 76.54139715924939 20190328 76.05890497769965 20190329 78.54097720687994 20190401 77.3756880991352 20190402 77.02889074048967 20190403 78.61010431460667 20190404 79.1865062773887 20190408 79.66770464233764 20190409 79.89181986041427 20190410 78.73668418277514 20190411 79.25092945890131 20190412 79.3758920659885 20190415 78.4293821898676 20190416 77.06458982320811 20190417 76.25543876412698 20190418 76.25543876412696 20190419 76.8602856255534 20190422 77.69564462771204 20190423 77.64225761215826 20190424 77.07217249472818 20190425 74.78334265032926 20190426 74.78901473082024 20190429 74.83547612953254 20190430 74.1767956895695 20190506 75.15225148590977 20190507 75.62359266083094 20190508 75.51868631578607 20190509 75.28794908372568 20190510 76.05160090615499 20190513 76.3156309409069 20190514 77.13276515435163 20190515 78.20962314598133 20190516 77.66123954594555 20190517 78.02777579889145 20190520 79.30142530288823 20190521 79.98286879142046 20190522 81.34122581236122 20190523 82.00771042965954 20190524 82.0615736313868 20190527 81.40779805527202 20190528 82.1408930573491 20190529 83.52932871423782 20190530 84.61898483702952 20190531 82.69578042949094 20190603 84.60182819051006 20190604 82.37275704924521 20190605 81.76927749048339 20190606 81.29577018278808 20190610 81.00134152861386 20190611 81.00134152861385 20190612 81.31580954621381 20190613 82.13271344718218 20190614 83.07326830051721 20190617 81.29409123375984 20190618 81.58797696819767 20190619 82.05950363024135 20190620 82.52806677433567 20190621 81.80158812049504 20190624 81.83198628717982 20190625 81.83198628717983 20190626 82.89700378941023 20190627 84.19514473034738 20190628 82.91497205543659 20190701 84.69631672635597 20190702 85.9822053000462 20190703 84.57989460539474 20190704 85.19375345783331 20190705 85.92061425550116 20190708 85.92061425550114 20190709 86.35114141219474 20190710 86.62778291476155 20190711 85.4171927651509 20190712 85.46121802093474 20190715 85.99098553658793 20190716 86.54426197282561 20190717 82.9076380495884 20190718 84.68946614259477 20190719 83.33242550102433 20190722 82.73013886563557 20190723 81.8699127219114 20190724 81.90219564466312 20190725 81.90219564466314 20190726 83.42101731322886 20190729 81.82199713043079 20190730 82.46258680043422 20190731 83.0910983669829 20190801 82.37718866388248 20190802 82.79157431490474 20190805 83.35931352896087 20190806 82.63344464897696 20190807 82.2244072613954 20190808 81.8409550128397 20190809 80.9969667119931 20190812 81.81093184213557 20190813 81.75005304482649 20190814 81.27308037276302 20190815 81.85967423960727 20190816 81.05383792683509 20190819 80.61068052828597 20190822 80.0754447983271 20190823 80.23361932710979 20190826 81.53429379916973 20190827 82.12168137775528 20190828 81.59736203801438 20190829 83.23506180917434 20190830 82.00276249133086 20190902 82.00276249133087 20190903 82.49887574756377 20190904 82.64766148880052 20190905 83.00137138410629 20190906 82.3410997425148 20190909 83.3615964334954 20190910 84.51968307081087 20190911 82.3636361381733 20190912 83.35894303591324 20190916 83.45394497768608 20190917 83.02012722330936 20190918 82.82018996365913 20190919 83.29609907021218 20190924 83.67340699456938 20190925 83.5963645612844 20190927 83.59527265195315 20190930 82.34672534590541 20191008 82.27598963536215 20191009 81.6783346825308 20191010 80.9927977753503 20191011 80.29171726781686 20191014 80.31356178527595 20191015 80.11464405678603 20191016 80.39255744347572 20191017 80.06193496690021 20191018 79.8063517003506 20191021 79.11980024520174 20191022 79.50974058021613 20191023 79.21434231035941 20191024 79.70814715961451 20191025 79.08730346974271 20191028 79.99354791107477 20191029 80.23351600382826 20191030 80.18816727162368 20191031 80.06536426682189 20191101 79.93258892522122 20191104 80.30602048708603 20191105 79.36771384824401 20191106 79.6647296643636 20191107 80.37911595668633 20191108 78.5238197358857 20191111 79.24876629420176 20191113 79.49354725246819 20191114 78.56745502069654 20191115 79.87320935704805 20191118 80.498900830866 20191119 80.29137474645957 20191120 79.84288706387885 20191121 79.93876390686435 20191122 80.19505397950692 20191126 80.01177760663033 20191127 80.16615850262725 20191128 81.5713963666743 20191129 81.06351504204679 20191202 82.17013642492132 20191203 83.35914920322134 20191204 82.05656160040682 20191205 82.22810765236841 20191206 82.48529520476995 20191209 82.48529520476994 20191210 80.89910220012851 20191211 79.9265044762031 20191212 79.8983831543559 20191213 79.67315615726152 20191216 80.35946845700259 20191217 80.33400574323908 20191218 79.85237994147664 20191219 81.82822681431456 20191220 81.19211289141583 20191223 83.42594572607166 20191224 83.00362433472911 20191225 84.9657641318684 20191226 86.24232594129641 20191227 86.08099546647476 20191230 85.39386326264535 20191231 83.95964167496552 20200103 84.19920473182287 20200106 83.63375816001663 20200107 86.55817490900988 20200108 85.80133829209817 20200109 87.02675930512336 20200110 85.79647188252731 20200113 84.28841663898427 20200114 83.62531849483237 20200115 84.26680213298077 20200116 83.99802386860044 20200117 83.46875280593943 20200120 83.07246502916303 20200121 82.16985678222449 20200122 81.41828195794959 20200123 81.20310948534922 20200203 81.7812548624717 20200204 81.78125486247171 20200205 80.61905435652172 20200206 80.09690779437973 20200207 78.71317116321242 20200210 77.87679753549111 20200211 76.62251769972889 20200212 77.37440433914261 20200213 76.95654375174624 20200214 76.40947279404146 20200217 75.6639422435171 20200218 77.1816187122732 20200219 80.06978760866834 20200220 80.24796081599058 20200221 79.31350597920746 20200224 78.67455201280613 20200225 78.9973856699437 20200226 78.85262017931608 20200227 79.14524794563822 20200228 78.39209675279315 20200302 77.59581129448863 20200303 77.82259313878247 20200304 77.20900230953139 20200305 77.00213275551326
analyse_all(gtsp, "diff_real_est") # 略微变差,几乎持平
净值预测回测分析: 平均偏离: 0.10633261782727876 标准差偏离: 0.14924600716283906 预测偏差分位: 1% 分位: -0.366 5% 分位: -0.216 25% 分位: -0.085 50% 分位: -0.02 75% 分位: 0.069 95% 分位: 0.21 99% 分位: 0.442 涨跌偏差分析: 预测涨的比实际少: 0.23 预测涨的比实际多: 0.35 预测跌的比实际多: 0.19 预测跌的比实际少: 0.23
gfdqs=\
estimate_table("20190101", "20200305", ("real", {"F162719": 100}), ("est", holdings["162719"]),
("est_bc", {"954528": 95}))
analyse_all(gfdqs, "diff_real_est") #跟踪不错
净值预测回测分析: 平均偏离: 0.0611781800347652 标准差偏离: 0.09176119165721837 预测偏差分位: 1% 分位: -0.315 5% 分位: -0.135 25% 分位: -0.044 50% 分位: -0.003 75% 分位: 0.038 95% 分位: 0.122 99% 分位: 0.231 涨跌偏差分析: 预测涨的比实际少: 0.3 预测涨的比实际多: 0.2 预测跌的比实际多: 0.18 预测跌的比实际少: 0.31
analyse_all(gfdqs, "diff_real_est_bc") #还是实际持仓预测更稳定
净值预测回测分析: 平均偏离: 0.08768082694014524 标准差偏离: 0.13186120013259217 预测偏差分位: 1% 分位: -0.305 5% 分位: -0.224 25% 分位: -0.051 50% 分位: -0.006 75% 分位: 0.058 95% 分位: 0.186 99% 分位: 0.397 涨跌偏差分析: 预测涨的比实际少: 0.11 预测涨的比实际多: 0.4 预测跌的比实际多: 0.36 预测跌的比实际少: 0.13
gfdqs=\
estimate_table("20190101", "20200305", ("real", {"F162719": 100}), ("est", holdings["162719"]),
float_holdings=True, window=4, decay=0.65, smooth=0.2)
20190103 88.91600918473242 20190104 89.10591367122217 20190107 89.39180478855486 20190108 89.84499077145038 20190109 89.99938079562716 20190110 89.1623409970855 20190111 88.75216784917028 20190114 88.20007600624996 20190115 86.789746987543 20190116 90.2418729185157 20190117 90.60441265288051 20190118 90.36783466611232 20190122 91.39648283317071 20190123 90.67407102999461 20190124 91.04481522165392
../lof/predict.py:108: RuntimeWarning: invalid value encountered in double_scalars ratio = realf / estf
20190125 91.03140681188775 20190128 91.89913819974026 20190129 92.1258909657445 20190130 91.48639559954407 20190131 91.90982521834854 20190201 91.9806066996971 20190211 92.59290860059302 20190212 93.00109554011368 20190213 92.1701701704497 20190214 92.17382542781985 20190215 92.58876413611189 20190219 91.1737423579153 20190220 90.64152505523748 20190221 90.0111738377685 20190222 88.26230133939472 20190225 90.99816659429005 20190226 90.00545745473342 20190227 89.31283414486063 20190228 89.39361898651968 20190301 89.46704626254903 20190304 88.06367338421393 20190305 89.39032955826531 20190306 89.62490229415614 20190307 89.64797749456089 20190308 89.79382172652268 20190311 90.39090689931945 20190312 90.58127487386416 20190313 90.65607396851661 20190314 90.8094327973861 20190315 91.4790967546525 20190318 91.47507034537786 20190319 91.82203028256943 20190320 92.93527741378398 20190321 91.78588988079531 20190322 91.77715525508404 20190325 91.41011255709321 20190326 91.26878390167224 20190327 91.76676043258763 20190328 91.63744447603939 20190329 91.41465314783999 20190401 91.1734549613606 20190402 90.98449326453867 20190403 91.06391704100031 20190404 91.57856760611891 20190408 91.95089153235848 20190409 92.07059589960376 20190410 92.4840452267615 20190411 92.80499032029736 20190412 92.63402643229072 20190415 92.44457414044281 20190416 91.95512661943548 20190417 92.35691148437445 20190418 92.99649643418046 20190419 93.39320332164029 20190422 94.57260076801954 20190423 93.95273657144378 20190424 93.5561219509454 20190425 93.14594267576126 20190426 93.01277331121298 20190429 93.23670712364142 20190430 92.161361612901 20190506 93.18249862290885 20190507 93.84169435394791 20190508 91.63624814276767 20190509 91.9862759717356 20190510 92.07274273803058 20190513 90.98816377778331 20190514 92.76175036084494 20190515 93.31218027331714 20190516 93.16320043497342 20190517 93.23964768085499 20190520 94.46199607238005 20190521 94.05767354637179 20190522 94.50943206206175 20190523 96.21863556602142 20190524 93.14209291732854 20190527 93.35974698931001 20190528 92.94786747612903 20190529 91.89242707864844 20190530 94.72846556708498 20190531 92.77893137615197 20190603 92.06701789892242 20190604 92.57648568057984 20190605 92.86506341312453 20190606 91.68649023064924 20190610 91.42205140740472 20190611 91.48015699837416 20190612 91.1282297835265 20190613 90.54862720469905 20190614 91.39162487130832 20190617 90.22623012129887 20190618 89.86342199609146 20190619 89.72724868861857 20190620 89.57170263879385 20190621 89.63577001168407 20190624 90.0811189963516 20190625 89.52854093900159 20190626 89.93018196822332 20190627 88.66851236123608 20190628 88.00961443814707 20190701 87.62547374363709 20190702 86.89711430532913 20190703 86.40761064652375 20190704 84.84452772308812 20190705 87.12502408151342 20190708 87.01940441508877 20190709 87.09485502922499 20190710 88.37897430441585 20190711 89.82865095514289 20190712 88.75807425339123 20190715 87.55505420777834 20190716 87.67903058088154 20190717 88.15001333194625 20190718 87.90049041202032 20190719 87.51238286965939 20190722 88.55780547602282 20190723 88.72656695253464 20190724 89.3360726451651 20190725 89.07841572952785 20190726 89.14493448406094 20190729 89.4546965042221 20190730 88.62912988820055 20190731 88.57065649689338 20190801 89.70094146390763 20190802 90.16761737846277 20190805 90.89366663743134 20190806 89.64067384860748 20190807 91.31324762676587 20190808 91.6523243662846 20190809 92.38369402552617 20190812 92.32800570579184 20190813 90.068971237659 20190814 89.91254846787338 20190815 90.27253804930758 20190816 89.67507435994895 20190819 88.76219737770981 20190820 88.06791388369899 20190821 88.91328391884859 20190822 88.14280691284863 20190823 87.30277813616644 20190826 86.75189094955837 20190827 86.43192716463533 20190828 85.46499452496042 20190829 84.47308990050838 20190830 85.99224429067043 20190902 85.99224429067041 20190903 85.68022035385034 20190904 85.16629165886069 20190905 84.57687011251096 20190906 86.17656629089306 20190909 86.3642698052913 20190910 87.36932567692214 20190911 87.97035981206596 20190912 86.5075766657823 20190916 87.0018386764806 20190917 86.49497613157843 20190918 86.67469700759871 20190919 85.84857746009853 20190920 85.82676462489825 20190923 86.34510873881345 20190924 86.79609715044822 20190925 88.18196956766968 20190926 89.01875125529659 20190927 87.9717483403206 20190930 88.81497740634896 20191008 89.39970111362153 20191009 90.86473716469449 20191010 88.87661894922374 20191011 89.52409256864811 20191014 89.81173844490142 20191015 89.78843070878536 20191016 89.07021510202719 20191017 89.23432066667787 20191018 89.02330794919484 20191021 88.47205631821947 20191022 89.45267203210406 20191023 88.16574692938933 20191024 88.62299334122683 20191025 88.87290083720741 20191028 89.52172889910948 20191029 90.30522676562815 20191030 88.87611236862911 20191031 89.29016647373412 20191101 90.00876771446642 20191104 91.00784762186393 20191105 90.53665086085039 20191106 88.92819835814142 20191107 88.22150189523876 20191108 85.8697734276169 20191111 88.10887303384898 20191112 86.44322568277192 20191113 84.91096553248988 20191114 84.9109655324899 20191115 88.26955120560197 20191118 88.43189297056047 20191119 87.86358859104496 20191120 88.16935700626988 20191121 88.48070116720818 20191122 88.5112492596272 20191125 88.283835035927 20191126 88.56307852491517 20191127 88.30764874607061 20191128 88.50678617056954 20191129 88.78801068225668 20191202 89.76578160085643 20191203 90.84078220237029 20191204 90.86962723956078 20191205 91.95810054155892 20191206 90.06589015332172 20191209 90.37545888396663 20191210 90.86452122997693 20191211 91.77550794497839 20191212 92.41168308712234 20191213 92.81199033792734 20191216 92.72290609036055 20191217 91.8482527668917 20191218 91.99603594540689 20191219 92.18958396635455 20191220 92.2587484685978 20191223 91.61613338899694 20191224 92.58974392085177 20191225 92.85239827812555 20191226 93.49176278032333 20191227 95.10309610840886 20191230 95.85813192290718 20191231 94.53305058175098 20200102 94.69895495204211 20200103 96.3856264925505 20200106 96.59102571121394 20200107 97.34637625110464 20200108 94.86937992162451 20200109 94.84083410608807 20200110 93.97140079598528 20200113 94.00216368410625 20200114 92.55864147625181 20200115 92.16335016194525 20200116 93.20966029969885 20200117 92.90579824517135 20200120 95.90359828583807 20200121 96.11119022207768 20200122 94.46517903144843 20200123 94.41541945563924 20200203 94.25355073142607 20200204 94.01909922750293 20200205 94.00982019241013 20200206 93.71415026424133 20200207 93.52122822620852 20200210 91.42624780619239 20200211 90.31776443889022 20200212 89.87931271056208 20200213 88.82049962608266 20200214 88.57739438284605 20200217 87.11146130268466 20200218 87.18061838827916 20200219 89.97892017150454 20200220 91.53454692672123 20200221 90.2704073717158 20200224 91.25763638944586 20200225 93.45787928113134 20200226 91.81971335066996 20200227 91.95321355764929 20200228 92.29377732340454 20200302 92.48341583791715 20200303 92.31435120318643 20200304 91.81523098055037 20200305 92.56189553445614
analyse_all(gfdqs, "diff_real_est") # 好多了
净值预测回测分析: 平均偏离: 0.06163217662538718 标准差偏离: 0.09118138464047547 预测偏差分位: 1% 分位: -0.243 5% 分位: -0.129 25% 分位: -0.042 50% 分位: -0.0 75% 分位: 0.036 95% 分位: 0.139 99% 分位: 0.262 涨跌偏差分析: 预测涨的比实际少: 0.25 预测涨的比实际多: 0.25 预测跌的比实际多: 0.24 预测跌的比实际少: 0.25
dax = \
estimate_table("20190101", "20200305", ("real", {"F513030": 100}), ("est", holdings["513030"]))
warning: this fund has no data for rate
analyse_all(dax, "diff_real_est") ## 精度也算逆天
净值预测回测分析: 平均偏离: 0.041622922621231295 标准差偏离: 0.052359059264518816 预测偏差分位: 1% 分位: -0.144 5% 分位: -0.094 25% 分位: -0.039 50% 分位: -0.009 75% 分位: 0.028 95% 分位: 0.076 99% 分位: 0.117 涨跌偏差分析: 预测涨的比实际少: 0.34 预测涨的比实际多: 0.22 预测跌的比实际多: 0.09 预测跌的比实际少: 0.36
dax = \
estimate_table("20190101", "20200305", ("real", {"F513030": 100}), ("est", holdings["513030"]),
float_holdings=True, window=4, decay=0.65, smooth=0.2)
warning: this fund has no data for rate 20190103 94.78009282166988 20190104 94.77859353435717 20190107 95.48728734367326 20190108 96.084298394594 20190109 96.84278698858081 20190110 98.02883134656308 20190111 96.02064481323588 20190114 95.56067965358507 20190115 96.94461095834129 20190116 97.93568747908293 20190117 98.74830105252403 20190118 99.99999999999999 20190121 100.00000000000001 20190122 99.25520602010282 20190123 98.73132983442622 20190124 99.73164289331211 20190125 99.12014703094799 20190128 100.0 20190129 98.71870959891163 20190130 99.52890964478524 20190131 100.0 20190201 100.0 20190211 98.30647204233175 20190212 100.0 20190213 98.72454801419771 20190214 98.82092282185205 20190215 98.15301855832794 20190218 98.15301855832791 20190219 97.45060380952742 20190220 97.9621628773251 20190221 98.59695113126624 20190222 97.63908298554 20190225 97.43449712852494 20190226
../lof/predict.py:108: RuntimeWarning: invalid value encountered in double_scalars ratio = realf / estf
97.61444132671564 20190227 95.55117793146698 20190228 97.81686830716028 20190301 96.22838535384197 20190304 95.72622149925418 20190305 94.49782930223165 20190306 96.53710522409419 20190307 96.99365467700743 20190308 95.08092605744481 20190311 96.9464084770509 20190312 96.94640847705092 20190313 97.75713782571884 20190314 96.77678180012111 20190315 96.23683986280824 20190318 96.16314053264566 20190319 95.7980434260631 20190320 96.1256476787763 20190321 96.18723713026354 20190322 97.00970798049883 20190325 97.20544406038857 20190326 97.3645937215426 20190327 96.92755410946017 20190328 96.9275541094602 20190329 97.62900351730342 20190401 97.2347286786578 20190402 96.42409778601245 20190403 96.88954221601738 20190404 95.58475225028378 20190408 95.23491426861764 20190409 96.87464209449004 20190410 96.38905700412252 20190411 96.97890657841288 20190412 94.94709334833033 20190415 95.72652412908437 20190416 96.89188161976895 20190417 96.46007981274032 20190418 96.17123061573854 20190419 95.82234314320978 20190423 96.42530807111596 20190424 94.52559089757902 20190425 96.14081938767062 20190426 97.01273705636288 20190429 95.49506978157983 20190430 94.88345726628387 20190506 95.60284047886027 20190507 93.74273005395062 20190508 96.55483337312722 20190509 97.43595291070248 20190510 95.5045515450427 20190513 95.1944520179961 20190514 96.65334842247654 20190515 95.98848052923668 20190516 95.53819784804608 20190517 95.33446858403634 20190520 95.34482183915368 20190521 95.21036619692825 20190522 95.06953080894326 20190523 95.61460440187447 20190524 94.75302473867994 20190527 93.86935800917585 20190528 95.45709345868568 20190529 95.19314282864448 20190530 96.22990175924397 20190531 96.23017410464982 20190603 96.39400094760254 20190604 96.7853865322902 20190605 97.24779581366874 20190606 98.22434078210183 20190610 98.56624728034673 20190611 99.99999999999999 20190612 99.49961036703192 20190613 97.38430591497305 20190614 96.58982554041545 20190617 95.90434777917193 20190618 94.93538375219435 20190619 96.16081444395115 20190620 96.62689478254933 20190621 96.2694128726075 20190624 97.09345202057386 20190625 97.97084224955476 20190626 97.9708422495548 20190627 98.98157648724627 20190628 99.8210108097451 20190701 99.6766508695825 20190702 99.75618218970037 20190703 98.6641646823095 20190704 98.81410774164351 20190705 98.66996726717171 20190708 98.22030052044595 20190709 97.93073438008194 20190710 98.36828009060274 20190711 98.5521315122385 20190712 98.23885126621015 20190715 98.88903540340047 20190716 97.3681980404896 20190717 99.4874792013687 20190718 98.14497200544892 20190719 96.61076338117371 20190722 97.64254224208943 20190723 97.99564809358029 20190724 97.5147679600899 20190725 100.00000000000001 20190726 98.06891999685885 20190729 98.43066117662585 20190730 97.91287960828778 20190731 97.95777809762602 20190801 97.72530446782768 20190802 98.84445521929288 20190805 99.40802877026103 20190806 100.00000000000001 20190807 97.46354953709637 20190808 98.18805101037725 20190809 98.19679295641212 20190812 98.41498063221503 20190813 97.91275366725313 20190814 97.73292152525113 20190815 97.45667167982654 20190816 96.92431399049198 20190819 97.43368305574629 20190820 97.28117158718834 20190821 97.10598109960088 20190822 97.6673356924443 20190823 97.87892887793656 20190826 97.59922343199653 20190827 97.56818822525014 20190828 96.76578478548782 20190829 97.31078004297198 20190830 98.33899649651026 20190902 98.1764783187476 20190903 97.08107610004548 20190904 96.87804734998274 20190905 97.52274661532353 20190906 97.72466349943717 20190910 97.11855541848477 20190911 97.38079209936629 20190912 97.67816685395242 20190916 98.49713814255246 20190917 99.09371035756645 20190918 100.00000000000001 20190919 100.0 20190920 97.42774397842598 20190923 98.1366210035222 20190924 97.78510887626724 20190925 97.8986319502209 20190926 97.80354895298906 20190927 97.4312182434616 20190930 96.0508757356511 20191008 95.82845571578265 20191009 97.27031399811861 20191010 95.80139869793611 20191011 96.78413503772165 20191014 97.39914609270993 20191015 97.84854065621168 20191016 98.25568301287889 20191017 99.0968897591683 20191018 98.37291184593006 20191021 98.25836789656437 20191023 99.17162692349322 20191024 100.0 20191025 98.20076273600039 20191028 99.62136074505635 20191029 100.0 20191030 100.0 20191031 97.7558805867726 20191101 99.2927745077816 20191104 97.50543514495799 20191105 100.0 20191106 96.69669686243236 20191107 97.08510940364464 20191108 96.62622205227818 20191111 98.18918658488974 20191112 97.41599456184576 20191113 98.01720995591468 20191114 98.62335810929515 20191115 98.48910837075441 20191118 99.43873061785857 20191119 100.00000000000001 20191120 100.0 20191121 99.99999999999997 20191122 100.0 20191125 99.0588574187791 20191126 99.05881445972238 20191127 99.59692291888639 20191128 99.99946376943188 20191202 100.0 20191203 98.74903454963417 20191204 98.76421693887414 20191205 99.23460304182362 20191206 99.54458599736638 20191209 99.19961653506623 20191210 99.62315244277823 20191211 99.3841362313074 20191212 98.92256309074216 20191213 97.90537946707694 20191216 97.90537946707697 20191217 99.2257224282727 20191218 98.79775313581116 20191219 99.24196356204646 20191220 98.9515931660646 20191223 99.57637017021028 20191224 100.0 20191225 100.0 20191226 100.0 20191227 100.0 20191230 100.0 20191231 97.90631297989685 20200102 98.91706688015068 20200103 100.0 20200106 96.97382110844018 20200107 97.20802025510278 20200109 98.169547143952 20200110 98.95559969206595 20200113 97.99768146972252 20200114 98.72622708497684 20200115 99.2099079004798 20200116 98.19184315828225 20200117 98.08960230417706 20200120 100.0 20200121 99.99999999999997 20200122 100.0 20200123 98.18746275388047 20200203 100.00000000000001 20200204 100.0 20200205 97.56785869079555 20200206 97.08449256147311 20200207 97.63128860142466 20200210 97.69459177344295 20200211 96.74728047336077 20200212 97.92858256775992 20200213 98.21629862935094 20200214 98.48035465657686 20200217 97.85603392810339 20200218 98.24191984942075 20200219 98.50439477638129 20200220 96.71011423502081 20200221 98.31466749743984 20200224 99.01661692886306 20200225 98.82089530177683 20200226 98.82089530177686 20200227 97.81369460736299 20200228 98.70494922555493 20200302 99.55684722987077 20200303 99.69041916536989 20200304 99.99999999999999 20200305 100.00000000000001
analyse_all(dax, "diff_real_est") # 在本来就准的基础上,进一步改善
净值预测回测分析: 平均偏离: 0.03750258301849859 标准差偏离: 0.0454188130802292 预测偏差分位: 1% 分位: -0.104 5% 分位: -0.081 25% 分位: -0.04 50% 分位: -0.011 75% 分位: 0.027 95% 分位: 0.063 99% 分位: 0.085 涨跌偏差分析: 预测涨的比实际少: 0.25 预测涨的比实际多: 0.3 预测跌的比实际多: 0.17 预测跌的比实际少: 0.28
dax = \
estimate_table_with_pos("20190101", "20200305", ("real", {"F513030": 100}), ("est", holdings["513030"]))
warning: this fund has no data for rate
analyse_all(dax, "diff_real_est")
净值预测回测分析: 平均偏离: 0.040043320409176374 标准差偏离: 0.05096457858857964 预测偏差分位: 1% 分位: -0.122 5% 分位: -0.092 25% 分位: -0.039 50% 分位: -0.012 75% 分位: 0.027 95% 分位: 0.068 99% 分位: 0.094 涨跌偏差分析: 预测涨的比实际少: 0.29 预测涨的比实际多: 0.27 预测跌的比实际多: 0.13 预测跌的比实际少: 0.31
dax.plot(x="date", y="estpos")
<matplotlib.axes._subplots.AxesSubplot at 0x11eae6080>
gt = estimate_table("20190301", "20200310", ("real", {"F513100": 100}), ("est", {"20": 99}))
analyse_all(gt, "diff_real_est") ##sota 0.025 0.035 98
净值预测回测分析: 平均偏离: 0.02232150761113922 标准差偏离: 0.03331837141011317 预测偏差分位: 1% 分位: -0.136 5% 分位: -0.046 25% 分位: -0.016 50% 分位: -0.001 75% 分位: 0.016 95% 分位: 0.04 99% 分位: 0.062 涨跌偏差分析: 预测涨的比实际少: 0.32 预测涨的比实际多: 0.27 预测跌的比实际多: 0.17 预测跌的比实际少: 0.24
sp500 = \
estimate_table("20190101", "20200305", ("real", {"F513500": 100}), ("est", holdings["513500"]))
warning: this fund has no data for rate
analyse_all(sp500, "diff_real_est") # 仓位设定有问题,导致预测总是实际少
净值预测回测分析: 平均偏离: 0.04710265681733935 标准差偏离: 0.06961432146964162 预测偏差分位: 1% 分位: -0.189 5% 分位: -0.119 25% 分位: -0.019 50% 分位: 0.01 75% 分位: 0.044 95% 分位: 0.094 99% 分位: 0.197 涨跌偏差分析: 预测涨的比实际少: 0.52 预测涨的比实际多: 0.07 预测跌的比实际多: 0.07 预测跌的比实际少: 0.35
sp500 = \
estimate_table("20190101", "20200305", ("real", {"F513500": 100}), ("est", {"166": 99.5}))
analyse_all(sp500, "diff_real_est")
净值预测回测分析: 平均偏离: 0.017746793204680103 标准差偏离: 0.040475675508421405 预测偏差分位: 1% 分位: -0.123 5% 分位: -0.026 25% 分位: -0.005 50% 分位: 0.002 75% 分位: 0.011 95% 分位: 0.033 99% 分位: 0.116 涨跌偏差分析: 预测涨的比实际少: 0.38 预测涨的比实际多: 0.21 预测跌的比实际多: 0.2 预测跌的比实际少: 0.21
nsdq = \
estimate_table("20190101", "20200305", ("real", {"F161130": 100}), ("est", {"20": 94}))
analyse_all(nsdq, "diff_real_est") # 跟踪的很一般
净值预测回测分析: 平均偏离: 0.12216182410912323 标准差偏离: 0.1833932579608965 预测偏差分位: 1% 分位: -0.522 5% 分位: -0.301 25% 分位: -0.073 50% 分位: 0.002 75% 分位: 0.086 95% 分位: 0.243 99% 分位: 0.599 涨跌偏差分析: 预测涨的比实际少: 0.36 预测涨的比实际多: 0.24 预测跌的比实际多: 0.16 预测跌的比实际少: 0.25
nsdq = \
estimate_table("20190101", "20200305", ("real", {"F161130": 100}), ("est", {"20": 94}), float_holdings=True)
20190111 94.98915406894054 20190114 96.18608890311174 20190123 94.94949306632245 20190214 96.1975188414544 20190219 97.75149945255046 20190220 98.30207512761253 20190221 98.69959941828886 20190225 96.81241407707077 20190228 95.67668864004108 20190318 94.29177804471698 20190528 95.43999862226586 20190529 96.63121411967879 20190530 97.76632699876653 20190531 98.64625233615371 20190619 97.12878286893026 20190705 95.4811363698285 20190708 94.32921056786233 20190709 93.30115834909205 20190710 92.3482717770836 20190711 93.48083076088028 20190730 94.51678844585928 20190816 95.5504028193633 20190830 96.63244544044227 20191111 97.48645432229227 20191120 95.66089703264777 20191121 93.27526312650791 20191122 91.87241207960061 20191127 93.11839958565166 20191128 94.50536520402375 20191129 95.91147884041469 20191227 94.75852521267205 20191230 93.90114316430976 20191231 92.80383861833349 20200102 91.99205840992055 20200113 93.52936836733129 20200121 94.94180228458376 20200122 95.93597723699204 20200123 96.98619116621487 20200203 98.57885257476376 20200204 99.5066540094461 20200205 100.0 20200207 98.6085249834941 20200210 96.98733298425819 20200211 94.35890684912344 20200212 92.51632750637836 20200213 90.94041114511042 20200214 88.92634498871585 20200218 87.55549093681263 20200219 86.53506818214238 20200224 88.63790765153645 20200225 91.15118876541946 20200227 92.21369570502361 20200305 93.27145154353816
analyse_all(nsdq, "diff_real_est") ## 考虑仓位调节后,跟踪效果明显加强!!!
净值预测回测分析: 平均偏离: 0.028541250402246907 标准差偏离: 0.058683335315467273 预测偏差分位: 1% 分位: -0.211 5% 分位: -0.087 25% 分位: -0.014 50% 分位: -0.004 75% 分位: 0.009 95% 分位: 0.055 99% 分位: 0.127 涨跌偏差分析: 预测涨的比实际少: 0.23 预测涨的比实际多: 0.37 预测跌的比实际多: 0.16 预测跌的比实际少: 0.24
rj = estimate_table("20191001", "20200305", ("real", {"F513880": 100}), ("est", {"178": 95}))
analyse_all(rj, "diff_real_est")
净值预测回测分析: 平均偏离: 0.06843507292208129 标准差偏离: 0.10318900780357843 预测偏差分位: 1% 分位: -0.312 5% 分位: -0.161 25% 分位: -0.052 50% 分位: -0.002 75% 分位: 0.037 95% 分位: 0.129 99% 分位: 0.329 涨跌偏差分析: 预测涨的比实际少: 0.28 预测涨的比实际多: 0.24 预测跌的比实际多: 0.21 预测跌的比实际少: 0.27
rj = estimate_table("20191001", "20200305", ("real", {"F513880": 100}), ("est", {"178": 95}), float_holdings=True)
warning: this fund has no data for rate 20191009 96.19034492306771 20191015 95.15794452830187 20191023 96.23357657135672 20191024 94.80183359605346 20191025 92.98009826635071 20191028 91.40047248386391 20191104 91.70338822259805 20191105 92.7274733259754 20191106 95.73506377472368 20191112 94.575907008482 20191122 91.47366194430906 20191125 89.50988330484543 20191128 91.92576397505816 20191203 92.6450548611614 20191205 93.85054364222272 20191206 95.9948744769812 20191211 97.34371580286457 20191212 99.08426593617219 20191213 100.0 20191216 100.0 20191218 98.23294822910302 20191219 96.84840584847062 20200106 98.6814957750291 20200107 99.99894362852034 20200110 97.54109915292014 20200113 96.13031552214173 20200115 96.91828338975952 20200116 97.69304602000149 20200122 98.36412010674104 20200123 99.02219811688835 20200204 96.86275714501069 20200205 96.18319493470636 20200207 96.92614378846483 20200212 96.10176675892353 20200213 96.54561333099599 20200214 96.85080241275031 20200218 97.44347834076076 20200219 96.01104431565676 20200302 97.07505224553589
analyse_all(rj, "diff_real_est") # 几乎持平
净值预测回测分析: 平均偏离: 0.07166306068302974 标准差偏离: 0.10592680450275156 预测偏差分位: 1% 分位: -0.31 5% 分位: -0.17 25% 分位: -0.051 50% 分位: 0.0 75% 分位: 0.038 95% 分位: 0.146 99% 分位: 0.33 涨跌偏差分析: 预测涨的比实际少: 0.28 预测涨的比实际多: 0.24 预测跌的比实际多: 0.22 预测跌的比实际少: 0.26
zghl = estimate_table("20190101", "20200305", ("real", {"F164906": 100}), ("est", {"954018": 95}))
analyse_all(zghl, "diff_real_est") # 貌似就是这个指数,但是不太准==
净值预测回测分析: 平均偏离: 0.1386085271800198 标准差偏离: 0.7894710041910674 预测偏差分位: 1% 分位: -0.327 5% 分位: -0.146 25% 分位: -0.054 50% 分位: 0.007 75% 分位: 0.06 95% 分位: 0.162 99% 分位: 0.274 涨跌偏差分析: 预测涨的比实际少: 0.31 预测涨的比实际多: 0.23 预测跌的比实际多: 0.22 预测跌的比实际少: 0.24
zghl = estimate_table("20190101", "20200305", ("real", {"F164906": 100}), ("est", {"954018": 95}),
float_holdings=True, window=4, decay=0.65, smooth=0.2)
20190103 94.84754425577417 20190104 94.67983249363367 20190107 94.46259787435622 20190108 94.46259787435623 20190109 94.13354068565776 20190110 94.36642591768546
../lof/predict.py:108: RuntimeWarning: invalid value encountered in double_scalars ratio = realf / estf
20190111 94.49147061954886 20190114 94.43346170513458 20190115 94.27916358446538 20190116 94.68314956298144 20190117 94.32139439695084 20190118 94.16376316019192 20190121 94.36988883177338 20190122 94.47504929030637 20190123 95.69500017859473 20190124 96.33377286569768 20190125 95.77119626476872 20190128 96.1943401664517 20190129 97.18363260369748 20190130 96.843732981561 20190131 97.21686384364345 20190201 97.39964711079051 20190211 96.52547279870105 20190212 96.00833936817388 20190213 96.00833936817385 20190214 95.5543665466728 20190215 96.19384781379462 20190218 96.50962244694742 20190219 96.61182296429517 20190220 96.03360501869197 20190221 96.05645498220845 20190222 95.994210994571 20190225 95.07402763683615 20190226 95.55019133335887 20190227 96.39992738337689 20190228 96.39992738337686 20190301 97.53340693614994 20190304 99.45632134144516 20190305 100.0 20190306 98.89287144488618 20190307 98.1740385819862 20190308 98.19902942907048 20190311 97.95468811750216 20190312 97.94782817701412 20190313 97.70646648379014 20190314 98.43186313021552 20190315 98.55805266962257 20190318 97.99996880131931 20190319 97.7432406167195 20190320 98.77285217952438 20190321 99.31665688797463 20190322 99.42529879922218 20190325 99.14103754924527 20190326 100.00000000000001 20190327 98.31431528906835 20190328 98.24301378945742 20190329 97.83063334005878 20190401 97.3718863745563 20190402 98.01971760471659 20190403 97.96835700947709 20190404 97.17783924874571 20190408 97.56264545816497 20190409 96.65287579963467 20190410 96.19777225932644 20190411 97.28204608735467 20190412 98.31453435286353 20190415 96.56067896301957 20190416 97.57492259224465 20190417 97.45915964360728 20190418 97.96728727124504 20190419 97.99811940847259 20190422 97.99811940847256 20190423 99.3410650449284 20190424 100.00000000000001 20190425 99.12861856339663 20190426 96.55268124372816 20190429 95.96163817562774 20190430 95.86542089971377 20190506 94.49251321550476 20190507 97.4326552790498 20190508 97.71130194768625 20190509 95.95148385523477 20190510 95.569832435279 20190513 95.45923110117376 20190514 98.207422434096 20190515 98.90424585475986 20190516 96.06364625794559 20190517 96.25089270439324 20190520 96.47373137205122 20190521 94.83500607270672 20190522 95.97065745909568 20190523 95.99911963728317 20190524 95.99737639293629 20190527 96.36076889766954 20190528 96.10941564259933 20190529 95.6588501878214 20190530 96.05600068462729 20190531 94.65192881377051 20190603 93.20420234696067 20190604 94.89383984828916 20190605 92.2521457252949 20190606 91.79552654785317 20190610 92.67873125660722 20190611 93.67007215727935 20190612 94.59629677877155 20190614 91.88550330740337 20190617 92.11701131318692 20190618 91.52612012176382 20190619 90.68407852926623 20190620 89.52687295189364 20190621 90.83390800082823 20190624 90.83390800082822 20190625 89.84728538023293 20190626 90.34223438153305 20190627 90.81312818444404 20190628 90.67667880999049 20190701 90.81031573829492 20190702 89.35994795133495 20190703 88.5020474060669 20190704 89.3167343482618 20190705 86.48394275281282 20190708 86.17407998036447 20190709 82.32481254883389 20190710 83.43974806084621 20190711 85.18163506653772 20190712 83.44664555471917 20190715 84.37810629112221 20190716 85.77197157148099 20190717 85.65220497636524 20190718 85.75320965498314 20190719 85.75914969270981 20190722 87.59046474352698 20190723 87.35565337716814 20190724 87.73655445296187 20190725 87.0375955605157 20190726 88.35964430027592 20190729 88.23217255816084 20190730 87.59562370374776 20190731 87.52899705236587 20190801 87.89857183593841 20190802 89.52466928361176 20190805 89.64354544276881 20190806 90.05657572469586 20190807 90.15233135131261 20190808 90.35113412221517 20190809 90.82180529269945 20190812 88.55530234161871 20190813 89.04143510768914 20190814 87.993107086633 20190815 86.55423438464761 20190816 88.5470643974929 20190819 87.93499931825902 20190820 88.2409102541861 20190821 89.024069184924 20190822 90.0911668639337 20190823 91.33406014812162 20190826 89.84968658642136 20190827 90.49519004059304 20190828 91.13212666817122 20190829 91.17875959306544 20190830 91.10073532831419 20190902 92.57842906130678 20190903 94.3895604728327 20190904 95.57592916209158 20190905 96.0109908619381 20190906 94.99328361356298 20190909 94.67268583958268 20190910 95.63608994229573 20190911 94.96564310012441 20190912 95.9486820997365 20190916 95.18092965523479 20190917 96.918946946902 20190918 97.78966724507153 20190920 100.0 20190923 100.0 20190924 99.38231541389986 20190925 99.43175085317682 20190926 99.18391918101239 20190927 99.55143977398855 20190930 99.32002008376337 20191008 97.94366028721907 20191009 97.13772573477135 20191010 96.01323352869471 20191011 95.77177855354371 20191014 96.20017146344844 20191015 94.925942701588 20191016 94.19719554085432 20191017 92.54095998889414 20191018 95.3751057977783 20191021 95.15930508887702 20191022 94.43445374715597 20191023 95.1167303994734 20191024 96.4757602125075 20191025 96.80532690664567 20191028 97.21217977782274 20191029 96.1974159203353 20191030 96.91849742341661 20191031 96.51634077494994 20191101 96.45075757415894 20191104 95.3425743066461 20191105 95.10636820251601 20191106 95.9486559824377 20191107 95.73264563566086 20191108 95.43100921811403 20191111 96.5643377149036 20191112 97.65670502718488 20191113 98.46715140764711 20191114 98.09733211887567 20191115 99.25775086605705 20191118 97.77925610200356 20191120 97.70182806497057 20191121 96.66328680990222 20191122 95.02726727342771 20191125 95.27416278308358 20191126 93.43595029086988 20191127 94.67657187716914 20191128 93.09617038510225 20191129 92.66506130739333 20191202 94.49636478246923 20191203 94.46237305406143 20191204 94.29781700751661 20191205 91.31507446154491 20191206 94.22791827186359 20191209 94.5988297961521 20191210 95.22417287729739 20191211 94.84081405829484 20191212 96.29458524074457 20191213 96.67325236560475 20191216 96.32949221498619 20191217 96.55894538655909 20191218 96.17796429496624 20191220 97.03926624712518 20191223 94.67753682073952 20191224 94.6775368207395 20191225 92.8276200676847 20191226 93.16794283041598 20191230 95.86700777802857 20191231 92.87376519058849 20200102 91.26425311870491 20200103 95.74281976872118 20200106 95.15666749340929 20200107 93.73331611604708 20200108 93.73331611604709 20200109 94.01548892625658 20200110 96.29361454939777 20200113 95.68664873022165 20200114 96.27777093758903 20200115 98.0295529121203 20200116 95.57901502574164 20200117 94.84854660896245 20200120 94.60570082522743 20200121 93.27338134164432 20200122 96.6383989455763 20200123 97.84849218432007 20200203 95.38470098844154 20200204 97.32860998552896 20200205 96.05208313722135 20200206 96.10234085657407 20200207 96.86519815068448 20200210 97.79863324523302 20200211 97.56931226436764 20200212 98.11639591569448 20200213 99.40083373672516 20200214 97.56792052535293 20200217 97.72890127413469 20200218 97.9809323042748 20200219 98.31233790899216 20200220 99.62610682924152 20200221 100.0 20200224 98.71234247487308 20200225 99.2816893249074 20200226 97.25082447333125 20200227 97.09667310461263 20200228 96.28196790517794 20200302 96.91760259751379 20200303 97.29277658084322 20200304 97.40280856916091 20200305 97.29953483072296
analyse_all(zghl, "diff_real_est") # 几乎一致,稍有一丝丝改善
净值预测回测分析: 平均偏离: 0.134815673182512 标准差偏离: 0.7368848108187612 预测偏差分位: 1% 分位: -0.313 5% 分位: -0.158 25% 分位: -0.045 50% 分位: 0.007 75% 分位: 0.06 95% 分位: 0.163 99% 分位: 0.283 涨跌偏差分析: 预测涨的比实际少: 0.31 预测涨的比实际多: 0.23 预测跌的比实际多: 0.22 预测跌的比实际少: 0.24
from lof.holdings import holdings_160644_19hy, holdings_160644_19s4
from lof.utils import scale_dict
def cutoff(hdict, threhold=1):
d = {}
aim = 0
for k, v in hdict.items():
if v>threhold:
d[k] = v
aim += v
return scale_dict(d.copy(), aim=aim)
d=cutoff(holdings_160644_19hy, threhold=2.5)
hl = estimate_table("20200101", "20200325", ("real", {"F160644": 100}), ("est", d))
analyse_all(hl, "diff_real_est") ## full 190101 200305 0.31 0.429
净值预测回测分析: 平均偏离: 0.4123143196570495 标准差偏离: 0.553320687236681 预测偏差分位: 1% 分位: -1.143 5% 分位: -0.896 25% 分位: -0.105 50% 分位: 0.106 75% 分位: 0.327 95% 分位: 1.062 99% 分位: 1.248 涨跌偏差分析: 预测涨的比实际少: 0.4 预测涨的比实际多: 0.11 预测跌的比实际多: 0.28 预测跌的比实际少: 0.21
hl = estimate_table("20200101", "20200325", ("real", {"F160644": 100}), ("est", holdings_160644_19s4))
/Users/shixin/Documents/newwork/quant finance/xalpha/xalpha/universal.py:146: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy df[k] = df[k].apply(_float)
analyse_all(hl, "diff_real_est") ## 预测效果拙计
净值预测回测分析: 平均偏离: 0.46212656420615356 标准差偏离: 0.61200792219348 预测偏差分位: 1% 分位: -1.432 5% 分位: -0.797 25% 分位: -0.282 50% 分位: 0.046 75% 分位: 0.42 95% 分位: 1.018 99% 分位: 1.482 涨跌偏差分析: 预测涨的比实际少: 0.32 预测涨的比实际多: 0.19 预测跌的比实际多: 0.23 预测跌的比实际少: 0.26
hl = estimate_table_with_pos("20200101", "20200325", ("real", {"F160644": 100}), ("est", holdings_160644_19s4))
hl ## 放弃预测了,调仓估计太猛。。。
date | real | est | estpos | estposld | diff_real_est | |
---|---|---|---|---|---|---|
0 | 2020-01-03 | -0.490913 | -0.437436 | 0.950000 | 0.950000 | -0.053477 |
1 | 2020-01-06 | 0.409363 | 0.463410 | 0.958486 | 0.982353 | -0.054047 |
2 | 2020-01-07 | 0.710851 | 0.724081 | 0.950877 | 0.912900 | -0.013230 |
3 | 2020-01-08 | -0.539755 | -0.903040 | 0.946768 | 0.933502 | 0.363285 |
4 | 2020-01-09 | 2.003757 | 1.670934 | 0.850957 | 0.650991 | 0.332823 |
5 | 2020-01-10 | 0.296706 | 0.666257 | 0.858318 | 1.000000 | -0.369552 |
6 | 2020-01-13 | 1.978986 | 1.623447 | 0.811265 | 0.825773 | 0.355539 |
7 | 2020-01-14 | -1.510453 | -1.376872 | 0.939974 | 0.988934 | -0.133581 |
8 | 2020-01-15 | 0.375787 | 1.022930 | 0.924968 | 1.000000 | -0.647143 |
9 | 2020-01-16 | 0.637458 | 0.740169 | 0.936513 | 0.775245 | -0.102711 |
10 | 2020-01-17 | 1.588578 | 1.295950 | 0.875570 | 0.806556 | 0.292628 |
11 | 2020-01-20 | -0.504751 | -0.618700 | 0.844463 | 1.000000 | 0.113950 |
12 | 2020-01-21 | -2.317716 | -2.038051 | 0.865450 | 0.789285 | -0.279665 |
13 | 2020-01-22 | 2.036660 | 1.043652 | 0.926771 | 0.984209 | 0.993008 |
14 | 2020-01-23 | -1.906188 | -1.640071 | 0.908464 | 1.000000 | -0.266117 |
15 | 2020-02-03 | -2.085665 | -2.137443 | 0.993528 | 1.000000 | 0.051778 |
16 | 2020-02-04 | 4.280964 | 4.281700 | 0.991990 | 0.969460 | -0.000735 |
17 | 2020-02-05 | -0.338780 | -0.292782 | 0.987841 | 0.991819 | -0.045998 |
18 | 2020-02-06 | 1.949610 | 1.596505 | 0.983586 | 0.995367 | 0.353105 |
19 | 2020-02-07 | 0.245170 | 0.178653 | 0.995128 | 1.000000 | 0.066517 |
20 | 2020-02-10 | 0.821757 | -0.197446 | 0.998101 | 1.000000 | 1.019203 |
21 | 2020-02-11 | -0.349311 | 0.486369 | 1.000000 | 1.000000 | -0.835680 |
22 | 2020-02-12 | 0.817916 | 1.643115 | 1.000000 | 1.000000 | -0.825199 |
23 | 2020-02-13 | 0.347692 | -0.482726 | 0.910295 | 0.657998 | 0.830417 |
24 | 2020-02-14 | 0.163619 | 0.209932 | 0.798163 | 0.657998 | -0.046313 |
25 | 2020-02-17 | 0.884020 | 0.126587 | 0.655037 | 0.646709 | 0.757434 |
26 | 2020-02-18 | -0.152395 | 0.354121 | 0.744002 | 1.000000 | -0.506517 |
27 | 2020-02-19 | 1.077936 | 0.931968 | 0.855209 | 1.000000 | 0.145967 |
28 | 2020-02-20 | -0.670064 | -0.663001 | 0.997155 | 0.989154 | -0.007063 |
29 | 2020-02-21 | -1.729216 | -1.651593 | 0.996444 | 1.000000 | -0.077623 |
30 | 2020-02-24 | -1.691966 | -3.385880 | 0.995555 | 1.000000 | 1.693914 |
31 | 2020-02-25 | -0.816286 | -0.194344 | 0.910234 | 0.657766 | -0.621942 |
32 | 2020-02-26 | -0.039663 | -0.466847 | 0.887792 | 1.000000 | 0.427184 |
33 | 2020-02-27 | -2.390636 | -1.154110 | 0.805378 | 0.792746 | -1.236526 |
34 | 2020-02-28 | -0.934959 | -0.687504 | 0.932048 | 1.000000 | -0.247455 |
35 | 2020-03-02 | 2.810833 | 1.930919 | 0.915060 | 1.000000 | 0.879914 |
36 | 2020-03-03 | -2.015566 | -1.356485 | 1.000000 | 1.000000 | -0.659081 |
37 | 2020-03-04 | 2.158859 | 1.774747 | 1.000000 | 1.000000 | 0.384113 |
38 | 2020-03-05 | -0.328947 | -0.523462 | 1.000000 | 1.000000 | 0.194515 |
39 | 2020-03-06 | -1.840184 | -2.591814 | 0.958617 | 0.842229 | 0.751630 |
40 | 2020-03-09 | -4.758023 | -4.730108 | 0.864499 | 0.680617 | -0.027916 |
41 | 2020-03-10 | 3.230638 | 3.458935 | 0.796421 | 0.869601 | -0.228297 |
42 | 2020-03-11 | -1.025907 | -2.372034 | 0.759166 | 0.743855 | 1.346127 |
43 | 2020-03-12 | -5.570097 | -5.043342 | 0.734738 | 0.512619 | -0.526755 |
44 | 2020-03-13 | 4.778800 | 3.829034 | 0.685777 | 0.811478 | 0.949766 |
45 | 2020-03-16 | -8.275132 | -7.262540 | 0.700641 | 0.855880 | -1.012593 |
46 | 2020-03-17 | 2.676511 | 2.971950 | 0.822587 | 0.798329 | -0.295439 |
47 | 2020-03-18 | -3.955056 | -3.986173 | 0.806830 | 0.740815 | 0.031117 |
48 | 2020-03-19 | 1.263453 | 1.095271 | 0.780050 | 0.800531 | 0.168182 |
49 | 2020-03-20 | 1.270795 | 2.773797 | 0.802103 | 0.899829 | -1.503002 |
50 | 2020-03-23 | -1.220625 | -1.159887 | 0.766969 | 0.548452 | -0.060738 |
51 | 2020-03-24 | 5.901374 | 4.866121 | 0.760309 | 0.807132 | 1.035253 |
52 | 2020-03-25 | 1.930207 | 1.363523 | 0.731261 | 0.922063 | 0.566684 |
zghl = estimate_table("20190101", "20200305", ("real", {"F513050": 100}), ("est", {"954018": 95}))
warning: this fund has no data for rate
analyse_all(zghl, "diff_real_est")
净值预测回测分析: 平均偏离: 0.38391103684749234 标准差偏离: 0.9363378102198336 预测偏差分位: 1% 分位: -1.363 5% 分位: -0.55 25% 分位: -0.248 50% 分位: 0.022 75% 分位: 0.231 95% 分位: 0.721 99% 分位: 1.143 涨跌偏差分析: 预测涨的比实际少: 0.27 预测涨的比实际多: 0.27 预测跌的比实际多: 0.25 预测跌的比实际少: 0.22
zghl = estimate_table("20190101", "20200305", ("real", {"F513050": 100}), ("est", {"954018": 95}),
float_holdings=True, window=4, decay=0.65, smooth=0.2)
20190103 95.05977782839773 20190104 95.03628642204424 20190107 95.00674155857332 20190108 95.74219561435346 20190109 95.99842755198297 20190110 97.59106099525168 20190111 99.07877969071899 20190114 97.36853792766284 20190115 98.1092696894567 20190116
../lof/predict.py:108: RuntimeWarning: invalid value encountered in double_scalars ratio = realf / estf
95.72285254006678 20190117 96.21383510605598 20190118 95.65858077897346 20190122 93.07816445028465 20190123 90.86363614676328 20190124 92.77878339063216 20190125 92.13739014461872 20190128 89.6284660878274 20190129 89.69693797830962 20190130 92.5857542878532 20190131 91.45092672149805 20190201 91.94124335324895 20190211 92.0371018674194 20190212 89.29870915293931 20190213 89.47447717491525 20190214 87.99165812818995 20190215 87.61597855139316 20190219 87.66600627505248 20190220 86.0400337947778 20190221 88.46601958527867 20190222 86.99926383760953 20190225 82.53457675462604 20190226 82.50080243747061 20190227 83.4558185113491 20190228 84.01686586110883 20190301 82.7695693068644 20190304 82.2555247690458 20190305 82.52205048273954 20190306 81.04372756885743 20190307 84.26530257624395 20190308 82.39627797270798 20190311 80.30663490728003 20190312 83.63994250604998 20190313 83.91033681139061 20190314 82.40036272535035 20190315 81.15443813899603 20190318 82.4316760655865 20190319 82.43062528297399 20190320 82.31263549050176 20190321 83.23522741325728 20190322 82.69481404212132 20190325 82.42748746581356 20190326 84.17141571007629 20190327 81.54865005551187 20190328 80.26450552233923 20190329 81.85614624228347 20190401 81.11533688446337 20190402 80.13839097027254 20190403 79.79567270560588 20190404 78.5762152717624 20190408 77.95023925708234 20190409 79.25487131491676 20190410 77.44729572082234 20190411 80.7380961740686 20190412 79.1156950818252 20190415 80.72446059746473 20190416 81.32145571705229 20190417 83.01422199807415 20190418 83.83926728334508 20190419 83.8392672833451 20190423 84.77557385087225 20190424 84.95338868537081 20190425 87.68400537896785 20190426 86.87936649112278 20190429 86.47117356320503 20190430 85.40868764846614 20190506 86.25827074462002 20190507 86.7624385281962 20190508 85.8547780434441 20190509 85.57051451933405 20190510 84.9923042796103 20190514 85.11525869227088 20190515 86.3078610426966 20190516 85.93392392771538 20190517 86.76410131296174 20190520 88.33371707943441 20190521 88.50568259963232 20190522 90.37174672234751 20190523 90.29412729770111 20190524 89.72389352611616 20190527 89.72389352611614 20190528 89.95655323669412 20190529 89.21624696048661 20190530 85.67472730646605 20190531 85.77530089128273 20190603 87.56311000687452 20190604 82.09835309661536 20190605 82.71637189960317 20190606 81.63231951903772 20190610 84.29228216107211 20190611 82.6379109666697 20190612 83.14474278748287 20190613 84.56422882188569 20190614 84.69581295701308 20190617 83.38142621776541 20190618 81.94669722485759 20190619 86.49498499092091 20190620 87.7640838333683 20190621 85.93439083374457 20190624 87.72242591927711 20190625 87.76131645428687 20190626 86.27633478077298 20190627 88.1646790049758 20190628 86.6007207864921 20190701 86.60072078649212 20190702 87.73386854682403 20190703 88.19288746896059 20190704 88.1928874689606 20190705 89.60391359719156 20190708 87.0628978537872 20190709 82.75233172231209 20190710 82.89701532378739 20190711 84.34191154131364 20190712 79.12272758451569 20190715 79.4599621815806 20190716 82.16834650203162 20190717 83.20441573929641 20190718 83.09904695021525 20190719 82.63463365340928 20190722 83.95279586096935 20190723 85.05339053245558 20190724 83.1604572884211 20190725 80.52588030638508 20190726 82.57118631425129 20190729 81.99159152912002 20190730 77.50935623268927 20190731 78.65113772816018 20190801 82.57842769657731 20190802 83.55934010716457 20190805 83.5413751670636 20190806 85.09216983475291 20190807 87.61240922912542 20190808 87.25452448472119 20190809 88.83559960616782 20190812 88.30061157599431 20190813 86.35899675851911 20190814 85.17945687534454 20190815 81.23764855246921 20190816 81.43461019409226 20190819 79.15653443562118 20190820 80.12315656818971 20190821 81.81807567656645 20190822 82.5837564693431 20190823 83.21941870076944 20190826 81.59684853720502 20190827 83.19065603220115 20190828 83.4071884900209 20190829 81.38751764622646 20190830 85.70689921886952 20190903 84.2237548903551 20190904 85.54898130359554 20190905 85.10752664525786 20190906 84.03763605596718 20190909 86.01121196784845 20190910 84.21416030435095 20190911 84.06183285446481 20190912 84.02323464629706 20190916 88.18405764125166 20190917 86.57928551027044 20190918 90.68333265218045 20190919 92.09776310736503 20190920 93.7685003378053 20190923 94.03147815048935 20190924 94.68003715568472 20190925 92.95186518263074 20190926 93.5117003821691 20190927 91.17453869647476 20190930 92.82733062548884 20191008 94.78621183177842 20191009 95.2611871531049 20191010 95.23063348382243 20191011 94.56647848241398 20191014 90.84401561913043 20191015 92.31438670731299 20191016 94.44120431894956 20191017 90.52155480326587 20191018 93.19529800875279 20191021 94.11204014846302 20191022 92.83610005210578 20191023 92.49834121782595 20191024 90.27770586936087 20191025 91.73138605308976 20191028 91.86072994053984 20191029 87.23274149642879 20191030 87.73508189206181 20191031 89.48310445306934 20191101 87.22031285479783 20191104 83.97955006033162 20191105 81.91636631847358 20191106 82.40192542548476 20191107 82.68389451085935 20191108 81.05230141493745 20191111 79.43594305037148 20191112 83.23859491378978 20191113 86.13029516039168 20191114 84.41695963228024 20191115 84.93768651112092 20191118 85.11978613042177 20191119 83.85799050312228 20191120 84.08470499537617 20191121 82.93320865350027 20191122 81.65201004711952 20191125 79.4794826782809 20191126 80.41844874835475 20191127 83.5789005432717 20191128 83.81911528061168 20191129 85.32161937649389 20191202 86.38147095792378 20191203 87.14354501109791 20191204 88.95208624052184 20191205 89.23854398015004 20191206 88.46205761887528 20191209 88.2586953645105 20191210 91.94731348751833 20191211 91.62090641732 20191212 91.95315904839013 20191213 93.68637751040286 20191216 96.72634513321702 20191217 96.44815953383288 20191218 96.76184771717477 20191219 95.95011516281228 20191220 99.69631171706749 20191223 98.94366978075793 20191224 96.4219682906778 20191225 96.73416318052396 20191226 99.80538672013364 20191227 97.65238642313246 20191230 97.16957215410612 20191231 95.41032789064424 20200102 99.59368237733851 20200103 100.0 20200106 99.64779759183081 20200107 97.9027972082973 20200108 100.0 20200109 99.1296815397325 20200110 99.99999999999999 20200113 99.98800685455286 20200114 99.99999999999999 20200115 100.00000000000001 20200116 98.15149913014469 20200117 100.00000000000001 20200120 100.0 20200121 97.48352578780965 20200122 100.00000000000001 20200123 99.45845909147945 20200203 96.02921468808881 20200204 95.99412870695689 20200205 95.92786898081465 20200206 93.55927431696175 20200207 94.08673253577456 20200210 92.75119658566639 20200211 92.7137832225167 20200212 94.16679639869157 20200213 93.70070316127686 20200214 92.78063375730268 20200217 90.18083184689543 20200218 88.18081003961643 20200219 89.41963597836396 20200220 91.03837384387094 20200221 90.26912894162687 20200224 90.54881566134199 20200225 94.2030430162798 20200226 93.68335376927017 20200227 92.99305332055847 20200228 92.45730313461226 20200302 93.3586589992516 20200303 91.31696670181668 20200304 91.59432496466799 20200305 90.47912798776595
analyse_all(zghl, "diff_real_est") ## 效果整体不佳,毕竟只是替代指数预测,是用中国互联在预测中概互联
净值预测回测分析: 平均偏离: 0.3729667577703976 标准差偏离: 0.8792921342073579 预测偏差分位: 1% 分位: -1.355 5% 分位: -0.554 25% 分位: -0.236 50% 分位: -0.005 75% 分位: 0.239 95% 分位: 0.717 99% 分位: 1.112 涨跌偏差分析: 预测涨的比实际少: 0.3 预测涨的比实际多: 0.23 预测跌的比实际多: 0.19 预测跌的比实际少: 0.28
zghl = estimate_table("20190101", "20200305", ("real", {"F513050": 100}), ("est", holdings["513050"]))
# 直接按股票持仓回测
warning: this fund has no data for rate
/Users/shixin/Documents/newwork/quant finance/xalpha/xalpha/universal.py:111: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy df[k] = df[k].apply(_float)
analyse_all(zghl, "diff_real_est") # 效果明显好于用中国互联替代预测,但精度还是处于预测的下游
净值预测回测分析: 平均偏离: 0.23933544281723101 标准差偏离: 0.3804756811121884 预测偏差分位: 1% 分位: -0.861 5% 分位: -0.547 25% 分位: -0.179 50% 分位: -0.023 75% 分位: 0.141 95% 分位: 0.481 99% 分位: 0.825 涨跌偏差分析: 预测涨的比实际少: 0.35 预测涨的比实际多: 0.19 预测跌的比实际多: 0.1 预测跌的比实际少: 0.36
fs = estimate_table("20200210", "20200310", ("real", {"F539003": 100}), ("est", {"27": 90}))
analyse_all(fs, "diff_real_est") ## 这也算跟踪?
净值预测回测分析: 平均偏离: 0.5283972528064959 标准差偏离: 0.7386660564739429 预测偏差分位: 1% 分位: -0.488 5% 分位: -0.47 25% 分位: -0.264 50% 分位: 0.242 75% 分位: 0.593 95% 分位: 1.1 99% 分位: 2.244 涨跌偏差分析: 预测涨的比实际少: 0.24 预测涨的比实际多: 0.19 预测跌的比实际多: 0.38 预测跌的比实际少: 0.19
fs = estimate_table("20200210", "20200310", ("real", {"F539003": 100}), ("est", {"27": 90}),
float_holdings=True, window=4, decay=0.65, smooth=0.2)
20200211 90.69251051123888 20200212 91.82780658000073 20200213 92.36374912425 20200214 93.91310721733443 20200217 92.59854258721278 20200218 89.37083140167216 20200219 90.6704612198551 20200220 88.60876119620922 20200221 85.13194068592846 20200224 83.93483146866896 20200225 85.24384764935226 20200226 86.1241074875769 20200227 84.00510647475909 20200228 83.22577290949985 20200302 81.18712928277694 20200303 83.54102738460666 20200304 84.65645864940409 20200305 84.53867383376162 20200306 81.55699857796287 20200309 81.60885728246151 20200310 79.82079347815389
analyse_all(fs, "diff_real_est") # 虽然略有改善,但也是很差
净值预测回测分析: 平均偏离: 0.4695590992529565 标准差偏离: 0.6669560977885407 预测偏差分位: 1% 分位: -0.49 5% 分位: -0.462 25% 分位: -0.313 50% 分位: 0.236 75% 分位: 0.529 95% 分位: 0.779 99% 分位: 2.071 涨跌偏差分析: 预测涨的比实际少: 0.29 预测涨的比实际多: 0.14 预测跌的比实际多: 0.38 预测跌的比实际少: 0.19
hbzx = estimate_table("20190101", "20200310", ("real", {"F501021": 100}), ("est", {".SPHCMSHP": 92}))
analyse_all(hbzx, "diff_real_est")
净值预测回测分析: 平均偏离: 0.12873881115102398 标准差偏离: 0.1794073681739216 预测偏差分位: 1% 分位: -0.487 5% 分位: -0.302 25% 分位: -0.065 50% 分位: 0.02 75% 分位: 0.106 95% 分位: 0.278 99% 分位: 0.516 涨跌偏差分析: 预测涨的比实际少: 0.37 预测涨的比实际多: 0.22 预测跌的比实际多: 0.19 预测跌的比实际少: 0.23
bp = estimate_table("20190301", "20200301", ("real", {"F161128": 100}), ("est", {"962700": 95}) )
analyse_all(bp, "diff_real_est")
净值预测回测分析: 平均偏离: 0.03005764396976259 标准差偏离: 0.04837197894916738 预测偏差分位: 1% 分位: -0.103 5% 分位: -0.069 25% 分位: -0.024 50% 分位: -0.006 75% 分位: 0.014 95% 分位: 0.054 99% 分位: 0.139 涨跌偏差分析: 预测涨的比实际少: 0.09 预测涨的比实际多: 0.49 预测跌的比实际多: 0.32 预测跌的比实际少: 0.1
bp = estimate_table_with_pos("20190301", "20200301", ("real", {"F161128": 100}), ("est", {"962700": 90}) )
analyse_all(bp, "diff_real_est")
净值预测回测分析: 平均偏离: 0.021718872044452726 标准差偏离: 0.041554018312517586 预测偏差分位: 1% 分位: -0.105 5% 分位: -0.049 25% 分位: -0.011 50% 分位: -0.003 75% 分位: 0.008 95% 分位: 0.063 99% 分位: 0.094 涨跌偏差分析: 预测涨的比实际少: 0.27 预测涨的比实际多: 0.31 预测跌的比实际多: 0.14 预测跌的比实际少: 0.28
bp.plot(x="date", y="estpos")
<matplotlib.axes._subplots.AxesSubplot at 0x118a26630>
bp = estimate_table("20200201", "20200325", ("real", {"F161128": 100}), ("est", {"962700": 95}) )
analyse_all(bp, "diff_real_est")
净值预测回测分析: 平均偏离: 0.10711800037902634 标准差偏离: 0.18298292891054715 预测偏差分位: 1% 分位: -0.555 5% 分位: -0.316 25% 分位: -0.071 50% 分位: -0.025 75% 分位: 0.013 95% 分位: 0.151 99% 分位: 0.422 涨跌偏差分析: 预测涨的比实际少: 0.27 预测涨的比实际多: 0.16 预测跌的比实际多: 0.16 预测跌的比实际少: 0.41
bp = estimate_table_with_pos("20200201", "20200325", ("real", {"F161128": 100}), ("est", {"962700": 95}) )
analyse_all(bp, "diff_real_est")
净值预测回测分析: 平均偏离: 0.1178957348472328 标准差偏离: 0.20216755173213008 预测偏差分位: 1% 分位: -0.703 5% 分位: -0.366 25% 分位: -0.094 50% 分位: -0.009 75% 分位: 0.024 95% 分位: 0.143 99% 分位: 0.357 涨跌偏差分析: 预测涨的比实际少: 0.24 预测涨的比实际多: 0.19 预测跌的比实际多: 0.22 预测跌的比实际少: 0.35
bp.plot(x="date", y="estpos")
<matplotlib.axes._subplots.AxesSubplot at 0x11a702b00>
nayq = estimate_table("20190101", "20200310", ("real", {"F163208": 100}), ("est", holdings["163208"]))
analyse_all(nayq, "diff_real_est") # 预测一般,但不是特别差
净值预测回测分析: 平均偏离: 0.13208577471850988 标准差偏离: 0.22785982345126046 预测偏差分位: 1% 分位: -0.362 5% 分位: -0.24 25% 分位: -0.095 50% 分位: -0.009 75% 分位: 0.073 95% 分位: 0.345 99% 分位: 0.565 涨跌偏差分析: 预测涨的比实际少: 0.18 预测涨的比实际多: 0.36 预测跌的比实际多: 0.28 预测跌的比实际少: 0.19
nayq = estimate_table("20190101", "20200310", ("real", {"F163208": 100}), ("est", holdings["163208"]), float_holdings=True)
20190109 90.12407704517783 20190110 90.43832932363975 20190111 90.80916214589467 20190114 91.75772964993098 20190116 89.98302301063102 20190117 88.4585862070784 20190118 86.28018736544071 20190121 84.50811217824572 20190122 83.34368318060753 20190124 82.34778682050076 20190125 81.30324534742645 20190201 79.70574831926663 20190211 78.00607798476406 20190212 76.8562995036019 20190222 76.26879557510891 20190307 76.46274054913988 20190308 78.29745553486339 20190401 79.91683678491083 20190402 81.61377984875169 20190403 82.64121397670125 20190404 83.36494717851892 20190408 84.13441411148536 20190411 83.15843115013897 20190412 82.1806584252174 20190415 80.77963946696569 20190416 79.42267569952918 20190417 78.54651901050448 20190419 77.73982483246162 20190424 78.21042094934018 20190426 78.88767203784838 20190510 78.32777539101468 20190513 77.5732539037026 20190515 79.64755529969275 20190524 78.76129907341681 20190604 78.321881204943 20190610 78.82437355798501 20190624 79.82894043272621 20190625 81.34302770290101 20190626 83.39738153340751 20190627 86.77990017592177 20190628 89.51311825896367 20190701 91.91452345576053 20190702 93.01568648992476 20190703 93.97897479042777 20190704 94.81491555363318 20190709 92.06181050277551 20190710 89.55384466978396 20190711 87.6566678866587 20190712 86.17400811626706 20190719 85.1540603628906 20190730 87.77549339065237 20190816 86.78655093981286 20190826 85.46087969609856 20190827 84.93879289245014 20190828 84.3045814000053 20190829 83.87844609978144 20190903 82.48561309767996 20190904 80.89941917008524 20190905 80.21491517657721 20190910 81.31859885524185 20190911 82.24719155624906 20190917 81.57099244396906 20190918 79.72269941264337 20190920 80.62804020203616 20190923 81.37517041803314 20190926 80.45653014502965 20190927 81.03559854325073 20190930 81.62326079550274 20191008 82.76936863845096 20191009 83.60300121561683 20191015 84.2192018430088 20191016 85.32642634446039 20191017 87.03727766283689 20191018 89.15818302891937 20191021 89.81513059321556 20191023 88.20675728896435 20191025 89.14969462884349 20191028 90.68065938612995 20191101 89.6774197130793 20191105 90.80667036227673 20191106 91.8376412275338 20191107 92.72789229537223 20191206 91.51555982979154 20191209 90.56109445203488 20191210 88.06903453871331 20191211 85.91527583633278 20200102 87.37446718115473 20200103 88.17280363494083 20200109 89.27207857764417 20200110 90.33042928629098 20200113 91.46179927564316 20200114 92.31659597759563 20200121 93.54704289430265 20200203 92.3497035019482 20200204 90.99009906578198 20200210 89.96684581718458 20200214 90.65777701087546 20200219 91.83101987633192 20200227 90.11683767005228 20200228 88.16750247345384 20200302 87.00922331251489 20200303 85.49730309149928 20200304 83.78457319899616 20200306 82.91777998504327
analyse_all(nayq, "diff_real_est") # 预测明显改善
净值预测回测分析: 平均偏离: 0.10036739554677777 标准差偏离: 0.15816222684666867 预测偏差分位: 1% 分位: -0.409 5% 分位: -0.229 25% 分位: -0.071 50% 分位: -0.008 75% 分位: 0.065 95% 分位: 0.195 99% 分位: 0.442 涨跌偏差分析: 预测涨的比实际少: 0.25 预测涨的比实际多: 0.28 预测跌的比实际多: 0.2 预测跌的比实际少: 0.27
by = estimate_table("20190101", "20200310", ("real", {"F161226": 100}), ("est", {"996734": 95}))
analyse_all(by, "diff_real_est") #偏差过大。。。
净值预测回测分析: 平均偏离: 0.44999715731539347 标准差偏离: 0.7661396339450135 预测偏差分位: 1% 分位: -3.04 5% 分位: -1.127 25% 分位: -0.184 50% 分位: -0.004 75% 分位: 0.236 95% 分位: 0.936 99% 分位: 2.563 涨跌偏差分析: 预测涨的比实际少: 0.3 预测涨的比实际多: 0.26 预测跌的比实际多: 0.17 预测跌的比实际少: 0.27
xc = estimate_table("20190301", "20200310", ("real", {"F165513": 100}), ("est", holdings["165513"]))
analyse_all(xc, "diff_real_est")
净值预测回测分析: 平均偏离: 0.1595405294858351 标准差偏离: 0.29326077238744225 预测偏差分位: 1% 分位: -0.808 5% 分位: -0.31 25% 分位: -0.093 50% 分位: -0.013 75% 分位: 0.107 95% 分位: 0.278 99% 分位: 0.975 涨跌偏差分析: 预测涨的比实际少: 0.31 预测涨的比实际多: 0.29 预测跌的比实际多: 0.16 预测跌的比实际少: 0.23
xc = estimate_table("20200101", "20200320", ("real", {"F165513": 100}), ("est", holdings["165513"]))
analyse_all(xc, "diff_real_est")
净值预测回测分析: 平均偏离: 0.4045582553634708 标准差偏离: 0.7429430088592022 预测偏差分位: 1% 分位: -1.638 5% 分位: -0.797 25% 分位: -0.096 50% 分位: 0.042 75% 分位: 0.166 95% 分位: 1.653 99% 分位: 2.427 涨跌偏差分析: 预测涨的比实际少: 0.26 预测涨的比实际多: 0.2 预测跌的比实际多: 0.34 预测跌的比实际少: 0.2
yh = estimate_table("20200101", "20200301", ("real", {"F161815": 100}), ("est", holdings["161815"]))
analyse_all(yh, "diff_real_est")
净值预测回测分析: 平均偏离: 0.15532680999625523 标准差偏离: 0.18436609999596307 预测偏差分位: 1% 分位: -0.313 5% 分位: -0.276 25% 分位: -0.139 50% 分位: -0.01 75% 分位: 0.138 95% 分位: 0.298 99% 分位: 0.316 涨跌偏差分析: 预测涨的比实际少: 0.26 预测涨的比实际多: 0.26 预测跌的比实际多: 0.23 预测跌的比实际少: 0.26
yh = estimate_table("20200101", "20200301", ("real", {"F161815": 100}), ("est", {"1088675": 70}))
analyse_all(yh, "diff_real_est") #0.317, 0.403 70 (0.75, 0.82)
净值预测回测分析: 平均偏离: 0.3171633251037427 标准差偏离: 0.40339062807400033 预测偏差分位: 1% 分位: -0.709 5% 分位: -0.669 25% 分位: -0.211 50% 分位: 0.048 75% 分位: 0.274 95% 分位: 0.65 99% 分位: 0.863 涨跌偏差分析: 预测涨的比实际少: 0.31 预测涨的比实际多: 0.2 预测跌的比实际多: 0.23 预测跌的比实际少: 0.26
from lof.holdings import holdings_161116_19s4
gld = estimate_table("20200101", "20200325", ("real", {"F161116": 100}), ("est", holdings_161116_19s4))
sum([v for _, v in holdings_161116_19s4.items()])
92.86999999999999
analyse_all(gld, "diff_real_est")
净值预测回测分析: 平均偏离: 0.6535647648387035 标准差偏离: 1.3088569523948343 预测偏差分位: 1% 分位: -4.815 5% 分位: -1.463 25% 分位: -0.181 50% 分位: 0.016 75% 分位: 0.27 95% 分位: 1.509 99% 分位: 3.543 涨跌偏差分析: 预测涨的比实际少: 0.28 预测涨的比实际多: 0.28 预测跌的比实际多: 0.26 预测跌的比实际少: 0.17
xa.Compare("F161116", ("commodities/gold","USD"), start="20180101").v()
<matplotlib.axes._subplots.AxesSubplot at 0x122da2470>
xa.Compare("F161116", ("commodities/gold","USD"), start="20180101").corr() # 和黄金相关系数不及格。。。。
F161116 | commodities/gold | |
---|---|---|
F161116 | 1.00000 | 0.59971 |
commodities/gold | 0.59971 | 1.00000 |
gld = estimate_table_with_pos("20191001", "20200225", ("real", {"F161116": 100}), ("est", holdings_161116_19s4),
window=3, decay=0.8)
analyse_all(gld, "diff_real_est") # 0.49, 0.92 20 年 平稳时期
净值预测回测分析: 平均偏离: 0.19134468565719392 标准差偏离: 0.2517831260198441 预测偏差分位: 1% 分位: -0.621 5% 分位: -0.452 25% 分位: -0.105 50% 分位: 0.02 75% 分位: 0.162 95% 分位: 0.447 99% 分位: 0.578 涨跌偏差分析: 预测涨的比实际少: 0.41 预测涨的比实际多: 0.16 预测跌的比实际多: 0.13 预测跌的比实际少: 0.3
gld.plot(x="date", y="estpos")
<matplotlib.axes._subplots.AxesSubplot at 0x1218f17b8>
# from lof.holdings import holdings_160719_19s4
# xa.provider.set_proxy("http://127.0.0.1:8087")
gld = estimate_table("20191001", "20200225", ("real", {"F160719": 100}), ("est", holdings["160719"]),("bcest",
{"commodities/gold":90})
)
analyse_all(gld, "diff_real_est")
print("\n")
analyse_all(gld, "diff_real_bcest") # 还是真实持仓准
净值预测回测分析: 平均偏离: 0.12140793326205283 标准差偏离: 0.15001160103371575 预测偏差分位: 1% 分位: -0.362 5% 分位: -0.24 25% 分位: -0.101 50% 分位: 0.0 75% 分位: 0.097 95% 分位: 0.227 99% 分位: 0.281 涨跌偏差分析: 预测涨的比实际少: 0.33 预测涨的比实际多: 0.28 预测跌的比实际多: 0.17 预测跌的比实际少: 0.22 净值预测回测分析: 平均偏离: 0.17300555954771488 标准差偏离: 0.23733166703645128 预测偏差分位: 1% 分位: -0.629 5% 分位: -0.395 25% 分位: -0.121 50% 分位: -0.005 75% 分位: 0.114 95% 分位: 0.359 99% 分位: 0.449 涨跌偏差分析: 预测涨的比实际少: 0.27 预测涨的比实际多: 0.34 预测跌的比实际多: 0.23 预测跌的比实际少: 0.16
gld = estimate_table_with_pos("20191001", "20200225", ("real", {"F160719": 100}), ("est", holdings_160719_19s4))
analyse_all(gld, "diff_real_est")
净值预测回测分析: 平均偏离: 0.13032855563168053 标准差偏离: 0.16198181760630712 预测偏差分位: 1% 分位: -0.402 5% 分位: -0.301 25% 分位: -0.117 50% 分位: -0.011 75% 分位: 0.112 95% 分位: 0.232 99% 分位: 0.262 涨跌偏差分析: 预测涨的比实际少: 0.37 预测涨的比实际多: 0.25 预测跌的比实际多: 0.1 预测跌的比实际少: 0.29
xa.Compare("F160719", "F159937",("commodities/gold","USD"), start="20180601").v() # 跟不上啊
<matplotlib.axes._subplots.AxesSubplot at 0x11f3a4e10>
xa.Compare("F160719", ("commodities/gold","USD"), start="20180101").corr()
F160719 | commodities/gold | |
---|---|---|
F160719 | 1.000000 | 0.716482 |
commodities/gold | 0.716482 | 1.000000 |
gld.plot(x="date", y="estpos")
<matplotlib.axes._subplots.AxesSubplot at 0x11f212630>
gld = estimate_table_with_pos("20200201", "20200325", ("real", {"F160719": 100}), ("est", holdings_160719_19s4))
analyse_all(gld, "diff_real_est")
净值预测回测分析: 平均偏离: 0.2956363763900901 标准差偏离: 0.4074806463984154 预测偏差分位: 1% 分位: -0.719 5% 分位: -0.664 25% 分位: -0.181 50% 分位: 0.053 75% 分位: 0.203 95% 分位: 0.918 99% 分位: 1.034 涨跌偏差分析: 预测涨的比实际少: 0.43 预测涨的比实际多: 0.19 预测跌的比实际多: 0.14 预测跌的比实际少: 0.24
gld = estimate_table("20200201", "20200325", ("real", {"F160719": 100}), ("est", holdings_160719_19s4))
analyse_all(gld, "diff_real_est") ## 固定仓位好点
净值预测回测分析: 平均偏离: 0.2880271666070501 标准差偏离: 0.3716035221774948 预测偏差分位: 1% 分位: -0.724 5% 分位: -0.658 25% 分位: -0.199 50% 分位: 0.062 75% 分位: 0.197 95% 分位: 0.585 99% 分位: 0.838 涨跌偏差分析: 预测涨的比实际少: 0.43 预测涨的比实际多: 0.19 预测跌的比实际多: 0.19 预测跌的比实际少: 0.19
xa.provider.set_proxy("http://127.0.0.1:8087")
gld = estimate_table(
"20191001",
"20200225",
("real", {"F164701": 100}),
("est", holdings["164701"]),
("bcest", {"commodities/gold": 90}),
)
analyse_all(gld, "diff_real_est")
print("\n")
analyse_all(gld, "diff_real_bcest")
净值预测回测分析: 平均偏离: 0.05400003928906106 标准差偏离: 0.06995691407820687 预测偏差分位: 1% 分位: -0.162 5% 分位: -0.11 25% 分位: -0.054 50% 分位: -0.007 75% 分位: 0.04 95% 分位: 0.115 99% 分位: 0.153 涨跌偏差分析: 预测涨的比实际少: 0.28 预测涨的比实际多: 0.35 预测跌的比实际多: 0.15 预测跌的比实际少: 0.22 净值预测回测分析: 平均偏离: 0.1730015259474371 标准差偏离: 0.21976789496119645 预测偏差分位: 1% 分位: -0.531 5% 分位: -0.399 25% 分位: -0.126 50% 分位: 0.007 75% 分位: 0.13 95% 分位: 0.328 99% 分位: 0.462 涨跌偏差分析: 预测涨的比实际少: 0.33 预测涨的比实际多: 0.3 预测跌的比实际多: 0.19 预测跌的比实际少: 0.17
gld = estimate_table_with_pos(
"20200101",
"20200326",
("real", {"F164701": 100}),
("est", holdings["164701"]),
)
analyse_all(gld, "diff_real_est")
净值预测回测分析: 平均偏离: 0.09796134999036103 标准差偏离: 0.13560257112270027 预测偏差分位: 1% 分位: -0.329 5% 分位: -0.207 25% 分位: -0.076 50% 分位: -0.005 75% 分位: 0.065 95% 分位: 0.199 99% 分位: 0.35 涨跌偏差分析: 预测涨的比实际少: 0.31 预测涨的比实际多: 0.31 预测跌的比实际多: 0.17 预测跌的比实际少: 0.2
gld = estimate_table(
"20200101",
"20200326",
("real", {"F164701": 100}),
("est", holdings["164701"]),
)
analyse_all(gld, "diff_real_est") ## 仓位固定效果略好,类似指数
净值预测回测分析: 平均偏离: 0.07935650312273379 标准差偏离: 0.10888561587283502 预测偏差分位: 1% 分位: -0.199 5% 分位: -0.166 25% 分位: -0.072 50% 分位: -0.002 75% 分位: 0.054 95% 分位: 0.168 99% 分位: 0.314 涨跌偏差分析: 预测涨的比实际少: 0.31 预测涨的比实际多: 0.31 预测跌的比实际多: 0.15 预测跌的比实际少: 0.22
gld.plot(x="date", y="estpos")
<matplotlib.axes._subplots.AxesSubplot at 0x118c7a358>
xa.Compare("F164701", ("commodities/gold", "USD"),"F518880", start="20190601").v()
/Users/shixin/Documents/newwork/quant finance/xalpha/xalpha/universal.py:152: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy df[k] = df[k].apply(_float)
warning: this fund has no data for rate
<matplotlib.axes._subplots.AxesSubplot at 0x118d14c50>
haoil = estimate_table("20190101", "20200310", ("real", {"F160416": 100}), ("est", {"520": 88}))
analyse_all(haoil, "diff_real_est") #
净值预测回测分析: 平均偏离: 0.2207225009490602 标准差偏离: 0.32810089194879843 预测偏差分位: 1% 分位: -0.947 5% 分位: -0.398 25% 分位: -0.143 50% 分位: -0.003 75% 分位: 0.164 95% 分位: 0.437 99% 分位: 0.891 涨跌偏差分析: 预测涨的比实际少: 0.29 预测涨的比实际多: 0.24 预测跌的比实际多: 0.21 预测跌的比实际少: 0.27
haoil = estimate_table("20190101", "20200310", ("real", {"F160416": 100}), ("est", {"520": 90}),
float_holdings=True, window=4, decay=0.8, smooth=0.1)
20190103 90.50509834425999 20190104 90.82870624536903 20190107 91.535888888205 20190108 92.41654224670755 20190109 92.17991901311608 20190110 92.17991901311606 20190111 92.7164042022933 20190114 92.65822489404091 20190115 92.97020645646519 20190116 92.79518057471901
../lof/predict.py:108: RuntimeWarning: invalid value encountered in double_scalars ratio = realf / estf
20190117 92.103604741907 20190118 92.03459796307658 20190121 90.27349561955084 20190122 90.08613925310753 20190123 91.17978608333203 20190124 90.76197559236697 20190125 91.27255334878238 20190128 92.0525419006446 20190129 91.38684703817515 20190130 89.84960019985343 20190131 90.51054912701738 20190201 90.36498736305242 20190211 90.8119470033529 20190212 91.23589487087666 20190213 91.06383651189665 20190214 90.98902848285698 20190215 90.35606177178528 20190218 91.2795696366634 20190219 89.4898384332408 20190220 91.09599097951488 20190221 90.85670749517124 20190225 89.83067289335266 20190226 91.49590556512155 20190227 91.6326915926331 20190228 92.48822014346973 20190301 93.03861525933378 20190304 93.16616174820653 20190305 93.14263875443767 20190306 92.78408411199813 20190307 92.82669355755267 20190308 93.2579193892459 20190311 92.10068500281209 20190312 93.38006401292347 20190313 94.13015407683139 20190314 93.41021298442934 20190315 92.83640735839788 20190318 92.08977541249511 20190319 92.13158482653374 20190320 90.86679807492924 20190321 90.86866184015227 20190322 89.58043509697472 20190325 90.81097889982 20190326 91.12560609275151 20190327 90.89277465334045 20190328 90.38101718087083 20190329 88.94138494342513 20190401 88.59370979444009 20190402 87.69683816074621 20190403 87.63381738832072 20190404 87.63381738832071 20190408 87.8951461922753 20190409 86.80702603884723 20190410 88.11276482205486 20190411 88.12641300824464 20190412 87.50558497665422 20190415 88.20372288699508 20190416 88.1936434284553 20190417 86.52478649632138 20190418 87.307110176129 20190419 87.13153926910458 20190422 85.19432952136434 20190423 85.6129020960085 20190424 85.48866420895983 20190425 86.72157779136711 20190426 87.33008851907341 20190429 87.55726772425349 20190430 88.79617520877422 20190506 89.25427233089717 20190507 89.68375743614882 20190508 89.00021443918286 20190509 88.41153755459015 20190510 88.01910754233185 20190513 87.85347516215957 20190514 88.48708005436518 20190515 88.03428232700273 20190516 87.56471974605549 20190517 88.98743518085922 20190520 88.42976510834158 20190521 89.18894509864806 20190522 88.17184281223186 20190523 87.92333413049504 20190524 87.94787798843137 20190527 87.23488835414634 20190528 87.48940501982051 20190529 86.07874405128766 20190530 86.75344698167413 20190531 86.3839935570655 20190603 85.61117318830532 20190604 86.23799709570281 20190605 86.85963727275232 20190606 86.08642654647626 20190610 85.36470508953887 20190611 86.21669823570906 20190612 86.45416871534225 20190613 87.44373958866774 20190614 86.45919201098664 20190617 86.24941940864389 20190618 86.10617280248921 20190619 86.10617280248923 20190620 86.12243949632605 20190621 86.83760711328678 20190624 86.75923778332378 20190625 86.42646524219136 20190626 86.33079653227477 20190627 85.35911263801857 20190628 84.78543026681429 20190701 85.41954546056478 20190702 85.25642237189852 20190703 84.96592879355889 20190704 86.57062155094583 20190705 85.65100605868604 20190708 84.71362034228807 20190709 84.71362034228808 20190710 85.3081546025561 20190711 84.76765896959735 20190712 85.40229472644268 20190715 86.12171619014437 20190716 86.48711496349632 20190717 86.26575738745473 20190718 87.03367485781625 20190719 87.5872215279559 20190722 88.8959226136795 20190723 88.96221351018589 20190724 89.42129474607752 20190725 88.81690934338008 20190726 89.6719905835847 20190729 90.16024377481357 20190730 89.06729067144208 20190731 89.24059056499058 20190801 88.72186639434418 20190802 87.58881337976358 20190805 86.99289095968687 20190806 87.2998384481279 20190807 87.8885341109098 20190808 86.31722073353819 20190809 87.00877077912452 20190812 88.7982915675762 20190813 88.49464215849727 20190814 88.53106774393507 20190815 89.57326696221973 20190816 88.9779231656083 20190819 88.78170988588118 20190820 89.09759960747891 20190821 88.29183033592405 20190822 89.16106536095047 20190823 88.23895752459663 20190826 88.23895752459661 20190827 89.38341255405878 20190828 89.4298591709258 20190829 90.11316463663965 20190830 91.24822355076181 20190902 91.825554972874 20190903 92.55695922524094 20190904 93.33421972772778 20190905 94.12729627856484 20190906 94.43967516455022 20190909 94.1076928204716 20190910 95.00944025504192 20190912 95.125747311586 20190916 94.98453498238138 20190917 96.1440679298888 20190918 97.00600792975902 20190919 97.09406754831497 20190920 97.80190374241154 20190923 97.84203902446966 20190924 99.08007356756252 20190925 99.1852328267244 20190926 98.45607571176205 20190927 97.949051891103 20190930 98.77491816868152 20191008 97.07099431039796 20191009 96.17945068347935 20191010 96.86923441528225 20191011 95.80391390491592 20191014 94.53562294172865 20191015 94.39468536184093 20191016 93.52282171312504 20191017 91.02129102585891 20191018 90.58313785165556 20191021 90.50188996197195 20191022 91.16349387847323 20191023 91.00780825175636 20191024 90.34851190948733 20191025 90.63433588056502 20191028 90.03988405828002 20191029 90.03988405828004 20191030 90.65944800215546 20191031 90.43775996557866 20191101 90.78849775822502 20191104 89.84885457574065 20191105 90.46270650163989 20191106 90.53559206490758 20191107 91.3069784229231 20191108 91.3306221362368 20191111 92.0973985298537 20191112 92.19608989539786 20191113 92.88648492628086 20191114 93.14273670757 20191115 92.46075373316332 20191118 94.24163650308537 20191119 93.2777659966394 20191120 91.42795930774277 20191121 90.99326088970187 20191122 90.99326088970189 20191125 89.8859326451289 20191126 89.68267495014167 20191127 90.47713664099177 20191128 91.05057519596168 20191129 92.31101254297535 20191202 93.10434309774654 20191203 93.42375440530526 20191204 93.24621253658196 20191205 93.62364160446761 20191206 93.54381265227244 20191209 93.12538620495438 20191210 93.12538620495437 20191211 93.45210857860071 20191212 94.00339224969429 20191213 92.61477817564834 20191216 93.10516364787132 20191217 93.61912572878789 20191218 91.8112844783985 20191219 93.22510566969224 20191220 93.60869339933913 20191223 92.40940464205566 20191225 94.1716025008091 20191226 94.44349555064893 20191227 94.44349555064892 20191230 94.0413420980644 20191231 93.80967570198915 20200102 93.81983037240808 20200103 92.81594512762646 20200106 93.2723065691104 20200107 94.03221765930414 20200108 92.6784697849656 20200109 91.65236614471496 20200110 91.46984357453756 20200113 93.03330261221551 20200114 93.42232452745564 20200115 92.11474931849129 20200116 94.15578234957489 20200117 93.29004801198101 20200120 92.90925905636425 20200121 93.49404455218924 20200122 93.34067750191323 20200123 95.34990074495926 20200203 94.80620100250492 20200204 95.71915387872485 20200205 95.18706976402457 20200206 95.04691042531782 20200207 95.34760562194886 20200210 96.19612947177646 20200211 96.88315194170218 20200212 96.59428883342503 20200213 96.50257092057193 20200214 95.62702318278969 20200217 95.35377487756303 20200218 95.55462090413337 20200219 96.49091226971589 20200220 95.85965479045807 20200221 96.32512218277523 20200224 95.2686613860293 20200225 94.51847132351318 20200226 95.35305734353237 20200227 93.98257223556836 20200228 93.49100058110854 20200302 92.90476665994518 20200303 91.98486854175552 20200304 90.53001207007524 20200305 88.66471074552298 20200306 88.66194273610886 20200309 88.72122981986901 20200310 88.42482746152646
analyse_all(haoil, "diff_real_est") # 替代预测效果很一般,浮动还是固定仓都很一般
净值预测回测分析: 平均偏离: 0.2316632707891009 标准差偏离: 0.3394105216535918 预测偏差分位: 1% 分位: -1.052 5% 分位: -0.411 25% 分位: -0.144 50% 分位: -0.004 75% 分位: 0.177 95% 分位: 0.489 99% 分位: 0.78 涨跌偏差分析: 预测涨的比实际少: 0.28 预测涨的比实际多: 0.24 预测跌的比实际多: 0.22 预测跌的比实际少: 0.26
haoil = estimate_table("20190101", "20200310", ("real", {"F160416": 100}), ("est", {"SP5475707.2": 90}),
)
analyse_all(haoil, "diff_real_est") # 还得是真实指数更靠谱
净值预测回测分析: 平均偏离: 0.10336445485275023 标准差偏离: 0.13535653835908334 预测偏差分位: 1% 分位: -0.34 5% 分位: -0.193 25% 分位: -0.07 50% 分位: 0.008 75% 分位: 0.094 95% 分位: 0.216 99% 分位: 0.346 涨跌偏差分析: 预测涨的比实际少: 0.33 预测涨的比实际多: 0.2 预测跌的比实际多: 0.2 预测跌的比实际少: 0.28
haoil = estimate_table("20200301", "20200320", ("real", {"F160416": 100}), ("est", {"SP5475707.2": 70}),
)
analyse_all(haoil, "diff_real_est")
净值预测回测分析: 平均偏离: 1.5458828787019208 标准差偏离: 2.2193865761580227 预测偏差分位: 1% 分位: -3.947 5% 分位: -3.401 25% 分位: -0.44 50% 分位: -0.025 75% 分位: 0.615 95% 分位: 3.82 99% 分位: 4.444 涨跌偏差分析: 预测涨的比实际少: 0.21 预测涨的比实际多: 0.21 预测跌的比实际多: 0.29 预测跌的比实际少: 0.29
haoil = estimate_table("20200201", "20200320", ("real", {"F160416": 100}), ("est", {"SP5475707.2": 90}),
float_holdings=True)
20200204 89.92132688797578 20200205 90.06334525873646 20200206 90.19716053487194 20200207 90.57167851883504 20200210 90.99863370283633 20200211 90.40637636173336 20200212 90.14666893597725 20200213 88.01434330854921 20200214 88.22330047103434 20200217 88.04983662440671 20200218 86.34798651510654 20200219 87.96547680684772 20200220 89.1531185122205 20200221 87.64133100549118 20200224 87.20815211376346 20200225 87.7095658833157 20200226 89.82478211996911 20200227 88.10417162396567 20200228 87.98874272050105 20200302 86.78685978084376 20200303 86.45581600882458 20200304 84.37036271557437 20200305 85.16944967796478 20200306 87.03338491656781 20200309 86.41159528899864 20200310 86.03814854417271 20200311 86.32912099962472 20200312 85.6553009674062 20200313 83.38038616628951 20200316 79.80389912361746
../lof/predict.py:105: RuntimeWarning: invalid value encountered in double_scalars ratio = realf / estf
20200318 77.50509134092462 20200319 76.34762184544849 20200320 74.85602023693059
analyse_all(haoil, "diff_real_est") # 浮动仓没啥区别
净值预测回测分析: 平均偏离: 0.7649936814692555 标准差偏离: 1.7554039097702738 预测偏差分位: 1% 分位: -2.996 5% 分位: -0.715 25% 分位: -0.131 50% 分位: 0.016 75% 分位: 0.171 95% 分位: 4.636 99% 分位: 5.914 涨跌偏差分析: 预测涨的比实际少: 0.21 预测涨的比实际多: 0.18 预测跌的比实际多: 0.35 预测跌的比实际少: 0.26
jsyy=\
estimate_table("20190101", "20200317", ("real", {"F160723": 100}), ("est", holdings["160723"]), float_holdings=True)
## 79
20190103 98.998011150905 20190104 99.13433420433203 20190107 99.32331625311409 20190108 99.691902335422 20190109 100.0 20190110 96.92323174237059 20190111 97.1019425677503 20190114 97.5798411421276 20190115 97.71198255900691 20190116 97.1365365226914 20190117 97.38370239104492 20190118 97.51482135780323 20190121 97.60080362836045 20190122 97.10693694452911 20190123 97.23149449432826 20190124 97.53955577789067 20190125 98.20240064688953 20190128 98.26865065565114 20190129 98.81678255580867 20190130 97.40995861312274 20190131 98.8094389139682 20190201 98.11076085899879 20190211 97.91622660360242 20190212 98.20763959378486 20190213 98.76761533484756 20190214 98.6675843689077 20190215 98.05451454065582 20190218 97.71865178050366 20190219 97.8648340189131 20190220 97.92001467231408 20190221 96.41545072018585 20190222 95.86874509375932 20190225 95.51552799111002 20190226 97.865549765494 20190227 97.59879461047939 20190228 96.73549848722095 20190301 96.20679499080065 20190304 95.85050798768998 20190305 96.51710148399373 20190306 95.61531279063942 20190307 95.66181972720395 20190308 94.72172054794582 20190311 93.9921122067115 20190312 96.17728390389627 20190313 96.0067728258366 20190315 95.67427416353172 20190318 95.46123788995901
../lof/predict.py:108: RuntimeWarning: invalid value encountered in double_scalars ratio = realf / estf
20190319 95.1823615790699 20190320 95.66499966773793 20190321 95.14401647761864 20190322 95.0787269888551 20190325 94.40631744470342 20190326 95.74319976611889 20190327 95.80710111535338 20190328 95.95306841568566 20190329 95.87594618583041 20190401 96.44916835341517 20190402 96.87302063893122 20190403 98.24421746283546 20190404 97.59128615658129 20190408 98.31583290523628 20190409 99.90732477935885 20190410 99.99999999999999 20190411 98.68787251255692 20190412 97.34673348581427 20190415 97.2926635429898 20190416 97.89089542143985 20190417 98.23154904127846 20190418 96.87378692011481 20190419 96.69495672079772 20190422 96.25902590607667 20190423 94.42659451670407 20190424 98.10505120134621 20190425 97.70517227339467 20190426 98.21451987169664 20190429 97.26345179763447 20190430 98.65915169666056 20190506 97.61449240768482 20190507 97.2977714978251 20190508 97.81026821104214 20190509 97.97235278262788 20190510 98.8559335122075 20190513 97.97518550008287 20190514 98.35958747108299 20190515 98.36869906298752 20190516 99.01922292874488 20190517 99.89230245681202 20190520 97.35840373036316 20190521 96.84323777675381 20190522 96.84646288396627 20190523 96.50890065020837 20190524 98.39651681317189 20190527 97.11202449990235 20190528 97.15961760424284 20190529 96.9985054040193 20190530 97.20529782025815 20190531 97.89772466077034 20190603 95.079237765087 20190604 95.75290210754066 20190605 96.01968274324392 20190606 95.81048099152949 20190610 94.98136508328678 20190611 94.20318773114975 20190612 94.44339651679529 20190613 94.19148058071984 20190614 92.9379228037595 20190617 94.00042623111857 20190618 94.24416076009172 20190619 93.4132032592097 20190620 92.8223672868978 20190621 92.37342837172643 20190624 91.47635593269149 20190625 89.25362619144192 20190626 91.47233177671075 20190627 89.40642342224649 20190628 88.28495959967823 20190701 89.3444740708391 20190702 90.06218221505881 20190703 89.64570545529821 20190704 92.88990049732777 20190705 92.29320472932389 20190708 91.12421316846637 20190709 91.28087180009618 20190710 91.92788546614084 20190711 93.62059133685248 20190712 93.29561262952542 20190715 94.7558660199951 20190716 93.53204995197756 20190717 94.09948818980956 20190718 96.01824685816759 20190719 95.95742492427736 20190722 95.68681905905666 20190723 94.36680325744679 20190724 94.66744514978143 20190725 95.07721739168942 20190726 96.87711465361386 20190729 98.11890520654437 20190730 100.0 20190731 99.3555310842712 20190801 99.47957830769663 20190802 97.84513427110195 20190805 97.07791330055645 20190806 96.03227117899891 20190807 96.18023890674618 20190808 94.23935606901794 20190809 95.5659993844393 20190812 97.4663116439416 20190813 96.06179517624155 20190814 96.57520203559808 20190815 96.5837420381924 20190816 97.42808920027322 20190819 96.09047594994678 20190820 95.69052441102286 20190821 95.37520169452475 20190822 95.69774799171263 20190823 95.52803287061758 20190826 93.20233767253818 20190827 94.73963104862277 20190828 97.12583705526335 20190829 95.53457129707357 20190830 92.62723217081087 20190902 95.97458604177231 20190903 96.09954329979504 20190904 97.17555481580845 20190905 94.72846498210103 20190906 93.82102615444056 20190909 95.48942347992543 20190910 95.48942347992542 20190911 93.93109014843797 20190912 92.87227328428004 20190916 92.82763954420929 20190917 95.05172818042588 20190918 95.66522549388704 20190919 94.97137076149995 20190920 94.89758030683682 20190923 95.35327569296126 20190924 96.12807822056983 20190925 96.07143459210988 20190926 95.62876525332753 20190927 96.37452982149532 20190930 95.82632855518864 20191008 95.58258509084742 20191009 95.51647171053949 20191010 98.75380108403442 20191011 96.57224720225125 20191014 96.16056531671477 20191015 95.92361382183962 20191016 97.00539284221581 20191017 96.4163749468147 20191018 97.18488314718402 20191021 98.76533592556817 20191022 97.65038273599167 20191023 98.90548275492318 20191024 96.03856269068196 20191025 95.83833679420597 20191028 97.47213656899109 20191029 98.39597653617899 20191030 97.94376532681734 20191031 98.56215756545743 20191101 99.8644462313409 20191104 99.71077007647662 20191105 98.38987774096073 20191106 98.50019898578817 20191107 98.71994329203514 20191108 98.07941609276853 20191111 98.30947550140378 20191112 96.29207528652896 20191113 95.4489895446411 20191114 93.77118450152136 20191115 95.42906128769687 20191118 93.8036393762692 20191119 96.03667924505316 20191120 95.01186755973671 20191121 94.99148227234855 20191122 95.61349385380937 20191125 95.21423320422713 20191126 95.41771136568647 20191127 95.32893924051837 20191128 94.24915052590671 20191129 93.13442767845231 20191202 96.75327034159778 20191203 95.7835577443651 20191204 92.229167032951 20191205 95.23872790031396 20191206 95.47172505864944 20191209 97.62344767179466 20191210 94.81442142615144 20191211 93.89301870968062 20191212 95.08271148654492 20191213 95.13511739070832 20191216 95.66472951451563 20191217 95.18153411410228 20191218 94.9297240039535 20191219 95.03964740682322 20191220 94.65778492170817 20191223 96.11805102606617 20191224 96.24667671564349 20191225 96.76143547635543 20191226 96.83354468740856 20191227 97.14742116380549 20191230 94.9070401904274 20191231 94.48877472816402 20200102 92.89774670667182 20200103 95.88497133063368 20200106 95.36128333799104 20200107 93.91622045827137 20200108 92.6461331742685 20200109 93.87868873285372 20200110 94.00948840341148 20200113 93.74344025838313 20200114 93.07473386900506 20200115 92.60551133395929 20200116 93.2920440864787 20200117 93.25273098995116 20200120 93.13583617742864 20200121 94.45195360331434 20200122 95.23552796261242 20200123 96.79584526015093 20200203 97.08368785797877 20200204 95.50110891193394 20200205 94.50247498171147 20200206 94.39689122447953 20200207 93.96526660306931 20200210 92.57102186527716 20200211 91.0391361879991 20200212 89.14273465512001 20200213 90.5652291149273 20200214 89.16266672913679 20200217 87.02366960314446 20200218 86.93582921411002 20200219 86.38452345836215 20200220 86.62199334935622 20200221 85.98498661524492 20200224 89.05230555956066 20200225 87.06568691203636 20200226 87.46321280180729 20200227 86.5990387450102 20200228 87.17118123229557 20200302 86.71389630767548 20200303 86.27409887893536 20200304 86.41934747150903 20200305 87.00902316848197 20200306 88.61143638018807 20200309 90.00418632128252 20200310 88.15993653658315 20200311 87.30281952012277 20200312 86.23128722334133 20200313 84.58437537616395 20200316 81.49969255269298 20200317 79.22571829980201
jsyy=\
estimate_table("20200101", "20200317", ("real", {"F160723": 100}), ("est", holdings["160723"]), float_holdings=True)
# 79 所以有两个月足够了
analyse_all(jsyy, "diff_real_est") # 在仓位巨变的情况下,浮动仓位预测准确性大幅上升
净值预测回测分析: 平均偏离: 0.3102546169014142 标准差偏离: 0.6595336841739304 预测偏差分位: 1% 分位: -1.383 5% 分位: -1.068 25% 分位: -0.07 50% 分位: -0.007 75% 分位: 0.069 95% 分位: 0.951 99% 分位: 2.482 涨跌偏差分析: 预测涨的比实际少: 0.06 预测涨的比实际多: 0.3 预测跌的比实际多: 0.34 预测跌的比实际少: 0.3
jsyy=\
estimate_table("20200101", "20200317", ("real", {"F160723": 100}), ("est", holdings["160723"]))
analyse_all(jsyy, "diff_real_est")
净值预测回测分析: 平均偏离: 0.5139938766873343 标准差偏离: 1.0234878205057947 预测偏差分位: 1% 分位: -1.97 5% 分位: -0.574 25% 分位: -0.079 50% 分位: 0.05 75% 分位: 0.25 95% 分位: 1.717 99% 分位: 3.925 涨跌偏差分析: 预测涨的比实际少: 0.02 预测涨的比实际多: 0.34 预测跌的比实际多: 0.53 预测跌的比实际少: 0.11
jsyy=\
estimate_table("20200101", "20200317", ("real", {"F160723": 100}),
("est", holdings["160723"]), float_holdings=True, window=4, decay=0.65, smooth=0.6)
20200103 98.40920667693318 20200106 97.64853514951241 20200107 96.62523556281496 20200108 95.15401686708452 20200109 93.0823814868199 20200110 93.36443546932975 20200113 93.11216029576838 20200114 91.27013083061011 20200115 92.13050838334848 20200116 91.59142148486188 20200117 91.06325234221197 20200120 96.16646465319991 20200121 99.84629272643697 20200122 99.99999999999999 20200123 100.00000000000003 20200203 96.29661772963763 20200204 92.26665630352407 20200205 93.50409512818467 20200206 89.94835094303721 20200207 85.88148943436546 20200210 83.4463279162062 20200211 78.78541461154028 20200212 83.13619172865776 20200213 79.95897641886171 20200214 76.81147545782146 20200217 75.55999514008762 20200218 76.4799222401603 20200219 75.6369490310907 20200220 75.623577001374 20200221 86.32632227780684 20200224 83.59299231836273 20200225 85.43632206375919 20200226 83.91234854574422 20200227 86.9878170010383 20200228 83.10182678087973 20200302 82.47401722714106 20200303 83.38535021874404 20200304 86.13184793730808 20200305 90.40385072561526 20200306 95.30399675201251 20200309 91.9347292911875 20200310 89.8274011221422 20200311 86.08059020624405 20200312 80.03967138790792 20200313 70.07407118095644 20200316 64.53761156946534 20200317 62.16971931143681
analyse_all(jsyy, "diff_real_est") # 2020 SOTA 0.26 0.53 window=3, decay=0.7, smooth=0.6
#2019 SOTA 0.09 0.135 window=4, decay=0.65, smooth=0.2
净值预测回测分析: 平均偏离: 0.3030265858700378 标准差偏离: 0.6305422687037667 预测偏差分位: 1% 分位: -1.448 5% 分位: -0.29 25% 分位: -0.071 50% 分位: -0.006 75% 分位: 0.111 95% 分位: 1.297 99% 分位: 2.282 涨跌偏差分析: 预测涨的比实际少: 0.11 预测涨的比实际多: 0.26 预测跌的比实际多: 0.38 预测跌的比实际少: 0.26
nfyy=\
estimate_table("20200101", "20200318", ("real", {"F501018": 100}),
("est", holdings["501018"]), float_holdings=True, window=4, decay=0.65, smooth=0.2)
20200103 93.45665232707752 20200106 93.51791428472517 20200107 93.5520801679379 20200108 93.66822034810588 20200109 93.30883359089702 20200110 92.58731785691867 20200113 91.69075781817025 20200114 89.60552641051424 20200115 88.69825004960039 20200116 88.2053335988735 20200117 87.91742762155187 20200120 90.39437404355327 20200121 91.96893139296083 20200122 92.95730053434691 20200123 95.8519902704606 20200203 95.26656120900611 20200204 92.29800617194215 20200205 92.37057678788422 20200206 90.81708290720317 20200207 87.13760505389847 20200210 85.85909407258791 20200211 82.9640141805221 20200212 83.06792602093726 20200213 79.60366262516155 20200214 77.42560684761044 20200217 76.49471700799037 20200218 77.00261147197513 20200219 77.75406518838784 20200220 80.54352300480772 20200221 82.47785873914064 20200224 81.06854400234613 20200225 83.30907585665355 20200226 82.21006333173082 20200227 84.45929050470774 20200228 88.04085927902116 20200302 86.828801560879 20200303 87.06842714989392 20200304 87.20393662286146 20200305 85.5647472762889 20200306 86.10974509660099 20200309 85.65184977513036 20200310 83.40536321307515 20200311 80.80832316630564 20200312 78.9781298662052 20200313 73.55456223974132 20200316 73.28924350637332 20200317 74.40963966730133 20200318 75.86500405727163
analyse_all(nfyy, "diff_real_est") # SOTA 2019 0.129 0.188 window = 5
# SOTA 2020 0.41 0.83 window=5/4, decay=0.65, smooth=0.2
净值预测回测分析: 平均偏离: 0.42852850497808187 标准差偏离: 0.870009892781402 预测偏差分位: 1% 分位: -3.637 5% 分位: -0.763 25% 分位: -0.219 50% 分位: 0.006 75% 分位: 0.123 95% 分位: 0.825 99% 分位: 1.407 涨跌偏差分析: 预测涨的比实际少: 0.19 预测涨的比实际多: 0.21 预测跌的比实际多: 0.35 预测跌的比实际少: 0.25
jsyy=\
estimate_table_with_pos("20200101", "20200317", ("real", {"F160723": 100}),
("est", holdings["160723"]), pos=0.94, window=3, decay=0.8)
analyse_all(jsyy, "diff_real_est")
# 20200101 0317 SOTA 0.26 0.53 window=3, decay=0.7, smooth=0.6
#2019 SOTA 0.09 0.135 window=4, decay=0.65, smooth=0.2
## new approach 2020 0.254 0.487 window=3, decay=0.8
净值预测回测分析: 平均偏离: 0.2538763052395668 标准差偏离: 0.4870486171347755 预测偏差分位: 1% 分位: -1.225 5% 分位: -0.249 25% 分位: -0.056 50% 分位: -0.005 75% 分位: 0.132 95% 分位: 1.166 99% 分位: 1.507 涨跌偏差分析: 预测涨的比实际少: 0.15 预测涨的比实际多: 0.21 预测跌的比实际多: 0.34 预测跌的比实际少: 0.3
def smooth_pos(r, e, o):
pos = r/e
if pos <= 0:
return o
if pos > 1:
pos = 1
elif pos < 0.5:
pos = pos ** 0.6
if abs(r) < 1:
pos = (pos + (3-3*abs(r))*o)/(4-3*abs(r))
return pos
gtsp=\
estimate_table_with_pos("20200101", "20200324", ("real", {"F160216": 100}),
("est", holdings["160216"]), pos=0.94, window=3, decay=0.8, smooth=smooth_pos)
analyse_all(gtsp, "diff_real_est") # 0.283 0.49
净值预测回测分析: 平均偏离: 0.28339514803858534 标准差偏离: 0.4909722047292374 预测偏差分位: 1% 分位: -1.736 5% 分位: -0.682 25% 分位: -0.152 50% 分位: -0.053 75% 分位: 0.166 95% 分位: 0.498 99% 分位: 1.167 涨跌偏差分析: 预测涨的比实际少: 0.1 预测涨的比实际多: 0.27 预测跌的比实际多: 0.33 预测跌的比实际少: 0.31
gtsp.plot(x="date", y=["estpos", "estposld"])
<matplotlib.axes._subplots.AxesSubplot at 0x12016a438>
gtsp=\
estimate_table_with_pos("20190101", "20200305", ("real", {"F160216": 100}), ("est", holdings["160216"]),
pos=0.9, window=3, decay=0.8, smooth=smooth_pos)
# 0.09 0.13
analyse_all(gtsp, "diff_real_est")
净值预测回测分析: 平均偏离: 0.11508219285292358 标准差偏离: 0.15686811933164138 预测偏差分位: 1% 分位: -0.348 5% 分位: -0.22 25% 分位: -0.105 50% 分位: -0.022 75% 分位: 0.079 95% 分位: 0.225 99% 分位: 0.403 涨跌偏差分析: 预测涨的比实际少: 0.23 预测涨的比实际多: 0.35 预测跌的比实际多: 0.19 预测跌的比实际少: 0.23