#获取绩效数据
import requests
import json
def request_position_by_api_key(uname, key,notebook_id):
position_url = 'https://bigquant.com/bigwebapi/algo_info/plot_return'
r = requests.get(url=position_url, params={
'owner': uname,
'api_key': key,
'notebook_id': notebook_id,
})
return json.loads(r.text)
uname = ''
key = ''
notebook_id = ''
data = request_position_by_api_key(uname,key,notebook_id )
data
{'data': {'algo_info_plot_return': {'after_shared_cum_return_plot': [],
'algo_name': '可视化AI策略',
'annual_return': -0.0335536934630337,
'before_shared_cum_return_plot': [],
'benchmark_cum_return_plot': [[1659888000000.0, 0.0],
[1659974400000.0, 0.0019806623458862305],
[1660060800000.0, -0.009242236614227295],
[1660147200000.0, 0.010961294174194336],
[1660233600000.0, 0.010384798049926758],
[1660492800000.0, 0.009065508842468262],
[1660579200000.0, 0.007174968719482422],
[1660665600000.0, 0.01660621166229248],
[1660752000000.0, 0.007720470428466797],
[1660838400000.0, 0.0007230043411254883],
[1661097600000.0, 0.008033037185668945],
[1661184000000.0, 0.0031359195709228516],
[1661270400000.0, -0.01582789421081543],
[1661356800000.0, -0.0076746344566345215],
[1661443200000.0, -0.009770631790161133],
[1661702400000.0, -0.014115989208221436],
[1661788800000.0, -0.017425179481506348],
[1661875200000.0, -0.01669079065322876],
[1661961600000.0, -0.02515268325805664],
[1662048000000.0, -0.030004680156707764],
[1662307200000.0, -0.03197824954986572],
[1662393600000.0, -0.023093700408935547],
[1662480000000.0, -0.022442162036895752],
[1662566400000.0, -0.026612579822540283],
[1662652800000.0, -0.013087332248687744],
[1662998400000.0, -0.00891023874282837],
[1663084800000.0, -0.01994079351425171],
[1663171200000.0, -0.0291595458984375],
[1663257600000.0, -0.05192577838897705],
[1663516800000.0, -0.05305469036102295],
[1663603200000.0, -0.05188876390457153],
[1663689600000.0, -0.058904409408569336],
[1663776000000.0, -0.06719517707824707],
[1663862400000.0, -0.070406973361969],
[1664121600000.0, -0.07507038116455078],
[1664208000000.0, -0.06166231632232666],
[1664294400000.0, -0.07699114084243774],
[1664380800000.0, -0.07736873626708984],
[1664467200000.0, -0.08273464441299438],
[1665331200000.0, -0.10297262668609619],
[1665417600000.0, -0.10134530067443848],
[1665504000000.0, -0.08769571781158447],
[1665590400000.0, -0.09532177448272705],
[1665676800000.0, -0.07367390394210815],
[1665936000000.0, -0.07272356748580933],
[1666022400000.0, -0.0746871829032898],
[1666108800000.0, -0.0895695686340332],
[1666195200000.0, -0.09477835893630981],
[1666281600000.0, -0.0976794958114624],
[1666540800000.0, -0.12408202886581421],
[1666627200000.0, -0.12550896406173706],
[1666713600000.0, -0.11840963363647461],
[1666800000000.0, -0.1246192455291748],
[1666886400000.0, -0.14627152681350708],
[1667145600000.0, -0.15413689613342285],
[1667232000000.0, -0.12388920783996582],
[1667318400000.0, -0.11337053775787354],
[1667404800000.0, -0.12058079242706299],
[1667491200000.0, -0.09182578325271606],
[1667750400000.0, -0.08986759185791016],
[1667836800000.0, -0.09612882137298584],
[1667923200000.0, -0.1045796275138855],
[1668009600000.0, -0.11147010326385498],
[1668096000000.0, -0.0866994857788086],
[1668355200000.0, -0.08535468578338623],
[1668441600000.0, -0.0680079460144043],
[1668528000000.0, -0.07562178373336792],
[1668614400000.0, -0.07941287755966187],
[1668700800000.0, -0.08353418111801147],
[1668960000000.0, -0.0913550853729248],
[1669046400000.0, -0.09124761819839478],
[1669132800000.0, -0.09029388427734375],
[1669219200000.0, -0.09432488679885864],
[1669305600000.0, -0.08975207805633545],
[1669564800000.0, -0.10000598430633545],
[1669651200000.0, -0.07223892211914062],
[1669737600000.0, -0.07112652063369751],
[1669824000000.0, -0.0610659122467041],
[1669910400000.0, -0.06680858135223389],
[1670169600000.0, -0.04850411415100098],
[1670256000000.0, -0.04336392879486084],
[1670342400000.0, -0.04571610689163208],
[1670428800000.0, -0.04553800821304321],
[1670515200000.0, -0.03612053394317627],
[1670774400000.0, -0.04692089557647705],
[1670860800000.0, -0.048792123794555664],
[1670947200000.0, -0.04657316207885742],
[1671033600000.0, -0.04727160930633545],
[1671120000000.0, -0.04673194885253906],
[1671379200000.0, -0.06143909692764282],
[1671465600000.0, -0.07691699266433716],
[1671552000000.0, -0.07655030488967896],
[1671638400000.0, -0.07522684335708618],
[1671724800000.0, -0.07710951566696167],
[1671984000000.0, -0.07342827320098877],
[1672070400000.0, -0.06273287534713745],
[1672156800000.0, -0.06673222780227661],
[1672243200000.0, -0.07024317979812622],
[1672329600000.0, -0.06664317846298218],
[1672675200000.0, -0.06272202730178833],
[1672761600000.0, -0.061504900455474854],
[1672848000000.0, -0.04327225685119629],
[1672934400000.0, -0.04030442237854004],
[1673193600000.0, -0.03253436088562012],
[1673280000000.0, -0.03148472309112549],
[1673366400000.0, -0.03327900171279907]],
'benchmark_symbol': '000300.HIX',
'capital_base': 10000000.0,
'count': '',
'cum_return': -0.0142535177586297,
'cum_return_plot': [[1659888000000.0, 0.0],
[1659974400000.0, 0.0012419673156961798],
[1660060800000.0, 0.004439095028559678],
[1660147200000.0, 0.012193600207440928],
[1660233600000.0, 0.005255140720253065],
[1660492800000.0, 0.0007182150088265539],
[1660579200000.0, 0.00947545470900219],
[1660665600000.0, 0.00850319941586908],
[1660752000000.0, 0.016776168587192147],
[1660838400000.0, 0.0009680229128729552],
[1661097600000.0, 0.0012527628462847323],
[1661184000000.0, 0.012009801290507242],
[1661270400000.0, -0.02309957968611829],
[1661356800000.0, -0.025015288994437085],
[1661443200000.0, -0.03353664058749937],
[1661702400000.0, -0.01568788316896204],
[1661788800000.0, -0.016939449584399722],
[1661875200000.0, -0.04799048755076975],
[1661961600000.0, -0.049320147566132434],
[1662048000000.0, -0.0261008391454272],
[1662307200000.0, -0.03597192676360086],
[1662393600000.0, -0.008209122085404582],
[1662480000000.0, 0.019990111143084244],
[1662566400000.0, 0.01343714209313821],
[1662652800000.0, 0.004145066273180768],
[1662998400000.0, 0.021239225142114983],
[1663084800000.0, 0.028445371441239865],
[1663171200000.0, -0.01838488376713302],
[1663257600000.0, -0.03490193466679491],
[1663516800000.0, -0.05015526403484084],
[1663603200000.0, -0.01906731638667453],
[1663689600000.0, -0.024502092825576662],
[1663776000000.0, -0.011448755073511042],
[1663862400000.0, -0.04157477648937702],
[1664121600000.0, -0.02294904504319001],
[1664208000000.0, -0.0059058586849424985],
[1664294400000.0, -0.051429795953878386],
[1664380800000.0, -0.05585190886597037],
[1664467200000.0, -0.07940447727738395],
[1665331200000.0, -0.10825931096464414],
[1665417600000.0, -0.09858687674412392],
[1665504000000.0, -0.05815337539403178],
[1665590400000.0, -0.04169208006227017],
[1665676800000.0, -0.023770247793609277],
[1665936000000.0, -0.019504501308536717],
[1666022400000.0, -0.011898782386355847],
[1666108800000.0, -0.030847688198620455],
[1666195200000.0, -0.020787379724896325],
[1666281600000.0, -0.02461798182298988],
[1666540800000.0, -0.04052051636509523],
[1666627200000.0, -0.031943453691309694],
[1666713600000.0, -0.020719669062911533],
[1666800000000.0, -0.04277192783244252],
[1666886400000.0, -0.08570332823745459],
[1667145600000.0, -0.07687015843133647],
[1667232000000.0, -0.05233389758481476],
[1667318400000.0, -0.02423436340022851],
[1667404800000.0, -0.00822710887124557],
[1667491200000.0, 0.004407632151017524],
[1667750400000.0, 0.005802117064294591],
[1667836800000.0, 0.007198474361628853],
[1667923200000.0, 0.007761849052157253],
[1668009600000.0, 0.008965334502480552],
[1668096000000.0, 0.008182158987284452],
[1668355200000.0, 0.0054308228481516245],
[1668441600000.0, 0.014366782498825528],
[1668528000000.0, 0.018210531452635674],
[1668614400000.0, 0.02294729920750335],
[1668700800000.0, 0.013590093105585873],
[1668960000000.0, 0.01077668634106107],
[1669046400000.0, -0.0009127589180862531],
[1669132800000.0, -0.020032457038642093],
[1669219200000.0, -0.015824706082827596],
[1669305600000.0, -0.02178856375655085],
[1669564800000.0, -0.027090159754609315],
[1669651200000.0, -0.018464535630147903],
[1669737600000.0, -0.018948893880572727],
[1669824000000.0, -0.018014860665570946],
[1669910400000.0, -0.00961728638999015],
[1670169600000.0, 0.0016217672259975224],
[1670256000000.0, -0.006990468198782019],
[1670342400000.0, -0.0075311356147525835],
[1670428800000.0, -0.010496767539447359],
[1670515200000.0, -0.012611584619532712],
[1670774400000.0, -0.016900816104529426],
[1670860800000.0, -0.001939836223055236],
[1670947200000.0, 0.003759516887316853],
[1671033600000.0, 0.003117794006486051],
[1671120000000.0, -0.006819457958265766],
[1671379200000.0, -0.03172030198731702],
[1671465600000.0, -0.034296693339477664],
[1671552000000.0, -0.041928135524735975],
[1671638400000.0, -0.058231522512094305],
[1671724800000.0, -0.06671701041044444],
[1671984000000.0, -0.014167513530936465],
[1672070400000.0, -0.0016293103580594063],
[1672156800000.0, -0.009519787374601699],
[1672243200000.0, -0.00809709672238268],
[1672329600000.0, -0.018334909515574576],
[1672675200000.0, 0.010678992920298315],
[1672761600000.0, -0.0029798972321068867],
[1672848000000.0, 0.009009687204713747],
[1672934400000.0, -0.001962008970057592],
[1673193600000.0, 0.011650839368589409],
[1673280000000.0, 0.01468461424398143],
[1673366400000.0, -0.014253517758629658]],
'description': '',
'error_data': '',
'first_date': '2022-08-08 00:00:00',
'grade': -15,
'hold_percent_plot': [[1659888000000.0, 0.0],
[1659974400000.0, 0.2017],
[1660060800000.0, 0.4034],
[1660147200000.0, 0.6065],
[1660233600000.0, 0.806],
[1660492800000.0, 0.9885],
[1660579200000.0, 0.7447],
[1660665600000.0, 0.8087],
[1660752000000.0, 0.7832],
[1660838400000.0, 0.7824],
[1661097600000.0, 0.7869],
[1661184000000.0, 0.7758],
[1661270400000.0, 0.7787],
[1661356800000.0, 0.7753],
[1661443200000.0, 0.7952],
[1661702400000.0, 0.7813],
[1661788800000.0, 0.781],
[1661875200000.0, 0.7632],
[1661961600000.0, 0.7949],
[1662048000000.0, 0.7943],
[1662307200000.0, 0.7908],
[1662393600000.0, 0.7826],
[1662480000000.0, 0.7882],
[1662566400000.0, 0.7967],
[1662652800000.0, 0.7669],
[1662998400000.0, 0.7535],
[1663084800000.0, 0.744],
[1663171200000.0, 0.7985],
[1663257600000.0, 0.7394],
[1663516800000.0, 0.7958],
[1663603200000.0, 0.7868],
[1663689600000.0, 0.7915],
[1663776000000.0, 0.7629],
[1663862400000.0, 0.7604],
[1664121600000.0, 0.787],
[1664208000000.0, 0.7936],
[1664294400000.0, 0.6998],
[1664380800000.0, 0.7915],
[1664467200000.0, 0.7389],
[1665331200000.0, 0.7415],
[1665417600000.0, 0.6613],
[1665504000000.0, 0.6737],
[1665590400000.0, 0.6691],
[1665676800000.0, 0.7351],
[1665936000000.0, 0.7475],
[1666022400000.0, 0.709],
[1666108800000.0, 0.7767],
[1666195200000.0, 0.7788],
[1666281600000.0, 0.6202],
[1666540800000.0, 0.681],
[1666627200000.0, 0.5828],
[1666713600000.0, 0.7464],
[1666800000000.0, 0.7922],
[1666886400000.0, 0.8072],
[1667145600000.0, 0.7892],
[1667232000000.0, 0.8171],
[1667318400000.0, 0.6935],
[1667404800000.0, 0.7734],
[1667491200000.0, 0.7184],
[1667750400000.0, 0.698],
[1667836800000.0, 0.6544],
[1667923200000.0, 0.7491],
[1668009600000.0, 0.7158],
[1668096000000.0, 0.7262],
[1668355200000.0, 0.7505],
[1668441600000.0, 0.8074],
[1668528000000.0, 0.7635],
[1668614400000.0, 0.7097],
[1668700800000.0, 0.5965],
[1668960000000.0, 0.666],
[1669046400000.0, 0.7213],
[1669132800000.0, 0.5845],
[1669219200000.0, 0.7851],
[1669305600000.0, 0.7435],
[1669564800000.0, 0.7829],
[1669651200000.0, 0.7918],
[1669737600000.0, 0.8075],
[1669824000000.0, 0.7026],
[1669910400000.0, 0.7683],
[1670169600000.0, 0.7859],
[1670256000000.0, 0.7746],
[1670342400000.0, 0.8268],
[1670428800000.0, 0.8026],
[1670515200000.0, 0.7909],
[1670774400000.0, 0.7106],
[1670860800000.0, 0.7766],
[1670947200000.0, 0.6431],
[1671033600000.0, 0.7645],
[1671120000000.0, 0.8025],
[1671379200000.0, 0.7718],
[1671465600000.0, 0.757],
[1671552000000.0, 0.7923],
[1671638400000.0, 0.7634],
[1671724800000.0, 0.7971],
[1671984000000.0, 0.7898],
[1672070400000.0, 0.769],
[1672156800000.0, 0.7978],
[1672243200000.0, 0.7711],
[1672329600000.0, 0.7442],
[1672675200000.0, 0.7961],
[1672761600000.0, 0.7829],
[1672848000000.0, 0.7151],
[1672934400000.0, 0.7686],
[1673193600000.0, 0.7724],
[1673280000000.0, 0.7575],
[1673366400000.0, 0.7465]],
'id': 89124,
'index': '',
'keys': '',
'max_drawdown': 0.132923620643369,
'month_return': 0.00269280901588181,
'owner': 'yvan0617',
'relative_cum_return_plot': [[1659888000000.0, 0.0],
[1659974400000.0, -0.0007386950301899731],
[1660060800000.0, 0.013644548322647498],
[1660147200000.0, 0.000799883686344538],
[1660233600000.0, -0.005489771685183498],
[1660492800000.0, -0.008679642056261372],
[1660579200000.0, 0.0018526510229608384],
[1660665600000.0, -0.008493666986453041],
[1660752000000.0, 0.008306226633188807],
[1660838400000.0, -0.0003687006388614078],
[1661097600000.0, -0.007386399166911528],
[1661184000000.0, 0.008100032323774986],
[1661270400000.0, -0.007816050097101845],
[1661356800000.0, -0.01798136347384105],
[1661443200000.0, -0.024489964088758587],
[1661702400000.0, -0.002193366044391465],
[1661788800000.0, -0.00011288151262411894],
[1661875200000.0, -0.032442733212840746],
[1661961600000.0, -0.02546776972670406],
[1662048000000.0, 0.0031845354088595457],
[1662307200000.0, -0.004942281362704581],
[1662393600000.0, 0.014581451826584102],
[1662480000000.0, 0.04275201578729426],
[1662566400000.0, 0.04050135848601233],
[1662652800000.0, 0.016503336548200798],
[1662998400000.0, 0.02950554202347888],
[1663084800000.0, 0.04822812952006017],
[1663171200000.0, 0.010357037732822594],
[1663257600000.0, 0.017049261044797648],
[1663516800000.0, 0.002185888942076719],
[1663603200000.0, 0.033752995174707756],
[1663689600000.0, 0.035674932575438634],
[1663776000000.0, 0.05865749454010527],
[1663862400000.0, 0.03004011785533156],
[1664121600000.0, 0.055224902331860726],
[1664208000000.0, 0.0583348503509471],
[1664294400000.0, 0.027158164993015266],
[1664380800000.0, 0.0227898871225507],
[1664467200000.0, 0.003223951136258174],
[1665331200000.0, -0.006086239776897817],
[1665417600000.0, 0.0028913433041144465],
[1665504000000.0, 0.032643895950184465],
[1665590400000.0, 0.05932410644816111],
[1665676800000.0, 0.05378673483872576],
[1665936000000.0, 0.057310274471545464],
[1666022400000.0, 0.06775082397395149],
[1666108800000.0, 0.06444777593595075],
[1666195200000.0, 0.08158726160345209],
[1666281600000.0, 0.08082254753008788],
[1666540800000.0, 0.09482654922813105],
[1666627200000.0, 0.10639707166355472],
[1666713600000.0, 0.110242796029967],
[1666800000000.0, 0.09306157327456654],
[1666886400000.0, 0.0710746311497017],
[1667145600000.0, 0.09129023003901571],
[1667232000000.0, 0.08127204426043],
[1667318400000.0, 0.10035131290560884],
[1667404800000.0, 0.12735065746115315],
[1667491200000.0, 0.10485079427106392],
[1667750400000.0, 0.10400246857464612],
[1667836800000.0, 0.11313011061165779],
[1667923200000.0, 0.1241600249842838],
[1668009600000.0, 0.1341531975632948],
[1668096000000.0, 0.10165469525899229],
[1668355200000.0, 0.09702612761048757],
[1668441600000.0, 0.08597046825658516],
[1668528000000.0, 0.09895729826908428],
[1668614400000.0, 0.10857678809276994],
[1668700800000.0, 0.10339920294413818],
[1668960000000.0, 0.1097526642769302],
[1669046400000.0, 0.09678732758242536],
[1669132800000.0, 0.07464685046963382],
[1669219200000.0, 0.08402300427358811],
[1669305600000.0, 0.07198079619711506],
[1669564800000.0, 0.0782468205598017],
[1669651200000.0, 0.05453973507203358],
[1669737600000.0, 0.052754940132845984],
[1669824000000.0, 0.04235487491583356],
[1669910400000.0, 0.057643915842584326],
[1670169600000.0, 0.04890067059017045],
[1670256000000.0, 0.03421553044990899],
[1670342400000.0, 0.03619535803655194],
[1670428800000.0, 0.03290567952953016],
[1670515200000.0, 0.020506638994076898],
[1670774400000.0, 0.027508415925736163],
[1670860800000.0, 0.045162582508075255],
[1670947200000.0, 0.04869277303035435],
[1671033600000.0, 0.048790559176279835],
[1671120000000.0, 0.037806782481087264],
[1671379200000.0, 0.027798500398328985],
[1671465600000.0, 0.04201326317370113],
[1671552000000.0, 0.03336485186176885],
[1671638400000.0, 0.014299224917668774],
[1671724800000.0, 0.007225154461465433],
[1671984000000.0, 0.059920405872879945],
[1672070400000.0, 0.061166249347058166],
[1672156800000.0, 0.05730751125684175],
[1672243200000.0, 0.06280377958394623],
[1672329600000.0, 0.047719014756008704],
[1672675200000.0, 0.0742835927925829],
[1672761600000.0, 0.058370074858343335],
[1672848000000.0, 0.05053589988557694],
[1672934400000.0, 0.035853825249111626],
[1673193600000.0, 0.041595799076769024],
[1673280000000.0, 0.04358930973800934],
[1673366400000.0, 0.015760196331340293]],
'run_date': '2023-01-11 00:00:00',
'run_status': 0,
'shared': 0,
'shared_date': '',
'shelf_status': 0,
'six_month_return': -1.0,
'subscribe_limit': 50,
'subscribe_price': 500,
'subscribed': 0,
'tags': '重仓;分散持股;中频轮仓;',
'ten_days_return': -0.0246690698565792,
'three_month_return': 0.0286323025540929,
'today_return': -0.0284965213808768,
'unique_id': 'yvan0617_f61dd07e-17be-11ed-a0cc-52c587c2b1a9',
'update_time': '2023-01-11 17:34:33',
'week_return': -0.0113073151636816,
'win_ratio': 0.439153439,
'year_return': -1.0,
'viewtype': 'guest',
'notebook_id': 'f61dd07e-17be-11ed-a0cc-52c587c2b1a9',
'rank': -1,
'notify_email': 0,
'notify_wechat': 0,
'market_type': 0,
'status': 0,
'festival_price_info': {},
'new_come_price_info': {},
'min_month_price': '',
'original_month_price': '',
'selection_price': {},
'platform_guide_price': {'gp1': 0.0,
'gp2': 500.0,
'gp3': 800.0,
'gp4': 1000.0,
'gp5': 1500.0,
'gp6': '',
'gp7': '',
'id': 1,
'to_dict': '',
'update_time': '2018-06-30',
'zn1': 1.0,
'zn12': 0.65,
'zn18': '',
'zn24': '',
'zn3': 0.9,
'zn6': 0.8},
'subscriber_notify_wechat': '',
'subscriber_notify_email': '',
'subscriber_limit_time': '',
'subscriber_left_days': 0,
'subscriber_active_status': '',
'subscribe_by_price': '',
'follow_status': 0,
'want_subscribe_status': 0,
'benchmark_name': '沪深300',
'max_drawdown_stamp': [[1663084800000.0, 0.028445371441239865],
[1665331200000.0, -0.10825931096464414]],
'alpha': 0.04239611346721195,
'beta': 0.7130259055456739,
'volatility': 0.278034037994995,
'sharpe': -0.09120692845349214,
'ir': 0.017137071038052655}},
'message': 'SUCCESSED',
'code': '200',
'metadata': {'tabelname': 'algo_info_plot_return',
'limit': 1,
'page': 1,
'total_count': None,
'count': 68,
'viewtype': None,
'start_date': None,
'end_date': None,
'date_type': None,
'key_words': None,
'key_words_type': None}}
#转换成需要的数据
from datetime import datetime
r = data['data']['algo_info_plot_return']['cum_return_plot']
r
[[1659888000000.0, 0.0], [1659974400000.0, 0.0012419673156961798], [1660060800000.0, 0.004439095028559678], [1660147200000.0, 0.012193600207440928], [1660233600000.0, 0.005255140720253065], [1660492800000.0, 0.0007182150088265539], [1660579200000.0, 0.00947545470900219], [1660665600000.0, 0.00850319941586908], [1660752000000.0, 0.016776168587192147], [1660838400000.0, 0.0009680229128729552], [1661097600000.0, 0.0012527628462847323], [1661184000000.0, 0.012009801290507242], [1661270400000.0, -0.02309957968611829], [1661356800000.0, -0.025015288994437085], [1661443200000.0, -0.03353664058749937], [1661702400000.0, -0.01568788316896204], [1661788800000.0, -0.016939449584399722], [1661875200000.0, -0.04799048755076975], [1661961600000.0, -0.049320147566132434], [1662048000000.0, -0.0261008391454272], [1662307200000.0, -0.03597192676360086], [1662393600000.0, -0.008209122085404582], [1662480000000.0, 0.019990111143084244], [1662566400000.0, 0.01343714209313821], [1662652800000.0, 0.004145066273180768], [1662998400000.0, 0.021239225142114983], [1663084800000.0, 0.028445371441239865], [1663171200000.0, -0.01838488376713302], [1663257600000.0, -0.03490193466679491], [1663516800000.0, -0.05015526403484084], [1663603200000.0, -0.01906731638667453], [1663689600000.0, -0.024502092825576662], [1663776000000.0, -0.011448755073511042], [1663862400000.0, -0.04157477648937702], [1664121600000.0, -0.02294904504319001], [1664208000000.0, -0.0059058586849424985], [1664294400000.0, -0.051429795953878386], [1664380800000.0, -0.05585190886597037], [1664467200000.0, -0.07940447727738395], [1665331200000.0, -0.10825931096464414], [1665417600000.0, -0.09858687674412392], [1665504000000.0, -0.05815337539403178], [1665590400000.0, -0.04169208006227017], [1665676800000.0, -0.023770247793609277], [1665936000000.0, -0.019504501308536717], [1666022400000.0, -0.011898782386355847], [1666108800000.0, -0.030847688198620455], [1666195200000.0, -0.020787379724896325], [1666281600000.0, -0.02461798182298988], [1666540800000.0, -0.04052051636509523], [1666627200000.0, -0.031943453691309694], [1666713600000.0, -0.020719669062911533], [1666800000000.0, -0.04277192783244252], [1666886400000.0, -0.08570332823745459], [1667145600000.0, -0.07687015843133647], [1667232000000.0, -0.05233389758481476], [1667318400000.0, -0.02423436340022851], [1667404800000.0, -0.00822710887124557], [1667491200000.0, 0.004407632151017524], [1667750400000.0, 0.005802117064294591], [1667836800000.0, 0.007198474361628853], [1667923200000.0, 0.007761849052157253], [1668009600000.0, 0.008965334502480552], [1668096000000.0, 0.008182158987284452], [1668355200000.0, 0.0054308228481516245], [1668441600000.0, 0.014366782498825528], [1668528000000.0, 0.018210531452635674], [1668614400000.0, 0.02294729920750335], [1668700800000.0, 0.013590093105585873], [1668960000000.0, 0.01077668634106107], [1669046400000.0, -0.0009127589180862531], [1669132800000.0, -0.020032457038642093], [1669219200000.0, -0.015824706082827596], [1669305600000.0, -0.02178856375655085], [1669564800000.0, -0.027090159754609315], [1669651200000.0, -0.018464535630147903], [1669737600000.0, -0.018948893880572727], [1669824000000.0, -0.018014860665570946], [1669910400000.0, -0.00961728638999015], [1670169600000.0, 0.0016217672259975224], [1670256000000.0, -0.006990468198782019], [1670342400000.0, -0.0075311356147525835], [1670428800000.0, -0.010496767539447359], [1670515200000.0, -0.012611584619532712], [1670774400000.0, -0.016900816104529426], [1670860800000.0, -0.001939836223055236], [1670947200000.0, 0.003759516887316853], [1671033600000.0, 0.003117794006486051], [1671120000000.0, -0.006819457958265766], [1671379200000.0, -0.03172030198731702], [1671465600000.0, -0.034296693339477664], [1671552000000.0, -0.041928135524735975], [1671638400000.0, -0.058231522512094305], [1671724800000.0, -0.06671701041044444], [1671984000000.0, -0.014167513530936465], [1672070400000.0, -0.0016293103580594063], [1672156800000.0, -0.009519787374601699], [1672243200000.0, -0.00809709672238268], [1672329600000.0, -0.018334909515574576], [1672675200000.0, 0.010678992920298315], [1672761600000.0, -0.0029798972321068867], [1672848000000.0, 0.009009687204713747], [1672934400000.0, -0.001962008970057592], [1673193600000.0, 0.011650839368589409], [1673280000000.0, 0.01468461424398143], [1673366400000.0, -0.014253517758629658]]
#转成dataframe
df = pd.DataFrame(r,columns=['date','cum_returns'])
df
| date | cum_returns | |
|---|---|---|
| 0 | 1.659888e+12 | 0.000000 |
| 1 | 1.659974e+12 | 0.001242 |
| 2 | 1.660061e+12 | 0.004439 |
| 3 | 1.660147e+12 | 0.012194 |
| 4 | 1.660234e+12 | 0.005255 |
| ... | ... | ... |
| 101 | 1.672848e+12 | 0.009010 |
| 102 | 1.672934e+12 | -0.001962 |
| 103 | 1.673194e+12 | 0.011651 |
| 104 | 1.673280e+12 | 0.014685 |
| 105 | 1.673366e+12 | -0.014254 |
106 rows × 2 columns
#转换时间
df['date'] = df['date'].apply(lambda x:datetime.fromtimestamp(x/10**3))
df
| date | cum_returns | |
|---|---|---|
| 0 | 2022-08-08 | 0.000000 |
| 1 | 2022-08-09 | 0.001242 |
| 2 | 2022-08-10 | 0.004439 |
| 3 | 2022-08-11 | 0.012194 |
| 4 | 2022-08-12 | 0.005255 |
| ... | ... | ... |
| 101 | 2023-01-05 | 0.009010 |
| 102 | 2023-01-06 | -0.001962 |
| 103 | 2023-01-09 | 0.011651 |
| 104 | 2023-01-10 | 0.014685 |
| 105 | 2023-01-11 | -0.014254 |
106 rows × 2 columns
#转换成净值
df['returns'] = df['cum_returns'] + 1
#每日收益率
df['returns'] = (df['returns'] - df['returns'].shift(1)) / df['returns'].shift(1)
df['returns'] = df['returns'].fillna(0)
df
| date | cum_returns | returns | |
|---|---|---|---|
| 0 | 2022-08-08 | 0.000000 | 0.000000 |
| 1 | 2022-08-09 | 0.001242 | 0.001242 |
| 2 | 2022-08-10 | 0.004439 | 0.003193 |
| 3 | 2022-08-11 | 0.012194 | 0.007720 |
| 4 | 2022-08-12 | 0.005255 | -0.006855 |
| ... | ... | ... | ... |
| 101 | 2023-01-05 | 0.009010 | 0.012025 |
| 102 | 2023-01-06 | -0.001962 | -0.010874 |
| 103 | 2023-01-09 | 0.011651 | 0.013640 |
| 104 | 2023-01-10 | 0.014685 | 0.002999 |
| 105 | 2023-01-11 | -0.014254 | -0.028519 |
106 rows × 3 columns
#保存绩效文件
df[['date','returns']].set_index('date').to_csv('test1.csv')
df[['date','returns']].set_index('date').to_csv('test2.csv')
df[['date','returns']].set_index('date').to_csv('test3.csv')
# #转换成需要的数据
# from datetime import datetime
# r = data['data']['algo_info_plot_return']['cum_return_plot']
# df = pd.DataFrame(r,columns=['date','cum_returns'])
# #转换时间
# df['date'] = df['date'].apply(lambda x:datetime.fromtimestamp(x/10**3))
# #转换成净值
# df['returns'] = df['cum_returns'] + 1
# #每日收益率
# df['returns'] = (df['returns'] - df['returns'].shift(1)) / df['returns'].shift(1)
# df['returns'] = df['returns'].fillna(0)
# df[['date','returns']].set_index('date').to_csv('test1.csv')
# df[['date','returns']].set_index('date').to_csv('test2.csv')
# df[['date','returns']].set_index('date').to_csv('test3.csv')
# 本代码由可视化策略环境自动生成 2023年1月14日 14:42
# 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
m4 = M.strategy_asset_allocation.v1(
stra_dict={
"test1":"test1.csv",
"test2":"test2.csv",
"test3":"test3.csv"
},
start_date='2022-08-08',
upper_weight=1,
lower_weight=0,
target='风险平价',
balance_period='1周',
cal_period='全部历史',
cal_days=30
)
[2023-01-12 11:27:18.269065] INFO: moduleinvoker: strategy_asset_allocation.v1 运行完成[0.725947s].
再平衡日期和各策略对应权重:
2022-08-08 {'test1': 0.33, 'test2': 0.33, 'test3': 0.33}
2022-08-15 {'test1': 0.33, 'test2': 0.33, 'test3': 0.33}
2022-08-22 {'test1': 0.33, 'test2': 0.33, 'test3': 0.33}
2022-08-29 {'test1': 0.33, 'test2': 0.33, 'test3': 0.33}
2022-09-05 {'test1': 0.33, 'test2': 0.33, 'test3': 0.33}
2022-09-12 {'test1': 0.33, 'test2': 0.33, 'test3': 0.33}
2022-09-19 {'test1': 0.33, 'test2': 0.33, 'test3': 0.33}
2022-09-26 {'test1': 0.33, 'test2': 0.33, 'test3': 0.33}
2022-10-03 {'test1': 0.33, 'test2': 0.33, 'test3': 0.33}
2022-10-10 {'test1': 0.33, 'test2': 0.33, 'test3': 0.33}
2022-10-17 {'test1': 0.33, 'test2': 0.33, 'test3': 0.33}
2022-10-24 {'test1': 0.33, 'test2': 0.33, 'test3': 0.33}
2022-10-31 {'test1': 0.33, 'test2': 0.33, 'test3': 0.33}
2022-11-07 {'test1': 0.33, 'test2': 0.33, 'test3': 0.33}
2022-11-14 {'test1': 0.33, 'test2': 0.33, 'test3': 0.33}
2022-11-21 {'test1': 0.33, 'test2': 0.33, 'test3': 0.33}
2022-11-28 {'test1': 0.33, 'test2': 0.33, 'test3': 0.33}
2022-12-05 {'test1': 0.33, 'test2': 0.33, 'test3': 0.33}
2022-12-12 {'test1': 0.33, 'test2': 0.33, 'test3': 0.33}
2022-12-19 {'test1': 0.33, 'test2': 0.33, 'test3': 0.33}
2022-12-26 {'test1': 0.33, 'test2': 0.33, 'test3': 0.33}
2023-01-02 {'test1': 0.33, 'test2': 0.33, 'test3': 0.33}
2023-01-09 {'test1': 0.33, 'test2': 0.33, 'test3': 0.33}
策略绩效指标
| 策略名称 | 收益率 | 年化收益率 | 夏普比率 | 年化波动率 | 最大回撤 | 收益回撤比 |
|---|---|---|---|---|---|---|
| test1 | -1.43% | -3.36% | -0.11 | 27.80% | -13.29% | 0.25 |
| test2 | -1.43% | -3.36% | -0.11 | 27.80% | -13.29% | 0.25 |
| test3 | -1.43% | -3.36% | -0.11 | 27.80% | -13.29% | 0.25 |
| 组合收益 | -1.43% | -3.36% | -0.11 | 27.80% | -13.29% | 0.25 |