"""Chosen financial scenarios only. Standard library; prints JSON, no I/O or network.""" import json,math def fit(x,y): if len(x)!=len(y) or len(x)<2:raise ValueError("paired sample required") mx=sum(x)/len(x);my=sum(y)/len(y) xx=sum((v-mx)**2 for v in x);yy=sum((v-my)**2 for v in y);xy=sum((a-mx)*(b-my) for a,b in zip(x,y)) if xx==0 or yy==0:raise ValueError("variance required") return dict(correlation=xy/math.sqrt(xx*yy),beta=xy/xx,intercept=my-(xy/xx)*mx) def calculate(): x=[-.02,-.01,.01,.02]*2;y=[2*v for v in x[:4]]+[-2*v for v in x[4:]] windows={k:fit(x[a:b],y[a:b]) for k,a,b in [("first_four",0,4),("last_four",4,8),("all_eight",0,8)]} assert windows["first_four"]["beta"]==2 and windows["last_four"]["beta"]==-2 and windows["all_eight"]["beta"]==0 assert windows["first_four"]["correlation"]==1 and windows["last_four"]["correlation"]==-1 and windows["all_eight"]["correlation"]==0 equity=[dict(coin_price=p,company_A_equity_per_share=(1000*p)/1000,company_B_equity_per_share=(1000*p-20000)/1000) for p in [30,60,90]] option=[dict(end_price=p,value=min(p,75)+2) for p in [30,60,75,95]] payments=[dict(asset="A",count=100,average=5,value=500,count_share=100/125,value_share=500/3000),dict(asset="B",count=25,average=100,value=2500,count_share=25/125,value_share=2500/3000)] local=.7*1.5;real=local/1.4-1;token=1.5/1.4-1 assert math.isclose(local,1.05) and math.isclose(real,-.25) and math.isclose(token,1/14) assert 50*.6==30 and 40*.8==32 and math.isclose(30/32-1,-.0625) assert math.isclose(.9/.8-1,.125) return dict(scope="Invented arithmetic, no market observations, issuer valuations or forecasts.",treasury_equity=equity,covered_call=option,premium_example=dict(old_nav=40,old_ratio=.8,old_share=32,new_nav=50,new_ratio=.6,new_share=30,nav_return=.25,share_return=-.0625),payment_denominators=payments,inflation_example=dict(ltc_usd_factor=.7,fx_local_per_usd_factor=1.5,consumer_price_factor=1.4,local_return=local-1,real_ltc_return=real,real_constant_dollar_return=token),ratio_return=.9/.8-1,synthetic_regression=dict(benchmark_returns=x,second_series=y,windows=windows),checks=dict(regression_windows_checked=3,synthetic_model_families=6)) if __name__=="__main__":print(json.dumps(calculate(),indent=2))