"""C08教学构造模型;Python3.10+标准库;无网络,默认在脚本同目录写纯11ID JSON。""" from fractions import Fraction as F from decimal import Decimal as D, localcontext, ROUND_HALF_UP from pathlib import Path from datetime import date, timedelta import json def decimal(x,digits=8): x=F(x) with localcontext() as ctx: ctx.prec=70 value=D(x.numerator)/D(x.denominator) if digits is None: text=format(value,'f') return text.rstrip('0').rstrip('.') if '.' in text else text return format(value.quantize(D(1).scaleb(-digits),rounding=ROUND_HALF_UP),'f') def exact(x): return {'fraction':str(F(x)),'decimal_50dp':decimal(x,50)} def normalize(base,quote,base_amount,quote_amount,foreign,report='R'): if any(x is None or x=='' for x in [base,quote,base_amount,quote_amount,foreign,report]): raise ValueError('币对、方向、基数或报价缺失,拒绝猜测') ba,qa=F(base_amount),F(quote_amount) if ba<=0 or qa<=0 or foreign==report: raise ValueError('基数和报价必须正,原币与报告币需不同') if base==foreign and quote==report:return qa/ba if base==report and quote==foreign:return ba/qa raise ValueError('币对不匹配') def parse_quote(row): required=['source','timestamp','base_currency','quote_currency','base_amount','quote_amount','foreign_currency'] if any(k not in row or row[k] is None or row[k]=='' for k in required): raise ValueError('多源导入缺来源、时间、币对或基数,不能成为确定估值输入') return normalize(row['base_currency'],row['quote_currency'],row['base_amount'],row['quote_amount'],row['foreign_currency']) def drawdown(values,days): if len(values)!=len(days) or not values: raise ValueError('日期与净值长度不一致或为空') if values[0] is None or F(values[0])<=0: raise ValueError('首期净值未知或非正') peak=F(values[0]);peakday=days[0];maximum=F(0);peak_max=days[0];trough_max=days[0];rows=[] for d,v in zip(days,values): if v is None or F(v)<=0:raise ValueError('净值未知或非正,拒算比例回撤') v=F(v) if v>peak:peak=v;peakday=d dd=1-v/peak if dd>maximum:maximum=dd;peak_max=peakday;trough_max=d rows.append({'date':d,'value':decimal(v,4),'running_peak':decimal(peak,4),'peak_date':peakday,'drawdown_pct':decimal(dd*100,8)}) level=next(F(v) for d,v in zip(days,values) if d==peak_max) recovery=next((d for d,v in zip(days,values) if d>trough_max and F(v)>=level),None) if maximum==0: peak_max=trough_max=recovery=None return {'rows':rows,'maximum_fraction':str(maximum),'maximum_pct':decimal(maximum*100,8),'peak_date':peak_max,'trough_date':trough_max,'recovery_date':recovery} POLICY='内部Fraction精确有理数,十进制显示用Decimal70位上下文;金额通常显示2位、回报8位,最终显示四舍五入;不回用显示值做中间计算。全部样本与未来履约均构造,非真实市场数据或税务口径。' def model(): out={} raw=[('源甲','USD','R','100','720','USD'),('源乙','EUR','R','1','7.8','EUR'),('源丙','JPY','R','100','4.8','JPY'),('源丁','R','MYR','100','65','MYR')] rows=[] for source,base,quote,ba,qa,foreign in raw: record={'source':source,'timestamp':'2026-11-02T08:00:00Z','base_currency':base,'quote_currency':quote,'base_amount':ba,'quote_amount':qa,'foreign_currency':foreign} rate=parse_quote(record) back=rate*F(ba) if base==foreign else F(ba)/rate rows.append({'source':source,'timestamp':'2026-11-02T08:00:00Z','base_currency':base,'quote_currency':quote,'base_amount':ba,'quote_amount':qa,'foreign_currency':foreign,'report_per_foreign_exact':str(rate),'report_per_foreign_display':decimal(rate,8),'reconstructed_quote':decimal(back,8),'same_raw_quote':back==F(qa)}) out['DJ3-078']={'precision':POLICY,'inputs':{'report_currency':'R,教学人民币元单位','all_sources':'构造源甲乙丙丁,不是实际官方历史值','required_schema':['source','timestamp','base_currency','quote_currency','base_amount','quote_amount','foreign_currency']},'normalization':rows,'rejected_rows':[{'missing':k,'reason':'必填字段缺失,保留原文而不作为完整估值输入'} for k in ['base_amount','base_currency/quote_currency','source','timestamp']],'jpy_wrong_no_scale':decimal(F('4.8')),'jpy_correct':decimal(F('4.8')/100),'myr_wrong_divide_100':decimal(F(65)/100),'myr_correct':exact(F(20,13)),'jpy_10000_valuation_R':decimal(10000*F('.048'),2),'jpy_wrong_10000_R':decimal(10000*F('4.8'),2)} rates={'R':F(1),'A':F('7.2'),'B':F('10.8')} matrix=[{'from':a,'to':b,'factor_exact':str(rates[a]/rates[b]),'factor_display':decimal(rates[a]/rates[b],8)} for a in rates for b in rates] chain=F(1)/F('1.5')*F('10.8')/F('7.2') mixed=F(1)/F('1.5')*F('10.5')/F('7.2') out['DJ3-079']={'precision':POLICY,'inputs':{'same_time':'2026-11-02T10:00:00Z','rate_R_per_A':'7.2','rate_A_per_B':'1.5','direct_R_per_B':'10.8','stale_direct_R_per_B':'10.5','stale_timestamp':'2026-11-02T09:30:00Z','source':'全部为构造参考值,无买卖方向/费用或可交易报价'},'conversion_matrix':matrix,'path_B_A_R':'10.80000000','path_B_R_direct':'10.80000000','path_A_B_R':'7.20000000','consistent_cycle_A_B_R_A':exact(chain),'mixed_cycle_A_B_R_A':exact(mixed),'mixed_cycle_error_pct':decimal((mixed-1)*100,8),'mixed_R_per_B_difference':'-0.30000000'} out['DJ3-079']['cycle_100A_mixed_ending_A']=exact(100*mixed) qty={'R':F(10000),'A':F(1000),'B':F(500)};cost={'R':F(10000),'A':F(7000),'B':F(4000)} income=expense=realized=F(0);journal=[] def snapshot(day,event,detail): journal.append({'date':day,'event':event,'detail':detail,'quantity':{k:decimal(v,8) for k,v in qty.items()},'historical_R_cost':{k:decimal(v,12) for k,v in cost.items()},'cumulative_income_R':decimal(income,8),'cumulative_expense_R':decimal(expense,8),'cumulative_realized_FX_R':decimal(realized,12)}) snapshot('2026-11-02','期初','R10000,A1000成本7000R,B500成本4000R') qty['R']-=3600;cost['R']-=3600;qty['A']+=500;cost['A']+=3600 snapshot('2026-11-02','内部兑换1','支出3600R,取得500A;当时7.2R/A;无费用') removed=cost['A']/qty['A']*300;qty['A']-=300;cost['A']-=removed;qty['B']+=270;cost['B']+=2160;realized+=2160-removed snapshot('2026-11-03','内部兑换2','支出300A取得270B;当时7.2R/A与8R/B,两腿2160R;移动平均成本') qty['A']+=10;cost['A']+=73;income+=73 snapshot('2026-11-04','A利息','入10A,发生率7.3R/A,收入73R') removed=cost['A']/qty['A']*2;qty['A']-=2;cost['A']-=removed;expense+=F('14.6');realized+=F('14.6')-removed snapshot('2026-11-04','A费用','扣2A,发生率7.3R/A,费用14.60R;消耗库存成本另分') removed=cost['B']/qty['B']*5;qty['B']-=5;cost['B']-=removed;expense+=F('40.5');realized+=F('40.5')-removed snapshot('2026-11-04','B费用','扣5B,发生率8.1R/B,费用40.50R') close_rates={'R':F(1),'A':F('7.4'),'B':F('8.2')};close_values={k:qty[k]*close_rates[k] for k in qty};unrealized={k:close_values[k]-cost[k] for k in qty} nav=sum(close_values.values());change=nav-F(21000) assert income-expense+realized+sum(unrealized.values())==change out['DJ3-080']={'precision':POLICY,'inputs':{'opening_date':'2026-11-02','closing_date':'2026-11-06','cost_policy':'移动加权平均,库存支付按支付时参考价值列费用并单列处置汇差;个人教育备查法,非企业/税务统一规定','external_flow':'0','initial_NAV_R':'21000','close_R_per_A':'7.4','close_R_per_B':'8.2'},'quantity_cost_journal':journal,'closing_valuation':[{'currency':k,'quantity':decimal(qty[k],8),'rate_R_per_unit':decimal(close_rates[k],8),'value_R':decimal(close_values[k],2),'historical_cost_R':decimal(cost[k],12),'unrealized_FX_R':decimal(unrealized[k],12)} for k in qty],'income_R':decimal(income,2),'expense_R':decimal(expense,2),'realized_FX_R':exact(realized),'unrealized_FX_R':exact(sum(unrealized.values())),'closing_NAV_R':decimal(nav,2),'NAV_change_R':decimal(change,2),'all_FX_R':decimal(realized+sum(unrealized.values()),2),'zero_FX_with_all_event_rates_fixed':'若全部期初/事件/期末率不变,两次内部等值兑换的FX为零;收入与费用仍存在'} stages=[('2026-11-02','除息确认','7','19.5',50,100),('2026-11-04','报告日重估','7.2','19.5',50,100),('2026-11-06','派息转现金','6.9','19.5',0,150)] rows=[] for day,event,s,p,recv,cash in stages: s,p=F(s),F(p);rows.append({'date':day,'event':event,'R_per_A':decimal(s,4),'security_A':decimal(100*p,2),'receivable_A':str(recv),'cash_A':str(cash),'security_R':decimal(100*p*s,2),'receivable_R':decimal(recv*s,2),'cash_R':decimal(cash*s,2),'NAV_R':decimal((100*p+recv+cash)*s,2)}) out['DJ3-081']={'precision':POLICY,'inputs':{'shares':100,'pre_ex_price_A':'20','dividend_per_share_A':'.5','fixed_receivable_A':'50','opening_cash_A':'100','confirmation_date':'2026-11-02','report_date':'2026-11-04','pay_date_assumed':'2026-11-06','all_tax_fees':'0','policy':'构造权益确认凭证在除息日确认固定应收,外币金额不变;派息只改形态,非真实市场法定日期'},'stages':rows,'dividend_initial_R':'350.00','receivable_FX_ex_to_report_R':'10.00','receivable_FX_report_to_payment_R':'-15.00','receivable_FX_total_R':'-5.00','paid_dividend_cash_R':'345.00','wrong_report_omit_receivable_NAV_R':'14760.00','wrong_pay_keep_receivable_NAV_R':'14835.00','report_NAV_change_R':'420.00','pay_NAV_change_from_report_R':'-630.00','wrong_only_pay_income_R':'345.00'} out['DJ3-081'].update(dividend_initial_R=decimal(50*F(7),2),receivable_FX_ex_to_report_R=decimal(50*(F('7.2')-7),2),receivable_FX_report_to_payment_R=decimal(50*(F('6.9')-F('7.2')),2),receivable_FX_total_R=decimal(50*(F('6.9')-7),2),paid_dividend_cash_R=decimal(50*F('6.9'),2),wrong_report_omit_receivable_NAV_R=decimal((1950+100)*F('7.2'),2),wrong_pay_keep_receivable_NAV_R=decimal((1950+150+50)*F('6.9'),2),report_NAV_change_R=decimal(2100*(F('7.2')-7),2),pay_NAV_change_from_report_R=decimal(2100*(F('6.9')-F('7.2')),2)) rows=[{'date':'2026-11-02前','state':'成交前','units':100,'security_A':'1000','receivable_A':'0','cash_A':'0','rate':'7','NAV_R':'7000.00'},{'date':'2026-11-02','state':'成交确认','units':0,'security_A':'0','receivable_A':'1098','cash_A':'0','rate':'7.1','NAV_R':'7795.80'},{'date':'2026-11-03','state':'报告日未交收','units':0,'security_A':'0','receivable_A':'1098','cash_A':'0','rate':'7.2','NAV_R':'7905.60'},{'date':'2026-11-04','state':'假设交收','units':0,'security_A':'0','receivable_A':'0','cash_A':'1098','rate':'7','NAV_R':'7686.00'}] out['DJ3-082']={'precision':POLICY,'inputs':{'units_sold':100,'before_price_A':'10','sold_price_A':'11','fee_A':'2','gross_proceeds_A':'1100','net_receivable_A':'1098','trade_date':'2026-11-02','report_date':'2026-11-03','settlement_date_assumed':'2026-11-04','policy':'构造交易日终止确认证券、净应收保留至交收;无外部提款,未再投资,无额外税费','hypothetical_post_sale_market_price_A':'12'},'stages':rows,'price_change_at_opening_FX_R':'700.00','trade_security_FX_R':'110.00','fee_at_trade_R':'14.20','trade_NAV_change_R':'795.80','receivable_FX_to_report_R':'109.80','receivable_FX_report_to_settle_R':'-219.60','total_NAV_change_R':'686.00','wrong_report_retained_security_R':'8640.00','wrong_report_double_NAV_R':'16545.60'} net=F(100)*11-2 for row in rows: row['NAV_R']=decimal((F(row['security_A'])+F(row['receivable_A'])+F(row['cash_A']))*F(row['rate']),2) out['DJ3-082'].update(price_change_at_opening_FX_R=decimal(100*(11-10)*7,2),trade_security_FX_R=decimal(1100*(F('7.1')-7),2),fee_at_trade_R=decimal(2*F('7.1'),2),trade_NAV_change_R=decimal(net*F('7.1')-7000,2),receivable_FX_to_report_R=decimal(net*(F('7.2')-F('7.1')),2),receivable_FX_report_to_settle_R=decimal(net*(7-F('7.2')),2),total_NAV_change_R=decimal(net*7-7000,2),wrong_report_retained_security_R=decimal(100*12*F('7.2'),2),wrong_report_double_NAV_R=decimal((net+100*12)*F('7.2'),2)) rp,rb,g=F('.12'),F('.08'),F('.95');rpR=(1+rp)*g-1;rbR=(1+rb)*g-1 mixed=(1+rp)*F('.95')/((1+rb)*F('1.02'))-1 out['DJ3-083']={'precision':POLICY,'inputs':{'start':'2026-11-02','end':'2026-11-30','portfolio_local_return':'.12','benchmark_local_return':'.08','common_FX_factor':'.95','external_flow':'0','definition':'同起止、同报告换币因子,价格/全收益处理已对齐,无额外费用层差'},'comparison':[{'currency':'原币A','portfolio_return_pct':'12.00000000','benchmark_return_pct':'8.00000000','arithmetic_excess_pp':'4.00000000','geometric_relative_pct':decimal(((1+rp)/(1+rb)-1)*100,8)},{'currency':'报告币R','portfolio_return_pct':decimal(rpR*100,8),'benchmark_return_pct':decimal(rbR*100,8),'arithmetic_excess_pp':decimal((rpR-rbR)*100,8),'geometric_relative_pct':decimal(((1+rpR)/(1+rbR)-1)*100,8)}],'relative_exact':'1/27','different_FX_counterexample':{'portfolio_factor':'.95','benchmark_factor':'1.02','portfolio_R_return_pct':'6.40000000','benchmark_R_return_pct':'10.16000000','geometric_relative_pct':decimal(mixed*100,8),'geometric_relative_exact':str(mixed)},'zero_currency_change_arithmetic_excess_pp':'4.00000000'} hedge=[] for growth,s1 in [(F('.1'),F('6.8')),(F(0),F('6.8')),(F('-.1'),F('6.8')),(F('.1'),F('7.2'))]: a1=1000*(1+growth);asset=a1*s1;forward=1000*(F('7.05')-s1);local=(a1-1000)*7;points=F(50);residual=(a1-1000)*(s1-7) assert asset+forward-7000==local+points+residual hedge.append({'asset_A':decimal(a1,2),'spot_R_per_A':decimal(s1,2),'asset_R':decimal(asset,2),'forward_settlement_R':decimal(forward,2),'ending_total_R':decimal(asset+forward,2),'profit_R':decimal(asset+forward-7000,2),'local_asset_change_at_initial_FX_R':decimal(local,2),'forward_points_R':decimal(points,2),'unhedged_growth_FX_R':decimal(residual,2),'end_unhedged_A':decimal(a1-1000,2)}) out['DJ3-084']={'precision':POLICY,'inputs':{'start':'2026-11-02','end_maturity':'2026-11-30','initial_asset_A':'1000','initial_spot_R_per_A':'7','forward_nominal_A_sold':'1000','forward_contract_R_per_A':'7.05','initial_NAV_R':'7000','contract':'到期现金结算N*(K-S1),期间名义额不重置;不模拟保证金、税费、信用折价或提前平仓,非交易指导'},'scenario_bridge':hedge,'wrong_main_double_deduct_forward_points_total_R':'7680.00','zero_nominal_hedge_main_asset_only_R':'7480.00'} holdings=[('甲','R','USD','USD','0.6','0.7','0.5'),('甲','R','USD','EUR','0.6','0.2','0'),('甲','R','USD','R','0.6','0.1','0'),('乙','R','R','USD','0.4','0.4','1'),('乙','R','R','EUR','0.4','0.3','0.5'),('乙','R','R','未知','0.4','0.3',None)] rows=[];gross={};net={} for fund,trade,report,currency,fw,inside,h in holdings: amount=F(100000)*F(fw)*F(inside);hedged=amount*F(h) if h is not None else None;residual=amount-hedged if h is not None else None rows.append({'fund':fund,'trade_currency':trade,'share_report_currency':report,'underlying_quote_currency':currency,'fund_weight':fw,'inside_weight':inside,'gross_R_equivalent':decimal(amount,2),'hedge_ratio_disclosed':h,'hedge_R_equivalent':decimal(hedged,2) if h is not None else None,'net_nominal_R_equivalent':decimal(residual,2) if residual is not None else None,'operating_revenue_currency':'未知'}) gross[currency]=gross.get(currency,F(0))+amount if residual is not None:net[currency]=net.get(currency,F(0))+residual out['DJ3-085']={'precision':POLICY,'inputs':{'snapshot':'2026-11-02','portfolio_R_value':'100000','fund_weights':{'甲':'.6','乙':'.4'},'all_holdings_and_hedges':'构造名义表,R为教学人民币;非真实产品持仓','exposure_definition':'以同日R等值名义额统计报价币暴露,不等于完整经济收入敞口或NAV组成'},'mapping':rows,'gross_by_currency_R':{k:decimal(v,2) for k,v in gross.items()},'known_net_by_currency_R':{k:decimal(v,2) for k,v in net.items()},'unknown_underlying_R':'12000.00','known_USD_EUR_net_R':'39000.00','known_foreign_up_1pct_effect_R':'390.00','unknown_effect':'未披露部分及其对冲未知,不能报告全账户确定敏感性'} out['DJ3-086']={'precision':POLICY,'inputs':{'date':'2026-11-02','foreign_asset_USD':'1000','same_asset_price':'1USD/单位,1000单位;所有方案固定','report_cash_yuan':'500','shares':'1000','source_CNY_time':'16:00Z','source_CNH_time':'16:00Z','source_CNH_late_time':'18:00Z','rates_all_constructed':True},'valuation':[{'source':'CNY参考源','time':'16:00Z','rate_yuan_per_USD':'7.10','foreign_asset_yuan':'7100.00','cash_yuan':'500.00','total_yuan':'7600.00','NAV_yuan':'7.60000000'},{'source':'CNH参考源','time':'16:00Z','rate_yuan_per_USD':'7.12','foreign_asset_yuan':'7120.00','cash_yuan':'500.00','total_yuan':'7620.00','NAV_yuan':'7.62000000'},{'source':'CNH参考源后时点','time':'18:00Z','rate_yuan_per_USD':'7.15','foreign_asset_yuan':'7150.00','cash_yuan':'500.00','total_yuan':'7650.00','NAV_yuan':'7.65000000'}],'same_time_source_difference_yuan':'20.00','same_time_NAV_difference':'0.02000000','later_time_increment_yuan':'30.00','mixed_total_difference_yuan':'50.00'} for row in out['DJ3-086']['valuation']: value=1000*F(row['rate_yuan_per_USD']);row.update(foreign_asset_yuan=decimal(value,2),total_yuan=decimal(value+500,2),NAV_yuan=decimal((value+500)/1000,8)) days=['2026-11-02','2026-11-03','2026-11-04','2026-11-05','2026-11-06'];px=[10,None,11,None,12];py=[20,21,None,22,None];sx=list(map(F,['7','7.1','7.2','7.15','7.1']));sy=list(map(F,['8','8.1','8.05','8','7.95'])) lastx=lasty=None;dx=dy=None;wrongx=wrongy=None;rows=[];prev=None for i,day in enumerate(days): if px[i] is not None:lastx=F(px[i]);dx=day;wrongx=100*lastx*sx[i] if py[i] is not None:lasty=F(py[i]);dy=day;wrongy=50*lasty*sy[i] vx=100*lastx*sx[i];vy=50*lasty*sy[i];nav=vx+vy if prev: priceeffect=100*(lastx-prev[0])*sx[i-1]+50*(lasty-prev[1])*sy[i-1] fxeffect=100*lastx*(sx[i]-sx[i-1])+50*lasty*(sy[i]-sy[i-1]) assert nav-prev[2]==priceeffect+fxeffect else:priceeffect=fxeffect=F(0) rows.append({'report_date':day,'cutoff':'22:00Z,合成截点','X_price':decimal(lastx,2),'X_price_date':dx,'X_market_open':px[i] is not None,'X_USD_R_rate':decimal(sx[i],4),'X_fx_date':day,'X_value_R':decimal(vx,2),'Y_price':decimal(lasty,2),'Y_price_date':dy,'Y_market_open':py[i] is not None,'Y_EUR_R_rate':decimal(sy[i],4),'Y_fx_date':day,'Y_value_R':decimal(vy,2),'NAV_R':decimal(nav,2),'daily_price_effect_R':decimal(priceeffect,2),'daily_FX_effect_R':decimal(fxeffect,2),'wrong_freeze_R_value_NAV':decimal(wrongx+wrongy,2),'wrong_minus_correct_R':decimal(wrongx+wrongy-nav,2)}) prev=lastx,lasty,nav out['DJ3-087']={'precision':POLICY,'inputs':{'X_units':100,'X_currency':'USD','Y_units':50,'Y_currency':'EUR','calendar':'合成五日;X于11月3/5日休市,Y于11月4/6日休市;不是现实市场假日','policy':'先保存市场状态,休市使用最近已知价格并保留有效日,FX采用当日构造报价;没有费用、外部出入金或价格未来回填'},'valuation_matrix':rows} local=list(map(F,[100,110,105,104,112,108,110,114]));fx=list(map(F,['7','7','7.1','6.8','6.6','6.5','6.9','7']));days=['2026-11-02','2026-11-03','2026-11-04','2026-11-05','2026-11-06','2026-11-09','2026-11-10','2026-11-11'] rnav=[v*s for v,s in zip(local,fx)] out['DJ3-088']={'precision':POLICY,'inputs':{'dates':days,'local_NAV_A':[str(x) for x in local],'R_per_A':[str(x) for x in fx],'policy':'同一无外部资金流、无分红费用、固定份额路径;报告币NAV逐点相乘;峰值并列时保留最早日,恢复指最大回撤该峰值被重新达到'},'local_path':drawdown(local,days),'report_path':drawdown(rnav,days),'constant_rate_counterexample':drawdown([x*7 for x in local],days),'local_terminal_return_pct':decimal((local[-1]/local[0]-1)*100,8),'report_terminal_return_pct':decimal((rnav[-1]/rnav[0]-1)*100,8)} assert list(out)==[f'DJ3-{n:03d}' for n in range(78,89)] self_checks(out) return out def self_checks(out): assert normalize('JPY','R',100,'4.8','JPY')==F('.048') assert normalize('R','MYR',100,65,'MYR')==F(20,13) assert out['DJ3-080']['closing_NAV_R']=='21612.20' assert out['DJ3-081']['stages'][-1]['NAV_R']=='14490.00' assert out['DJ3-083']['comparison'][0]['geometric_relative_pct']==out['DJ3-083']['comparison'][1]['geometric_relative_pct'] assert out['DJ3-084']['scenario_bridge'][0]['ending_total_R']=='7730.00' assert out['DJ3-085']['gross_by_currency_R']=={'USD':'58000.00','EUR':'24000.00','R':'6000.00','未知':'12000.00'} assert out['DJ3-087']['valuation_matrix'][-1]['NAV_R']=='17265.00' assert out['DJ3-088']['local_path']['maximum_fraction']=='3/55' assert out['DJ3-088']['report_path']['maximum_fraction']=='34/385' assert out['DJ3-088']['local_path']['maximum_pct']==out['DJ3-088']['constant_rate_counterexample']['maximum_pct'] assert drawdown([F(1),F(1)],['a','b'])['maximum_fraction']=='0' sample={'source':'test','timestamp':'2026-11-02T08:00:00Z','base_currency':'A','quote_currency':'R','base_amount':100,'quote_amount':700,'foreign_currency':'A'} assert parse_quote(sample)==7 for missing in sample: incomplete=sample.copy();incomplete.pop(missing) try:parse_quote(incomplete) except ValueError:pass else:raise AssertionError('导入字段缺失未拒绝') for args in [('A','R',None,7,'A'),(None,'R',1,7,'A'),('A','R',0,7,'A'),('A','R',1,0,'A'),('A','B',1,7,'A')]: try:normalize(*args) except ValueError:pass else:raise AssertionError('缺失/异常报价未拒绝') for values in [[F(1),None],[F(1),F(0)],[F(1),F(-1)]]: try:drawdown(values,['a','b']) except ValueError:pass else:raise AssertionError('无效净值未拒绝') if __name__=='__main__': Path(__file__).resolve().with_suffix('.json').write_text(json.dumps(model(),ensure_ascii=False,indent=2)+'\n',encoding='utf-8',newline='\n')