org.unizone.finance.equity

Type VolatilityBS

org.unizone.0.5800
Instance of Type
Inheriting from SourceAdapterSingleTimeseries

Type dataValue
org.uninode.Type.displayPattern{att:org.unizone.source.Source.displayName}
org.unizone.source.Source.valueAttribute
org.uninode.Resource.resourceType
org.uninode.Resource.label
org.uninode.Resource.resourceOfList{}
org.uninode.Listable.resourcesReference[org.uninode.Listable.resources] of org.unizone.finance.equity.VolatilityBS

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
StringdisplayName
The display name is the name that is shown in lists, displays and graphs.
Sourceorg.unizone.0.4001essential
AttributevalueAttribute
The value attribute is used for determining the default value that should be used for displaying this source in a graph.
Sourceorg.unizone.0.4011type
inheritValue
SignaturevalueType
The value type determines which axes should be used in graphs.
Sourceorg.unizone.0.4002inheritValue
SourcesourceSourceAdapterSingleorg.unizone.0.4051

Method summaryDefined inOverridesProperties
voidactivateListable
voidcheckRangeSourceAdapterSingleSource
voiddesignEditor(WidgetWorkspace ws)Listable
voidgenerateScript(ScriptGenerationInfo info)SourceAdapterSingleScriptGenerator
Realget(DateTime timestamp)SourceAdapterSingleTimeseries
BooleanisResourceOf(Listable listable, Signature aspect)Mixabletype
ListablemixOn(Mixable mix)Mixable
ListablemixWith(Mixable mix)Mixable
voidput(DateTime timestamp, Real value)SourceAdapterSingleTimeseries
StringresourceStringListableintrospection
voidsetSource(Source source)SourceAdapterSingle
SourcesourceSourceAdapterSingle
voidXXXcom.nodelab.java.sourceadaptersingle.CheckRangeSourceAdapterSingle
SignatureXXXcom.nodelab.java.sourceadaptersingle.ValueTypeSourceAdapterSingle
voidcom.nodelab.java.source.ActivateSourceListable
Listablecom.nodelab.java.source.MixWithMiSourceMixable

Script summary
org.unizone.0.8532
/*

BaliTimeSource subclass: #BaliVolatilityBS

	instanceVariableNames: ' days standardVol '

	classVariableNames: ''

	poolDictionaries: ''

	category: 'Bali'!





!BaliVolatilityBS methodsFor: 'black&scholes'!

cashFlowVol: vol rate: rate timeArray: timeArray valueArray: valueArray
	| extraDays matDate call delta cashFlow trailDelta res strikePrice spotPrice years lastPrice |
	extraDays := 10.
	spotPrice := strikePrice := valueArray at: 1.
 	matDate := timeArray last addDays: extraDays.
	delta := 0.
	cashFlow := 0.
	spotPrice isNil ifFalse: [
		years := (matDate subtractDate: timeArray first) / 365.
		call := self nextSource
			bsPriceCall: true 
			spot: spotPrice
			years: years
			strike: strikePrice
			sigma: vol 
			rate: rate.
		delta := self nextSource
			bsDeltaCall: true
			spot: spotPrice
			years: years
			strike: strikePrice
			sigma: vol
			rate: rate.
		cashFlow := (spotPrice * delta - call) * 
			(self raise: (1 + (rate / 100)) to: (years - (extraDays / 365)))].
	2 to: timeArray size do: [:i |
		trailDelta := delta.
		spotPrice := valueArray at: i.
		spotPrice isNil ifFalse: [
			strikePrice isNil ifTrue: [strikePrice := spotPrice].
			lastPrice := spotPrice.
			years := (matDate subtractDate: (timeArray at: i)) / 365.
			delta := self nextSource
				bsDeltaCall: true
				spot: spotPrice
				years: years
				strike: strikePrice
				sigma: vol
				rate: rate.
			cashFlow := cashFlow + 
				((delta - trailDelta) * 
				spotPrice * 
				(self raise: (1 + (rate / 100)) to: (years - (extraDays / 365))))]].
	res := cashFlow - (lastPrice * delta) +
		(self nextSource
			bsPriceCall: true
			spot: lastPrice
			years: years
			strike: strikePrice
			sigma: vol
			rate: rate).
	^res!

volCalcRate: rate environment: env
	| res startVol src newEnv set sourceSteps array |
	startVol := self standardVol valueAspect: #value environment: env.
	startVol isNil ifTrue: [startVol := 25].
	src := self nextSource.
	newEnv := JazzEnvironment new.
	newEnv localAt: 'cond_history_from' put: (env timestamp subtractDays: self days value).
	newEnv localAt: 'cond_history_to' put: env timestamp.
	newEnv localAt: 'cond_history_resolution' put: #day.
	set := Set new.
	src collectStepsDim: #dimHistory environment: newEnv into: set.
	sourceSteps := set asList.
	sourceSteps sort.
	(sourceSteps size = 0 or: [(env timestamp subtractDate: (sourceSteps at: 1)) < (self days value - 10)])
		ifTrue: [^nil].
	array := Array new: sourceSteps size.
	1 to: array size do: [:i |
		newEnv localAt: 'cond_history' put: (sourceSteps at: i).
		array at: i put: (src valueAspect: #price environment: newEnv)].
	res := self
		optimize: [:vol | vol > 0
			ifTrue: [self cashFlowVol: vol rate: rate timeArray: sourceSteps valueArray: array]
			ifFalse: [self cashFlowVol: 1 rate: rate timeArray: sourceSteps valueArray: array]]
		final: 0
		lowStart: startVol * 0.5
		highStart: startVol * 1.5
		maxDiff: 0.0001.
	^res! !

!BaliVolatilityBS methodsFor: 'source'!

asSourceAdaptor
	self user currentSource isNil ifTrue: [^nil].
	self nextSource: self user currentSource.
	self user sourceCommandQty value > 0 
		ifTrue: [self days value: self user sourceCommandQty value].
	^self!

basicValueTypes
	^#(#volatility)!

defaultName
	self nextSource isNil ifTrue: [^self days truncated printString , ' days volatility'].
	^self days value truncated printString , ' days B&S vol ' , self nextSource name.! !

!BaliVolatilityBS methodsFor: 'aspects'!

days
	days isNil ifTrue: [days := 30 asValue].
	^days!

nextSource: aBaliSource
	super nextSource: aBaliSource.
	self standardVol nextSource: aBaliSource.!

standardVol
	standardVol isNil ifTrue: [standardVol := BaliVolatility new days: self days; nextSource: self nextSource].
	^standardVol! !

!BaliVolatilityBS methodsFor: 'timeSource'!

basicCreateDataAt: aBaliTime resolution: aResolution environment: env
	| data |
	self server user report: 'Preparing ' , self name , ' at ' , (aBaliTime printType: #day).
	data := BaliTimeData new source: self.
	data aspects at: #timestamp put: aBaliTime.
	data aspects at: #value put: (self volCalcRate: self server defaultRate environment: env).
	self server user report: ''.
	^data! !

!BaliVolatilityBS methodsFor: 'copying'!

baliCopy: aDictionary
	| src |
	src := aDictionary at: self ifAbsent: nil.
	src isNil ifFalse: [^src].
	src := super baliCopy: aDictionary.
	src days value: self days value.
	^src! !

!BaliVolatilityBS methodsFor: ' database'!

addDefinition
	| aspects |
	(aspects := super addDefinition) isNil ifTrue: [^nil].
	self addAspect: #dbDays value: self days value printString position: aspects + 1.
	^aspects + 1!

dbDays: aString
	self days value: (GotheTools atod: aString) truncated! !

!BaliVolatilityBS methodsFor: 'element'!

uiClass
	^BaliDaysUI! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

BaliVolatilityBS class
	instanceVariableNames: ''!


!BaliVolatilityBS class methodsFor: 'aspects'!

scriptClass
	^'VolatilityBS'!

scriptSuperClass
	^'Effect'! !


*/