In[]:=
iMaxYr=30;iSecPerYr=365.25*24*60*60//Round;
In[]:=
ClearAll[yrs];yrs[yr_]:=Round[iSecPerYr*yr];
In[]:=
yearTicks=Table[{yrs[i],Subscript[i,"yr"]},{i,iMaxYr}];
Stepwise Discount Function
Stepwise Discount Function
In[]:=
ClearAll[createDiscountFunction];createDiscountFunction[m_]:=Module[{t0,acc,t1,f1,dt,f},t0=m[[1,1]];acc=t0*m[[1,2]];ReleaseHold@Function[x,Evaluate[Hold[Which]@@Flatten@Table[{t1,f1}=m[[i]];dt=t1-t0;f=(t1*f1-acc)/dt;t0=t1;acc+=dt*f;{If[i==Length[m],True,x<=t1],f},{i,2,Length[m]}]]]];
In[]:=
(*parametersfromvideo*)mDataFromVideo={{0,0},{yrs[1],0},{yrs[2],.05},{yrs[3],.1},{yrs[5],.175},{yrs[10],.25},{yrs[25],.3},{yrs[30],.3}};
discount(t)
discount(t)
In[]:=
discount=createDiscountFunction[mDataFromVideo]
Out[]=
Function[x$,Which[x$≤31557600,0,x$≤63115200,0.1,x$≤94672800,0.2,x$≤157788000,0.2875,x$≤315576000,0.325,x$≤788940000,0.333333,True,0.3]]
Discount(t) = t∫0discount(t)t
Discount(t) = discount(t)t
t
∫
0
In[]:=
Discount=Function[t,Evaluate[Integrate[discount[t],t]]]
Out[]=
Functiont,
|
averageDiscount(t) = Discount(t)t
averageDiscount(t) =
Discount(t)
t
In[]:=
averageDiscount=Function[t,If[t>0,Discount[t]/t,0]];
inveralDiscount(t0, t1) = Discount(t1)-Discount(t0)t1-t0 = t1∫t0discount(t)t
inveralDiscount(t0, t1) = = discount(t)t
Discount(t1)-Discount(t0)
t1-t0
t1
∫
t0
In[]:=
intervalDiscount[t0_,t1_]:=If[t1>t0,(Discount[t1]-Discount[t0])/(t1-t0),0];
Plots
Plots
discount(t)
discount(t)
In[]:=
Plot[discount[t],{t,0,yrs[iMaxYr]},AxesOrigin->{0,0},Filling->Axis,AspectRatio->1/4,Ticks->{yearTicks,Automatic}]
Out[]=
averageDiscount(t)
averageDiscount(t)
In[]:=
Plot[averageDiscount[t],{t,0,yrs[iMaxYr]},AxesOrigin->{0,0},Filling->Axis,AspectRatio->1/4,Epilog->{PointSize[Large],Orange,Point[mDataFromVideo]},Ticks->{yearTicks,Automatic}]
Out[]=
In[]:=
TableForm[Table[With[{t=iSecPerYr*yr},{yr,averageDiscount[t],SelectFirst[mDataFromVideo,First[#]==t&,{"",""}][[2]],discount[t]}],{yr,Join[Range[iMaxYr],2^Range[Ceiling[Log2[iMaxYr]],16]]}],TableHeadings->{None,{"yr","Average","Expected","Instant"}}]
Out[]//TableForm=
yr | Average | Expected | Instant |
1 | 0. | 0 | 0 |
2 | 0.05 | 0.05 | 0.1 |
3 | 0.1 | 0.1 | 0.2 |
4 | 0.146875 | 0.2875 | |
5 | 0.175 | 0.175 | 0.2875 |
6 | 0.2 | 0.325 | |
7 | 0.217857 | 0.325 | |
8 | 0.23125 | 0.325 | |
9 | 0.241667 | 0.325 | |
10 | 0.25 | 0.25 | 0.325 |
11 | 0.257576 | 0.333333 | |
12 | 0.263889 | 0.333333 | |
13 | 0.269231 | 0.333333 | |
14 | 0.27381 | 0.333333 | |
15 | 0.277778 | 0.333333 | |
16 | 0.28125 | 0.333333 | |
17 | 0.284314 | 0.333333 | |
18 | 0.287037 | 0.333333 | |
19 | 0.289474 | 0.333333 | |
20 | 0.291667 | 0.333333 | |
21 | 0.293651 | 0.333333 | |
22 | 0.295455 | 0.333333 | |
23 | 0.297101 | 0.333333 | |
24 | 0.298611 | 0.333333 | |
25 | 0.3 | 0.3 | 0.333333 |
26 | 0.3 | 0.3 | |
27 | 0.3 | 0.3 | |
28 | 0.3 | 0.3 | |
29 | 0.3 | 0.3 | |
30 | 0.3 | 0.3 | 0.3 |
32 | 0.3 | 0.3 | |
64 | 0.3 | 0.3 | |
128 | 0.3 | 0.3 | |
256 | 0.3 | 0.3 | |
512 | 0.3 | 0.3 | |
1024 | 0.3 | 0.3 | |
2048 | 0.3 | 0.3 | |
4096 | 0.3 | 0.3 | |
8192 | 0.3 | 0.3 | |
16384 | 0.3 | 0.3 | |
32768 | 0.3 | 0.3 | |
65536 | 0.3 | 0.3 |
Example
Example