com.nodelab.interest

Type CalcInterestFuture

com.nodelab.0.10176
Instance of Type
Inheriting from Calculator

Type dataValue
org.uninode.Type.displayPatterna {att:org.uninode.Node.type}
org.uninode.Resource.resourceType
org.uninode.Resource.label
org.uninode.Resource.resourceOfList{}
org.uninode.Listable.resourcesReference[org.uninode.Listable.resources] of com.nodelab.interest.CalcInterestFuture

Attribute summaryDefined inUninode® IdPropertiesDefault
Reference[org.uninode.Listable.resources]resourcesListableorg.uninode.0.2001type
StringtoString
This is the display string.
Nodeorg.uninode.0.102
Typetype
The type of an object determines the behaviour and attributes of the object.
Nodeorg.uninode.0.101
StringuriNodeorg.uninode.0.103
StringlabelResourceorg.uninode.0.2041type
List[Type]resourceOfResourceorg.uninode.0.2042type
SignatureresourceType
This defines the type of resource. It can be 'view', 'adapter' or 'action'
Resourceorg.uninode.0.2043type

Method summaryDefined inOverridesProperties
voidactivateListable
voiddesignEditor(WidgetWorkspace ws)Listable
voidgenerateScript(ScriptGenerationInfo info)
Prepare and generate initialization code
ScriptGenerator
voidinstanceScript(ScriptGenerationInfo info)
return either variable name (like 'ave1', found in info), or a constructor call (new ...)
ScriptGenerator
BooleanisResourceOf(Listable listable, Signature aspect)Mixabletype
ListablemixOn(Mixable mix)Mixable
ListablemixWith(Mixable mix)Mixable
StringresourceStringListableintrospection
voidcom.nodelab.java.view.ActivateViewListable
Intcom.nodelab.java.view.ActorCountView
Actorcom.nodelab.java.view.ActorForSoView
Actorcom.nodelab.java.view.AddSourceSoView
voidcom.nodelab.java.view.ConstructorView
voidcom.nodelab.java.view.DesignViewWWView
Dimensioncom.nodelab.java.view.DimensionAtInView
Intcom.nodelab.java.view.DimensionCountView
Dimensioncom.nodelab.java.view.DimensionTypeTyView
voidcom.nodelab.java.view.DragMouseReReReReView
voidcom.nodelab.java.view.GenerateScriptSIViewScriptGenerator
Actorcom.nodelab.java.view.GetActorInView
voidcom.nodelab.java.view.InstallView
voidcom.nodelab.java.view.InstanceScriptSIViewScriptGenerator
Booleancom.nodelab.java.view.IsPerpetualView
voidcom.nodelab.java.view.PrepareView
Collection[Type]com.nodelab.java.view.RequiredDimensionsView
Scenecom.nodelab.java.view.SceneView
WidgetWorkspacecom.nodelab.java.view.WorkspaceView

Script summary
com.nodelab.0.10381
/*


BaliCalculator subclass: #BaliCalcInterestFuture

	instanceVariableNames: ' date dateStr volWeight1 editYield editWeight quoteOption theoOption volDays1 theoFuture bondTable bondTableInterface shortRate frontBack volWeight2 expiryDate expiryDateStr futureCount weightTable weightTableInterface years quoteFuture volDays2 yields bonds random dbName iterations calculateProcess theta iterationReport greeks baseRound precision deltaFuture '
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Bali'!


!BaliCalcInterestFuture methodsFor: 'changes'!

changeBonds
	bonds := nil.
	bondTable := nil.
	self bondTableInterface table: self bondTable.
	self changeWeights.
	GotheTools adjustColumnWidths: bondTableInterface.!

changeBondTable
	| i |
	i := self bondTableInterface selectionInTable selectionIndex y.
	i > 0
		ifTrue: [self editYield value: (self bondTable at: 2@i)]
		ifFalse: [self editYield value: nil].!

changeCalculation!

changeDate
	self date: (BaliTime fromString: self dateStr value).!

changeEditWeight
	| i |
	i := self weightTableInterface selectionInTable selectionIndex y.
	i > 0 ifTrue: [self weightTable at: 2@i put: self editWeight value].
	self resetCalculation.!

changeEditYield
	| i |
	i := self bondTableInterface selectionInTable selectionIndex y.
	i > 0 ifTrue: [self bondTable at: 2@i put: self editYield value].
	self setBondDelta.
	self resetCalculation.!

changeFrontBack
	self date: self date!

changeFutureCount
	self changeCalculation!

changeShortRate
	self changeCalculation!

changeVolWeight1
	self volWeight2 value: 1 - self volWeight1 value.!

changeVolWeight2
	self volWeight1 value: 1 - self volWeight2 value.!

changeWeights
	| ta |
	weightTable := nil.
	self weightTableInterface table: self weightTable.
	ta := self weightTableInterface columnLabels value.
	ta at: 3 put: self volDays1 value printString , ' days'.
	ta at: 4 put: self volDays2 value printString , ' days'.
	self calculate.
	GotheTools adjustColumnWidths: weightTableInterface.!

changeWeightTable
	| i |
	i := self weightTableInterface selectionInTable selectionIndex y.
	i > 0 
		ifTrue: [self editWeight value: (self weightTable at: 2@i)]
		ifFalse: [self editWeight value: nil].
"	self resetCalculation."!

changeYears
	self date: self date! !

!BaliCalcInterestFuture methodsFor: 'calculations'!

calculate
	| newDelta sz valueArray roundsDone precisionVal precisionArray frequencyArray |
	random := (Random new next * 1000000) truncated.
	self calculateProcess isNil ifFalse: [self calculateProcess terminate].
	self iterationReport value: ''.
	self calculateProcess: (self server executeBlock: [
		self resetCalculation: false.
		self expiryDate isNil 
			ifTrue: [
				Dialog warn: 'No expiry date'.
				sz := 0]
			ifFalse: [sz := self bonds size].
		sz > 0 ifTrue: [
			self greeks value
				ifFalse: [valueArray := Array with: 0d]
				ifTrue: [
					valueArray := Array new: 2 * sz + 2.
					1 to: valueArray size do: [:v | valueArray at: v put: 0d]].
			frequencyArray := Array new: sz.
			1 to: sz do: [:i | frequencyArray at: i put: 0].
			roundsDone := 0.
			self iterations value: 0.
			precisionArray := Array new: 10.
			1 to: precisionArray size do: [:i | precisionArray at: i put: 0d].
			[roundsDone < 1000000] whileTrue: [
				roundsDone := self calculateRates: valueArray frequency: frequencyArray roundsDone: roundsDone.
				roundsDone = 0 ifTrue: [
					Dialog warn: 'Illegal arguments, check sigma and correlations'.
					roundsDone := 1000000].
				1 to: 9 do: [:i | precisionArray at: i put: (precisionArray at: i + 1)].
				precisionArray at: 10 put: (valueArray at: 1).
				precisionVal := 0d.
				1 to: 9 do: [:i | precisionVal := precisionVal + ((precisionArray at: i) - (precisionArray at: i + 1)) abs].
				self precision value: ((precisionVal * 10000) rounded / 100000) asDouble.
				valueArray size > 2 ifTrue: [
					1 to: sz do: [:i |
						newDelta := 
							((valueArray at: 2 * i + 1) - (valueArray at: 2 * i + 2)) / 
							((self modDirtyPriceOf: i rate: 0.01d date: 0) - (self modDirtyPriceOf: i rate: -0.01d date: 0)).
						self bondTable at: 3@i put: newDelta]].
				1 to: sz do: [:i | self bondTable at: 11@i put: ((frequencyArray at: i) * 100 / roundsDone) asDouble].
				self setFuturePrice: (valueArray at: 1).
				GotheTools adjustColumnWidths: bondTableInterface.
			].
		].
	] priority: Processor userBackgroundPriority forceBackground: true).!

calculateRates: valueArray frequency: frequencyArray roundsDone: oldRounds
	| rand1 rand2 rand3 rand4 pi r val newVal sigma1 sigma2 sigma3 sigma4 rho12 rho13 rho14 rho23 rho24 rho34 eps1 eps2 eps3 eps4 cf1 cf2 cf3 cf4 x1 x2 x3 x4 rounds finance tmpVal sz u14 u24 u34 u44 newRounds dayDiff dtArray dirtyArrays winner d dt3Array dt3 |
	"update valueArray (future price, theta, delta1, delta2, delta3, delta4). return new roundsDone"
	rounds := 10000.
	newRounds := oldRounds + rounds.
	sz := self bonds size.
	d := (self expiryDate settlement: 4) subtractDate: (self date settlement: 3).
	r := (self raise: (1 + (self shortRate value * d / 100 / 360)) to: (365 / d)) ln.
	pi := 3.14159265358979d.
	finance := (r * ((self expiryDate settlement: 4) subtractDate: (self expiryDate settlement: 3)) / 365) exp.
	dayDiff := #(0 1 0 0 0 0 0 0 0 0).
	dtArray := Array new: valueArray size.
	1 to: dtArray size do: [:v | 
		dtArray at: v put: ((self expiryDate subtractDate: (self date addDays: (dayDiff at: v))) / 365) asDouble].
	dt3Array := Array new: valueArray size.
	1 to: dt3Array size do: [:v | 
		dt3Array at: v put: 
			(((self expiryDate settlement: 3) subtractDate: 
			((self date settlement: 3) addDays: (dayDiff at: v))) / 365) asDouble].
	dirtyArrays := Array new: sz.
	1 to: sz do: [:i | | ar dirty |
		dirtyArrays at: i put: (ar := Array new: 10).
		dirty := self modDirtyPriceOf: i rate: 0 date: 0.
		ar at: 1 put: dirty.
		ar at: 2 put: (self modDirtyPriceOf: i rate: 0 date: 1).
		1 to: sz do: [:j |
			i = j
				ifTrue: [
					ar at: 2 * j + 1 put: (self modDirtyPriceOf: i rate: 0.01d date: 0).
					ar at: 2 * j + 2 put: (self modDirtyPriceOf: i rate: -0.01d date: 0)]
				ifFalse: [
					ar at: 2 * j + 1 put: dirty.
					ar at: 2 * j + 2 put: dirty]]].
	sigma1 := self sigmaOf: 1.
	sigma2 := self sigmaOf: 2.
	sigma3 := self sigmaOf: 3.
	sigma4 := self sigmaOf: 4.
	(rho12 := self correlationOf: 1 and: 2) = 1.0d ifTrue: [^0].
	(rho13 := self correlationOf: 1 and: 3) = 1.0d ifTrue: [^0].
	(rho14 := self correlationOf: 1 and: 4) = 1.0d ifTrue: [^0].
	(rho23 := self correlationOf: 2 and: 3) = 1.0d ifTrue: [^0].
	(rho24 := self correlationOf: 2 and: 4) = 1.0d ifTrue: [^0].
	(rho34 := self correlationOf: 3 and: 4) = 1.0d ifTrue: [^0].
	cf1 := self conversionFactorOf: 1.
	cf2 := self conversionFactorOf: 2.
	cf3 := self conversionFactorOf: 3.
	cf4 := self conversionFactorOf: 4.
	u14 := self remainingCouponOf: 1 settlement: 4.
	u24 := self remainingCouponOf: 2 settlement: 4.
	u34 := self remainingCouponOf: 3 settlement: 4.
	u44 := self remainingCouponOf: 4 settlement: 4.
	1 to: valueArray size do: [:i | valueArray at: i put: (valueArray at: i) * oldRounds].
	1 to: rounds do: [:round |
		round  1000 = 0 ifTrue: [self iterations value: round + oldRounds].
		rand1 := self random.
		rand2 := self random.
		rand3 := self random.
		rand4 := self random.
		eps1 := (-2 * rand1 ln) sqrt * (2 * pi * rand2) cos.
		eps2 := (-2 * rand1 ln) sqrt * (2 * pi * rand2) sin.
		eps3 := (-2 * rand3 ln) sqrt * (2 * pi * rand4) cos.
		eps4 := (-2 * rand3 ln) sqrt * (2 * pi * rand4) sin.
		x1 := self e1: eps1 s1: sigma1.
		x2 := self e1: eps1 e2: eps2 s2: sigma2 r12: rho12.
		x3 := self e1: eps1 e2: eps2 e3: eps3 s3: sigma3 r12: rho12 r13: rho13 r23: rho23.
		x4 := self e1: eps1 e2: eps2 e3: eps3 e4: eps4 s3: sigma3 s4: sigma4
			r12: rho12 r13: rho13 r14: rho14 r23: rho23 r24: rho24 r34: rho34.
		1 to: valueArray size do: [:v | | dt |
			val := 100000.
			dt := dtArray at: v.
			dt3 := dt3Array at: v.
			tmpVal := ((dirtyArrays at: 1) at: v) * (((r - (sigma1 * sigma1 / 2)) * dt3) + (x1 * dt sqrt)) exp.
			val :=  (tmpVal * finance - u14) / cf1.
			winner := 1.
			sz > 1 ifTrue: [
				tmpVal := ((dirtyArrays at: 2) at: v) * (((r - (sigma2 * sigma2 / 2)) * dt3) + (x2 * dt sqrt)) exp.
				newVal :=  (tmpVal * finance - u24) / cf2.
				newVal < val ifTrue: [
					val := newVal.
					winner := 2].
				sz > 2 ifTrue: [
					tmpVal := ((dirtyArrays at: 3) at: v) * (((r - (sigma3 * sigma3 / 2)) * dt3) + (x3 * dt sqrt)) exp.
					newVal :=  (tmpVal * finance - u34) / cf3.
					newVal < val ifTrue: [
						val := newVal.
						winner := 3].
					sz > 3 ifTrue: [
						tmpVal := ((dirtyArrays at: 4) at: v) * (((r - (sigma4 * sigma4 / 2)) * dt3) + (x4 * dt sqrt)) exp.
						newVal :=  (tmpVal * finance - u44) / cf4.
						newVal < val ifTrue: [
							val := newVal.
							winner := 4]]]].
			v = 1 ifTrue: [frequencyArray at: winner put: (frequencyArray at: winner) + 1].
			valueArray at: v put: (valueArray at: v) + val]].
	1 to: valueArray size do: [:i | valueArray at: i put: (valueArray at: i) / newRounds].
	^newRounds.!

cleanPriceOf: index rate: disturbRate date: disturbDate
	^self cleanPriceOf: index rate: disturbRate date: disturbDate startPrice: true.!

cleanPriceOf: index rate: disturbRate date: disturbDate startPrice: startPrice
	| t r val dirty clean rate coupon env startDate endDate nom |
	index > self bonds size ifTrue: [^0].
	env := JazzEnvironment new.
	env localAt: 'cond_history' put: self date.
	rate := (self bondTable at: 2@index) + disturbRate.
	coupon := (self bonds at: index) valueAspect: #coupon environment: env.
	startPrice 
		ifTrue: [startDate := (self date settlement: 3) addDays: disturbDate]
		ifFalse: [startDate := self expiryDate settlement: 3].
	endDate := (self bonds at: index) valueAspect: #maturity environment: env.
	nom := 100.
	t := ((endDate subtractDate360: startDate) / 360) asDouble.
	r := (1 + (rate / 100)) ln.
	val := 0.
	0 to: t truncated do: [:y | val := val + (coupon * (r negated * (t - y)) exp)].
	dirty := val + (nom * (r negated * t) exp).
	clean := ((dirty - ((t ceiling - t) * coupon)) * 1000) rounded / 1000.
	^clean asDouble!

conversionFactorOf: index
	index > self bonds size ifTrue: [^1].
	^bondTable at: 4@index.!

correlationOf: index1 and: index2
	"index1 must be less than index2"
	| i |
	index2 > self bonds size ifTrue: [^0].
	i := self bonds size.
	1 to: index1 - 1 do: [:j | i := i + self bonds size - j].
	i := i + index2 - index1.
	^weightTable at: 2@i.!

e1: eps1 e2: eps2 e3: eps3 e4: eps4 s3: sigma3 s4: sigma4 r12: rho12 r13: rho13 r14: rho14 r23: rho23 r24: rho24 r34: rho34
	| d1 d2 d3 tmp1 d4 |
	d1 := sigma4 * rho14.
	d2 := sigma4 * (rho24 - (rho12 * rho14)) / (1 - (rho12 * rho12)) sqrt.
	d3 := sigma3 * sigma4 * 
		(((1 - (rho12 * rho12)) * rho34) +
		(rho14 * (rho23 * rho12 - rho13)) +
		(rho24 * (rho12 * rho13 - rho23))) /
		(1 - (rho12 * rho12)) sqrt /
		(1 - (rho12 * rho12) - (rho13 * rho13) - (rho23 * rho23) + (2 * rho12 * rho13 * rho23)) sqrt.
	tmp1 := ((1 - (rho12 * rho12)) * rho34) + (rho14 * (rho23 * rho12 - rho13)) + (rho24 * (rho12 * rho13 - rho23)).
	d4 := (sigma4 / (1 - (rho12 * rho12)) sqrt) *
		((1 - (rho12 * rho12) - (rho14 * rho14) - (rho24 * rho24) + (2 * rho12 * rho14 * rho24)) - 
		(sigma3 * sigma3 * tmp1 * tmp1 / 
			(1 - (rho12 * rho12) - (rho13 * rho13) - (rho23 * rho23) + (2 * rho12 * rho13 * rho23)))) sqrt.	
	^(d1 * eps1) + (d2 * eps2) + (d3 * eps3) + (d4 * eps4).!

e1: eps1 e2: eps2 e3: eps3 s3: sigma3 r12: rho12 r13: rho13 r23: rho23
	| c1 c2 c3 |
	c1 := sigma3 * rho13.
	c2 := sigma3 * (rho23 - (rho12 * rho13)) / (1 - (rho12 * rho12)) sqrt.
	c3 := sigma3 * ((1 - (rho12 * rho12) - (rho13 * rho13) - (rho23 * rho23) + (2 * rho12 * rho13 * rho23)) /
			(1 - (rho12 * rho12))) sqrt.
	^(c1 * eps1) + (c2 * eps2) + (c3 * eps3).!

e1: eps1 e2: eps2 s2: sigma2 r12: rho12
	| b1 b2 |
	b1 := rho12 * sigma2.
	b2 := sigma2 * (1 - (rho12 * rho12)) sqrt.
	^(b1 * eps1) + (b2 * eps2).!

e1: eps1 s1: sigma1
	^sigma1 * eps1.!

iterationCount: depth
	self bonds size > 2
		ifTrue: [^depth * depth * depth * depth]
		ifFalse: [^depth * depth]!

modDirtyPriceOf: index
	^self modDirtyPriceOf: index rate: 0 date: 0
"	| env coupon couponDate t clean |
	env := JazzEnvironment new.
	env localAt: 'cond_history' put: self date.
	coupon := (self bonds at: index) valueAspect: #coupon environment: env.
	couponDate := (self bonds at: index) valueAspect: #maturity environment: env.
	[(t := (couponDate subtractDate360: (self date settlement: 3)) / 360) >= 1] whileTrue: [
		couponDate := couponDate addYears: -1].
	clean := self cleanPriceOf: index rate: 0 date: 0.
	^(((clean + ((1 - t) * coupon)) * 1000000) rounded / 1000000) asDouble"!

modDirtyPriceOf: index rate: disturbRate date: disturbDate
	| env coupon couponDate t clean startDate dirty |
	env := JazzEnvironment new.
	env localAt: 'cond_history' put: self date.
	coupon := (self bonds at: index) valueAspect: #coupon environment: env.
	couponDate := (self bonds at: index) valueAspect: #maturity environment: env.
	startDate := (self date settlement: 3) addDays: disturbDate.
	[(t := (couponDate subtractDate360: startDate) / 360) >= 1] whileTrue: [
		couponDate := couponDate addYears: -1].
	clean := self cleanPriceOf: index rate: disturbRate date: disturbDate.
	dirty := (((clean + ((1 - t) * coupon)) * 1000000) rounded / 1000000) asDouble.
"8 = 3 days settlement + 5 days coupon settlement"
	(couponDate subtractDate: (expiryDate settlement: 8)) <= 0 ifTrue: [
		(couponDate subtractDate: (startDate settlement: 8)) >= 0 ifTrue: [
			dirty := dirty - (coupon / (1 + ((self shortRate value / 100) * ((couponDate subtractDate: (startDate settlement: 3)) / 360))))]].
	^dirty!

remainingCouponOf: index settlement: settlement
	| dtDirty env coupon maturity |
	index > self bonds size ifTrue: [^0].
	env := JazzEnvironment new.
	env localAt: 'cond_history' put: self date.
	coupon := (self bonds at: index) valueAspect: #coupon environment: env.
	maturity := (self bonds at: index) valueAspect: #maturity environment: env.
	dtDirty := (maturity subtractDate360: (self expiryDate settlement: settlement)) / 360.
	^(dtDirty ceiling - dtDirty) * coupon.!

resetCalculation
	self resetCalculation: true.!

resetCalculation: killProcess
	(killProcess and: [self calculateProcess notNil]) ifTrue: [self stopCalculation].
	self theoFuture value: 0d.
	self theoOption value: 0d.
	self precision value: 0d.
	self theta value: 0.
	self deltaFuture value: 0.
	1 to: self bonds size do: [:i | 
		self bondTable at: 3@i put: 0d.
		self bondTable at: 5@i put: 0d.
		self bondTable at: 6@i put: 0d.
		self bondTable at: 7@i put: 0d.
"		self bondTable at: 9@i put: 0d."
		self bondTable at: 10@i put: 0d.
		self bondTable at: 11@i put: 0d].!

setBondDelta
	| bond env interest maturity coupon rate delta |
	interest := BaliSecBond new.
	env := JazzEnvironment new.
	env localAt: 'cond_history' put: self date.
	1 to: self bonds size do: [:r |
		bond := self bonds at: r.
		maturity := (bond valueAspect: #maturity environment: env).
		coupon := (bond valueAspect: #coupon environment: env).
		rate := self bondTable at: 2@r.
		delta := interest deltaAt: self date maturity: maturity rate: rate coupon: coupon.
		bondTable at: 9@r put: delta].!

setFuturePrice: aPrice
	| r minPrice sz cleanArray clean newPrice financeGross financeNet dirtyArray deltaFut d |
	sz := self bonds size.
"	dt := (self expiryDate subtractDate: self date) / 365."
	d := (self expiryDate settlement: 4) subtractDate: (self date settlement: 3).
	r := (self raise: (1 + (self shortRate value * d / 100 / 360)) to: (365 / d)) ln.
	financeGross := (r * ((self expiryDate settlement: 4) subtractDate: (self expiryDate settlement: 3)) / 365) exp.
	financeNet := (r * ((self expiryDate settlement: 4) subtractDate: (self date settlement: 3)) / 365) exp.
	cleanArray := Array new: sz.
	dirtyArray := Array new: sz.
	minPrice := 1000000.
	1 to: sz do: [:i | | dirty dt |
		clean := self cleanPriceOf: i rate: 0d date: 0.
		cleanArray at: i put: clean.
		dirty := self modDirtyPriceOf: i.
		dirtyArray at: i put: dirty.
		dt := ((self expiryDate settlement: 3) subtractDate: (self date settlement: 3)) / 365.
		newPrice := 
			(dirty * financeGross * (r * dt) exp) - 
			(self remainingCouponOf: i settlement: 4).
		newPrice := newPrice / (self conversionFactorOf: i).
		minPrice := minPrice min: newPrice].
	self theoFuture value: ((aPrice * 1000) rounded / 1000) asDouble.
	self theoOption value: (((minPrice - aPrice) * 1000) rounded / 1000) asDouble.
	1 to: sz do: [:i | bondTable at: 5@i put: (cleanArray at: i) - ((self conversionFactorOf: i) * aPrice)].
	1 to: sz do: [:i | bondTable at: 6@i put: 
		((dirtyArray at: i) * financeNet) - 
		((self conversionFactorOf: i) * aPrice) - 
		(self remainingCouponOf: i settlement: 4)].
	1 to: sz do: [:i | bondTable at: 7@i put: 
		((((self conversionFactorOf: i) * aPrice + (self remainingCouponOf: i settlement: 4)) / (dirtyArray at: i)) - 1) * 100 * 360 / d].
	deltaFut := 0d.
	1 to: sz do: [:i | deltaFut := deltaFut + ((bondTable at: 3@i) * (bondTable at: 9@i))].
	self deltaFuture value: deltaFut.
	deltaFut > 0 ifTrue: [
		1 to: sz do: [:i | bondTable at: 10@i put: ((bondTable at: 9@i) / deltaFut)]].!

sigmaOf: index
	index > self bonds size ifTrue: [^0].
	^(weightTable at: 2@index) / 100! !

!BaliCalcInterestFuture methodsFor: 'aspects'!

baseRound
	^baseRound!

baseRound: aNumber
	baseRound := aNumber!

bonds
	| bond |
	bonds isNil ifTrue: [
		bonds := List new.
		self secretary 
			infoAspectsSpan: self futureName
			aspect1: 'cf'
			time: self date
			do: [:an |
				bond := self server element: (an at: 2) asSymbol.
				bond dbLoadInfo: 2.
				bonds add: bond].
		self secretary 
			infoAspectsSpan: self futureName
			aspect1: 'expiryDate'
			time: self date
			do: [:an | self expiryDate: (BaliTime fromString: (an at: 3))].
		self secretary 
			infoAspectsSpan: self futureName
			aspect1: 'name'
			time: self date
			do: [:an | self dbName value: (an at: 3)].
	].
	^bonds!

bondTable
	| bond env i |
	bondTable isNil ifTrue: [
		bondTable := TwoDList columns: 11 rows: self bonds size.
		env := JazzEnvironment new.
		env localAt: 'cond_history' put: self date.
		1 to: bonds size do: [:r |
			bond := self bonds at: r.
			bondTable at: 1@r put: bond printString.
			bondTable at: 2@r put: (bond valueAspect: #value environment: env).
			bondTable at: 8@r put: ''.
		].
		self setBondDelta.
		i := 1.
		self secretary 
			infoAspectsSpan: self futureName
			aspect1: 'cf'
			time: self date
			do: [:an | 
				self bondTable at: 4@i put: (GotheTools atod: (an at: 3)).
				i := i + 1].
	].
	^bondTable!

bondTableInterface
	bondTableInterface isNil ifTrue: [
		bondTableInterface := TableInterface new selectionInTable: (SelectionInTable with: self bondTable).
		bondTableInterface columnLabelsArray: 
			#('bonds' 'yield' 'hedge' 'conv. factor' 'gross basis' 'net basis' 'imp. repo' 'act repo' ' delta bond' ' delta b/f' 'freq %').
		GotheTools adjustColumnWidths: bondTableInterface.
	].
	^bondTableInterface.!

calculateProcess
	^calculateProcess!

calculateProcess: aProcess
	calculateProcess := aProcess!

date
	date isNil ifTrue: [self date: BaliTime now].
	^date!

date: aBaliTime
	date := aBaliTime.
	self changeBonds.!

dateStr
	^date isNil
		ifTrue:
			[dateStr := (self date printType: #day) asValue]
		ifFalse:
			[dateStr]!

dbName
	"This method was generated by UIDefiner.  Any edits made here
	may be lost whenever methods are automatically defined.  The
	initialization provided below may have been preempted by an
	initialize method."

	^dbName isNil
		ifTrue:
			[dbName := String new asValue]
		ifFalse:
			[dbName]!

deltaFuture
	^deltaFuture isNil
		ifTrue:
			[deltaFuture := 0 asValue]
		ifFalse:
			[deltaFuture]!

editWeight
	^editWeight isNil
		ifTrue:
			[editWeight := nil asValue]
		ifFalse:
			[editWeight]!

editYield
	^editYield isNil
		ifTrue:
			[editYield := nil asValue]
		ifFalse:
			[editYield]!

expiryDate
"	expiryDate isNil ifTrue: [expiryDate := self date addYears: self years value]."
	^expiryDate!

expiryDate: aBaliTime
	expiryDate := aBaliTime.
	self expiryDateStr value: (expiryDate printType: #day).!

expiryDateStr
	^expiryDateStr isNil
		ifTrue:
			[self expiryDate isNil
				ifFalse: [expiryDateStr := (self expiryDate printType: #day) asValue]
				ifTrue: [expiryDateStr := nil asValue]]
		ifFalse:
			[expiryDateStr]!

frontBack
	^frontBack isNil
		ifTrue:
			[frontBack := #front asValue]
		ifFalse:
			[frontBack]!

futureCount
	^futureCount isNil
		ifTrue:
			[futureCount := 1 asValue]
		ifFalse:
			[futureCount]!

futureName
	^self years value printString , 'stat' , self frontBack value asString.!

greeks
	^greeks isNil
		ifTrue:
			[greeks := true asValue]
		ifFalse:
			[greeks]!

iterationReport
	"This method was generated by UIDefiner.  Any edits made here
	may be lost whenever methods are automatically defined.  The
	initialization provided below may have been preempted by an
	initialize method."

	^iterationReport isNil
		ifTrue:
			[iterationReport := String new asValue]
		ifFalse:
			[iterationReport]!

iterations
	"This method was generated by UIDefiner.  Any edits made here
	may be lost whenever methods are automatically defined.  The
	initialization provided below may have been preempted by an
	initialize method."

	^iterations isNil
		ifTrue:
			[iterations := 0 asValue]
		ifFalse:
			[iterations]!

precision
	"This method was generated by UIDefiner.  Any edits made here
	may be lost whenever methods are automatically defined.  The
	initialization provided below may have been preempted by an
	initialize method."

	^precision isNil
		ifTrue:
			[precision := 0 asValue]
		ifFalse:
			[precision]!

quoteFuture
	"This method was generated by UIDefiner.  Any edits made here
	may be lost whenever methods are automatically defined.  The
	initialization provided below may have been preempted by an
	initialize method."

	^quoteFuture isNil
		ifTrue:
			[quoteFuture := 0 asValue]
		ifFalse:
			[quoteFuture]!

quoteOption
	"This method was generated by UIDefiner.  Any edits made here
	may be lost whenever methods are automatically defined.  The
	initialization provided below may have been preempted by an
	initialize method."

	^quoteOption isNil
		ifTrue:
			[quoteOption := 0 asValue]
		ifFalse:
			[quoteOption]!

random
	"initial value set in calculate"
"	random isNil ifTrue: [random := (Random new next * 1000000) truncated]."
	"GGL method"
	random := (random * 16807)  2147483647.
	^random asDouble / 2147483647.
	"Wichman-Hill
	random := (random * 171)  30269.
	^random asDouble / 30269."!

shortRate
	^shortRate isNil
		ifTrue:
			[shortRate := self server defaultRate asValue]
		ifFalse:
			[shortRate]!

theoFuture
	^theoFuture isNil
		ifTrue:
			[theoFuture := 0 asValue]
		ifFalse:
			[theoFuture]!

theoOption
	"This method was generated by UIDefiner.  Any edits made here
	may be lost whenever methods are automatically defined.  The
	initialization provided below may have been preempted by an
	initialize method."

	^theoOption isNil
		ifTrue:
			[theoOption := 0 asValue]
		ifFalse:
			[theoOption]!

theta
	"This method was generated by UIDefiner.  Any edits made here
	may be lost whenever methods are automatically defined.  The
	initialization provided below may have been preempted by an
	initialize method."

	^theta isNil
		ifTrue:
			[theta := 0 asValue]
		ifFalse:
			[theta]!

volDays1
	^volDays1 isNil
		ifTrue:
			[volDays1 := 30 asValue]
		ifFalse:
			[volDays1]!

volDays2
	^volDays2 isNil
		ifTrue:
			[volDays2 := 90 asValue]
		ifFalse:
			[volDays2]!

volWeight1
	^volWeight1 isNil
		ifTrue:
			[volWeight1 := 0.4 asValue]
		ifFalse:
			[volWeight1]!

volWeight2
	^volWeight2 isNil
		ifTrue:
			[volWeight2 := 0.6 asValue]
		ifFalse:
			[volWeight2]!

weightTable
	| bondsz sz row env set dates bondValues ar day firstDayIndex1 firstDayIndex2 w1 w2 s1 s2 val time trailVal trailTime span dt |
	weightTable isNil ifTrue: [
		bondsz := self bonds size.
		sz := bondsz + (bondsz * (bondsz - 1) / 2).
		weightTable := TwoDList columns: 4 rows: sz.
		bondsz = 0 ifTrue: [^weightTable].
		env := JazzEnvironment new.
		env localAt: 'cond_history_from' put: (self date subtractDays: (self volDays1 value max: self volDays2 value)).
		env localAt: 'cond_history_to' put: self date.
		set := Set new.
		self bonds first collectStepsDim: #dimHistory environment: env into: set.
		dates := set asList.
		dates sort.
		dt := 1.
		[dt < dates size] whileTrue: [ | d removeDate |
			d := dates at: dt.
			removeDate := d equalTo: (dates at: dt + 1) type: #day.
			removeDate
				ifTrue: [dates removeAtIndex: dt]
				ifFalse: [dt := dt + 1]].
		bondValues := Array new: self bonds size.
		1 to: self bonds size do: [:b |
			ar := Array new: ((dates size - 1) max: 0).
			bondValues at: b put: ar.
			val := nil.
			time := nil.
			1 to: dates size do: [:d |
				trailVal := val.
				trailTime := time.
				env localAt: 'cond_history' put: (dates at: d).
				val := ((self bonds at: b) valueAspect: #cleanPrice environment: env).
				time := dates at: d.
				(val isNil or: [trailVal isNil]) ifFalse: [
					span := time subtractDate: trailTime.
					span > 0 
						ifTrue: [
							ar at: d - 1 put: ((GotheObject ln: val) - (GotheObject ln: trailVal)) / (GotheObject sqrt: span / 365)]
						ifFalse: [
							time := trailTime.
							val := trailVal]]]].
		day := (self date subtractDays: self volDays1 value) daysStart.
		firstDayIndex1 := 1.
		[firstDayIndex1 < dates size and: [(dates at: firstDayIndex1) < day]] whileTrue: [firstDayIndex1 := firstDayIndex1 + 1].
		day := (self date subtractDays: self volDays2 value) daysStart.
		firstDayIndex2 := 1.
		[firstDayIndex2 < dates size and: [(dates at: firstDayIndex2) < day]] whileTrue: [firstDayIndex2 := firstDayIndex2 + 1].
		row := 1.
		1 to: bondsz do: [:b |
			weightTable at: 1@row put: ('sigma' , b printString).
			weightTable at: 3@row put: (s1 := (GotheTools sigma: (bondValues at: b) start: firstDayIndex1) * 100).
			weightTable at: 4@row put: (s2 := (GotheTools sigma: (bondValues at: b) start: firstDayIndex2) * 100).
			weightTable at: 2@row put: (s1 * self volWeight1 value) + (s2 * self volWeight2 value).
			row := row + 1.
		].
		1 to: bondsz - 1 do: [:i |
			i + 1 to: bondsz do: [:j |
				weightTable at: 1@row put: ('correl' , i printString , j printString).
				weightTable at: 3@row put: (w1 := GotheTools 
					correlation: (bondValues at: i) 
					and: (bondValues at: j) 
					start: firstDayIndex1
					minusOne: true).
				weightTable at: 4@row put: (w2 := GotheTools
					correlation: (bondValues at: i) 
					and: (bondValues at: j) 
					start: firstDayIndex2
					minusOne: true).
				weightTable at: 2@row put: (w1 * self volWeight1 value) + (w2 * self volWeight2 value).
				row := row + 1.
			].
		].
	].
	^weightTable!

weightTableInterface
	weightTableInterface isNil ifTrue: [
		weightTableInterface := TableInterface new selectionInTable: (SelectionInTable with: self weightTable).
		weightTableInterface columnLabelsArray: #('aspect' 'weighted' ' days 1' ' days 2').
	].
	^weightTableInterface.!

years
	^years isNil
		ifTrue:
			[years := 10 asValue]
		ifFalse:
			[years]! !

!BaliCalcInterestFuture methodsFor: 'actions'!

baliMessageSend: aMessageSymbol with: aParameter
	"send the message to all dependent elements"
	self bonds do: [:b | b baliMessage: aMessageSymbol with: aParameter].!

stopCalculation
	self calculateProcess isNil ifFalse: [self calculateProcess terminate].
	self calculateProcess: nil.
	self iterationReport value: ''.! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

BaliCalcInterestFuture class
	instanceVariableNames: ''!


!BaliCalcInterestFuture class methodsFor: 'interface specs'!

windowSpec
	"UIPainter new openOnClass: self andSelector: #windowSpec"

	
	^#(#FullSpec 
		#window: 
		#(#WindowSpec 
			#label: 'Unlabeled Canvas' 
			#bounds: #(#Rectangle 314 641 1240 1135 ) ) 
		#component: 
		#(#SpecCollection 
			#collection: #(
				#(#LabelSpec 
					#layout: #(#Point 11 35 ) 
					#label: ' date' ) 
				#(#InputFieldSpec 
					#layout: #(#Rectangle 97 33 197 59 ) 
					#colors: 
					#(#LookPreferences 
						#setBackgroundColor: #(#ColorValue #white ) ) 
					#model: #dateStr 
					#callbacksSpec: 
					#(#UIEventCallbackSubSpec 
						#valueChangeSelector: #changeDate ) ) 
				#(#LabelSpec 
					#layout: #(#Point 519 7 ) 
					#label: 'expiry date' ) 
				#(#InputFieldSpec 
					#layout: #(#Rectangle 591 6 689 30 ) 
					#colors: 
					#(#LookPreferences 
						#setBackgroundColor: #(#ColorValue 7044 7044 7044 ) ) 
					#model: #expiryDateStr 
					#tabable: false 
					#isReadOnly: true ) 
				#(#LabelSpec 
					#layout: #(#Point 205 96 ) 
					#label: 'option value' ) 
				#(#InputFieldSpec 
					#layout: #(#Rectangle 282 60 382 86 ) 
					#colors: 
					#(#LookPreferences 
						#setBackgroundColor: #(#ColorValue 7044 7044 7044 ) ) 
					#model: #theoFuture 
					#tabable: false 
					#isReadOnly: true 
					#type: #number ) 
				#(#LabelSpec 
					#layout: #(#Point 11 62 ) 
					#label: 'no of futures' ) 
				#(#InputFieldSpec 
					#layout: #(#Rectangle 97 63 197 89 ) 
					#colors: 
					#(#LookPreferences 
						#setBackgroundColor: #(#ColorValue 7044 7044 7044 ) ) 
					#model: #futureCount 
					#callbacksSpec: 
					#(#UIEventCallbackSubSpec 
						#valueChangeSelector: #resetCalculation ) 
					#tabable: false 
					#isReadOnly: true 
					#type: #number ) 
				#(#LabelSpec 
					#layout: #(#Point 204 65 ) 
					#label: 'futures price' ) 
				#(#InputFieldSpec 
					#layout: #(#Rectangle 97 92 197 118 ) 
					#colors: 
					#(#LookPreferences 
						#setBackgroundColor: #(#ColorValue #white ) ) 
					#model: #shortRate 
					#callbacksSpec: 
					#(#UIEventCallbackSubSpec 
						#valueChangeSelector: #resetCalculation ) 
					#type: #number ) 
				#(#LabelSpec 
					#layout: #(#Point 387 40 ) 
					#label: 'quoted' ) 
				#(#InputFieldSpec 
					#layout: #(#Rectangle 388 60 488 86 ) 
					#colors: 
					#(#LookPreferences 
						#setBackgroundColor: #(#ColorValue 7044 7044 7044 ) ) 
					#model: #quoteFuture 
					#tabable: false 
					#isReadOnly: true 
					#type: #number ) 
				#(#LabelSpec 
					#layout: #(#Point 280 41 ) 
					#label: 'theoretical' ) 
				#(#InputFieldSpec 
					#layout: #(#Rectangle 388 91 488 117 ) 
					#colors: 
					#(#LookPreferences 
						#setBackgroundColor: #(#ColorValue 7044 7044 7044 ) ) 
					#model: #quoteOption 
					#tabable: false 
					#isReadOnly: true 
					#type: #number ) 
				#(#InputFieldSpec 
					#layout: #(#Rectangle 282 91 382 117 ) 
					#colors: 
					#(#LookPreferences 
						#setBackgroundColor: #(#ColorValue 7044 7044 7044 ) ) 
					#model: #theoOption 
					#tabable: false 
					#isReadOnly: true 
					#type: #number ) 
				#(#LabelSpec 
					#layout: #(#LayoutOrigin 336 0 82 0.333333 ) 
					#label: '# days' ) 
				#(#InputFieldSpec 
					#layout: #(#LayoutFrame 384 0 82 0.333333 484 0 107 0.333333 ) 
					#colors: 
					#(#LookPreferences 
						#setBackgroundColor: #(#ColorValue #white ) ) 
					#model: #volDays1 
					#type: #number ) 
				#(#LabelSpec 
					#layout: #(#LayoutOrigin 336 0 112 0.333333 ) 
					#label: 'weight' ) 
				#(#InputFieldSpec 
					#layout: #(#LayoutFrame 385 0 109 0.333333 484 0 135 0.333333 ) 
					#colors: 
					#(#LookPreferences 
						#setBackgroundColor: #(#ColorValue #white ) ) 
					#model: #volWeight1 
					#callbacksSpec: 
					#(#UIEventCallbackSubSpec 
						#valueChangeSelector: #changeVolWeight1 ) 
					#type: #number ) 
				#(#InputFieldSpec 
					#layout: #(#LayoutFrame 487 0 82 0.333333 588 0 107 0.333333 ) 
					#colors: 
					#(#LookPreferences 
						#setBackgroundColor: #(#ColorValue #white ) ) 
					#model: #volDays2 
					#type: #number ) 
				#(#InputFieldSpec 
					#layout: #(#LayoutFrame 487 0 109 0.333333 588 0 135 0.333333 ) 
					#colors: 
					#(#LookPreferences 
						#setBackgroundColor: #(#ColorValue #white ) ) 
					#model: #volWeight2 
					#callbacksSpec: 
					#(#UIEventCallbackSubSpec 
						#valueChangeSelector: #changeVolWeight2 ) 
					#type: #number ) 
				#(#LabelSpec 
					#layout: #(#Point 11 93 ) 
					#label: 'short rate' ) 
				#(#MenuButtonSpec 
					#layout: #(#Rectangle 11 4 196 28 ) 
					#colors: 
					#(#LookPreferences 
						#setBackgroundColor: #(#ColorValue #white ) ) 
					#model: #years 
					#callbacksSpec: 
					#(#UIEventCallbackSubSpec 
						#valueChangeSelector: #changeYears ) 
					#menu: #yearsMenu ) 
				#(#TableViewSpec 
					#layout: #(#LayoutFrame 3 0 150 0 0 0.99568 78 0.333333 ) 
					#model: #bondTableInterface 
					#callbacksSpec: 
					#(#UIEventCallbackSubSpec 
						#valueChangeSelector: #changeBondTable ) 
					#selectionStyle: #row ) 
				#(#TableViewSpec 
					#layout: #(#LayoutFrame 4 0 136 0.333333 -5 1 -31 1 ) 
					#model: #weightTableInterface 
					#callbacksSpec: 
					#(#UIEventCallbackSubSpec 
						#valueChangeSelector: #changeWeightTable ) 
					#selectionStyle: #row ) 
				#(#LabelSpec 
					#layout: #(#LayoutOrigin 192 0 81 0.333333 ) 
					#label: 'Volatility and correlation' ) 
				#(#MenuButtonSpec 
					#layout: #(#Rectangle 200 4 326 28 ) 
					#colors: 
					#(#LookPreferences 
						#setBackgroundColor: #(#ColorValue #white ) ) 
					#model: #frontBack 
					#callbacksSpec: 
					#(#UIEventCallbackSubSpec 
						#valueChangeSelector: #changeFrontBack ) 
					#menu: #frontBackMenu ) 
				#(#LabelSpec 
					#layout: #(#LayoutOrigin 11 0 82 0.333333 ) 
					#label: 'Edit yield' ) 
				#(#InputFieldSpec 
					#layout: #(#LayoutFrame 74 0 81 0.333333 184 0 105 0.333333 ) 
					#colors: 
					#(#LookPreferences 
						#setBackgroundColor: #(#ColorValue #white ) ) 
					#model: #editYield 
					#callbacksSpec: 
					#(#UIEventCallbackSubSpec 
						#valueChangeSelector: #changeEditYield ) 
					#type: #number ) 
				#(#LabelSpec 
					#layout: #(#LayoutOrigin 11 0 -26 1 ) 
					#label: 'Edit weight' ) 
				#(#InputFieldSpec 
					#layout: #(#LayoutFrame 86 0 -29 1 187 0 -5 1 ) 
					#colors: 
					#(#LookPreferences 
						#setBackgroundColor: #(#ColorValue #white ) ) 
					#model: #editWeight 
					#callbacksSpec: 
					#(#UIEventCallbackSubSpec 
						#valueChangeSelector: #changeEditWeight ) 
					#type: #number ) 
				#(#LabelSpec 
					#layout: #(#Point 331 7 ) 
					#label: 'name' ) 
				#(#InputFieldSpec 
					#layout: #(#Rectangle 373 5 511 29 ) 
					#colors: 
					#(#LookPreferences 
						#setBackgroundColor: #(#ColorValue 7044 7044 7044 ) ) 
					#model: #dbName 
					#tabable: false 
					#isReadOnly: true ) 
				#(#LabelSpec 
					#layout: #(#Point 590 40 ) 
					#label: 'Iterations' ) 
				#(#InputFieldSpec 
					#layout: #(#Rectangle 590 60 671 86 ) 
					#colors: 
					#(#LookPreferences 
						#setBackgroundColor: #(#ColorValue 7044 7044 7044 ) ) 
					#model: #iterations 
					#type: #number ) 
				#(#ActionButtonSpec 
					#layout: #(#Rectangle 590 93 673 117 ) 
					#model: #calculate 
					#label: 'Calc. price' 
					#defaultable: true ) 
				#(#ActionButtonSpec 
					#layout: #(#Rectangle 676 93 754 117 ) 
					#colors: 
					#(#LookPreferences 
						#setForegroundColor: #(#ColorValue #white ) 
						#setBackgroundColor: #(#ColorValue #red ) ) 
					#model: #stopCalculation 
					#label: 'Stop' 
					#defaultable: true ) 
				#(#LabelSpec 
					#layout: #(#Point 492 41 ) 
					#label: 'theta' ) 
				#(#InputFieldSpec 
					#layout: #(#Rectangle 493 60 575 86 ) 
					#colors: 
					#(#LookPreferences 
						#setBackgroundColor: #(#ColorValue 7044 7044 7044 ) ) 
					#model: #theta 
					#type: #number ) 
				#(#CheckBoxSpec 
					#layout: #(#Point 495 97 ) 
					#colors: 
					#(#LookPreferences 
						#setBackgroundColor: #(#ColorValue #white ) ) 
					#model: #greeks 
					#label: 'calc. greeks' ) 
				#(#ActionButtonSpec 
					#layout: #(#LayoutFrame 592 0 83 0.333333 684 0 108 0.333333 ) 
					#model: #changeWeights 
					#label: 'Calc. weights' 
					#defaultable: true ) 
				#(#InputFieldSpec 
					#layout: #(#Rectangle 677 60 753 86 ) 
					#colors: 
					#(#LookPreferences 
						#setBackgroundColor: #(#ColorValue 7044 7044 7044 ) ) 
					#model: #precision 
					#type: #number ) 
				#(#LabelSpec 
					#layout: #(#Point 677 39 ) 
					#label: 'Price change' ) 
				#(#LabelSpec 
					#layout: #(#Point 204 125 ) 
					#label: ' delta future' ) 
				#(#InputFieldSpec 
					#layout: #(#Rectangle 282 121 382 147 ) 
					#colors: 
					#(#LookPreferences 
						#setBackgroundColor: #(#ColorValue 7044 7044 7044 ) ) 
					#model: #deltaFuture 
					#type: #number ) ) ) )! !

!BaliCalcInterestFuture class methodsFor: 'resources'!

frontBackMenu
	"MenuEditor new openOnClass: self andSelector: #frontBackMenu"

	
	^#(#Menu #(
			#(#MenuItem 
				#rawLabel: 'front' 
				#value: #front ) 
			#(#MenuItem 
				#rawLabel: 'back' 
				#value: #back ) ) #(2 ) nil ) decodeAsLiteralArray!

yearsMenu
	"MenuEditor new openOnClass: self andSelector: #yearsMenu"

	
	^#(#Menu #(
			#(#MenuItem 
				#rawLabel: '2 years' 
				#value: 2 ) 
			#(#MenuItem 
				#rawLabel: '5 years' 
				#value: 5 ) 
			#(#MenuItem 
				#rawLabel: '10 years' 
				#value: 10 ) ) #(3 ) nil ) decodeAsLiteralArray! !

*/